Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ linters:
- github.com/superfly/flyctl/render.Printf
- github.com/superfly/flyctl/render.Detailf
- github.com/superfly/flyctl/render.Donef
nlreturn:
block-size: 5
staticcheck:
checks:
- all
Expand Down
17 changes: 15 additions & 2 deletions scripts/clean-up-preflight-apps/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package main

import (
"bytes"
"context"
"fmt"
"io"
"os"
"os/exec"
"strings"
"time"

"github.com/google/shlex"
Expand Down Expand Up @@ -58,8 +61,9 @@ func run() error {
return err
}
cmd := exec.CommandContext(ctx, flyctlBin, cmdParts[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
var stdout, stderr bytes.Buffer
cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
cmd.Stderr = io.MultiWriter(os.Stderr, &stderr)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, fmt.Sprintf("FLY_API_TOKEN=%s", os.Getenv("FLY_PREFLIGHT_TEST_ACCESS_TOKEN")))
fmt.Fprintln(os.Stderr, cmdStr)
Expand All @@ -69,10 +73,19 @@ func run() error {
}
err = cmd.Wait()
if err != nil {
if isAppNotFound(stdout.String(), stderr.String()) {
fmt.Fprintf(os.Stderr, "app %s is already gone; continuing cleanup\n", app.Id)
continue
}
return err
}
}
}

return nil
}

func isAppNotFound(stdout, stderr string) bool {
output := strings.ToLower(stdout + "\n" + stderr)
return strings.Contains(output, "app not found")
}