Skip to content

Commit

Permalink
Merge pull request #87 from nitrictech/fix/command-errors
Browse files Browse the repository at this point in the history
fix: ensure failed commands are correctly handled

Co-authored-by: PulpDood <[email protected]>
  • Loading branch information
tjholm and pulpdood authored Jun 24, 2024
2 parents 8b15319 + fce7739 commit fe77d94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
32 changes: 14 additions & 18 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,22 @@ const dockerEnv = {
}

const up = async (stackName: string, cwd: string) =>
(
await exec(
`nitric up --ci --stack ${stackName}`,
undefined,
cwd,
false,
dockerEnv
)
).stdout
await exec(
`nitric up --ci --stack ${stackName}`,
undefined,
cwd,
false,
dockerEnv
)

const down = async (stackName: string, cwd: string) =>
(
await exec(
`nitric down --ci --stack ${stackName}`,
undefined,
cwd,
false,
dockerEnv
)
).stdout
await exec(
`nitric down --ci --stack ${stackName}`,
undefined,
cwd,
false,
dockerEnv
)

export const commands = {
up,
Expand Down
12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ export async function run() {
// run command if exists
if (command && stackName) {
core.info(`Running command ${command}`)
const output = await commands[command as keyof typeof commands](
const {
stdout: output,
success,
stderr
} = await commands[command as keyof typeof commands](
stackName,
workingDirectory
)

if (!success) {
core.error(`Failed running command ${command}`)
throw new Error(stderr)
}

core.info(`Done running command ${command}`)

core.setOutput('output', output)
Expand Down

0 comments on commit fe77d94

Please sign in to comment.