Skip to content

Commit

Permalink
fix: expose cleanup errors
Browse files Browse the repository at this point in the history
If anything fails during the cleanup, expose the error to the end-user
by changing the exit status.
  • Loading branch information
zimbatm committed Nov 8, 2024
1 parent 09dec2d commit 0163fa6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions command/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,33 @@ func CmdCleanup(c *cli.Context) (err error) {

log.Println("to undeploy:", toUndeploy)

var lastErr error

for _, name := range toUndeploy {
log.Println("Undeploying", name)

pullRequestID, err := strconv.Atoi(name)
if err != nil {
log.Println("Unable to parse pull request id: ", name)
lastErr = err
continue
}

cmd := exec.Command(c.Args().Get(0), c.Args()[1:]...) //#nosec
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()
if err != nil {
log.Println("undeploy error: ", err)

continue
}

pullRequestID, err := strconv.Atoi(name)
if err != nil {
log.Println("Unable to parse pull request id: ", name)

lastErr = err
continue
}

destroyGitHubDeployments(ctx, ghCli, owner, repo, pullRequestID, ignoreMissing)
}

return nil
return lastErr
}

func contains(item string, list []string) bool {
Expand Down

0 comments on commit 0163fa6

Please sign in to comment.