Skip to content

Commit

Permalink
add an env var that tells preflight now to print command history inst…
Browse files Browse the repository at this point in the history
…ead of doing a bunch of test ouput parsing

`make ci-preflight` now calls `preflight-test FLY_PREFLIGHT_TEST_NO_PRINT_HISTORY_ON_FAIL=true`, which is really a lot simpler than parsing go test json output :-)
  • Loading branch information
tvdfly committed May 31, 2023
1 parent 61d8ed1 commit 9a0e2d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 122 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
FLY_PREFLIGHT_TEST_ACCESS_TOKEN: ${{ secrets.FLYCTL_PREFLIGHT_CI_FLY_API_TOKEN }}
FLY_PREFLIGHT_TEST_FLY_ORG: flyctl-ci-preflight
FLY_PREFLIGHT_TEST_FLY_REGIONS: iad syd
# run: make ci-preflight
run: make preflight-test
run: make ci-preflight
- uses: superfly/flyctl-actions/setup-flyctl@master
if: always()
- name: Clean up any un-deleted preflight apps
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ preflight-test: build
if [ -r .direnv/preflight ]; then . .direnv/preflight; fi; \
go test ./test/preflight --tags=integration -v -timeout 30m --run="$(T)"

ci-preflight: build
go test ./test/preflight --tags=integration -v -timeout 30m -json --run="$(T)" >ci-preflight-test-results.njson ||:
go run ./scripts/report-ci-preflight-results ./ci-preflight-test-results.njson
ci-preflight:
$(MAKE) preflight-test FLY_PREFLIGHT_TEST_NO_PRINT_HISTORY_ON_FAIL=true

cmddocs: generate
@echo Running Docs Generation
Expand Down
100 changes: 0 additions & 100 deletions scripts/report-ci-preflight-results/main.go

This file was deleted.

39 changes: 22 additions & 17 deletions test/preflight/testlib/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type FlyctlTestEnv struct {
primaryRegion string
otherRegions []string
cmdHistory []*FlyctlResult
noHistoryOnFail bool
}

func (f *FlyctlTestEnv) OrgSlug() string {
Expand All @@ -54,28 +55,31 @@ func (f *FlyctlTestEnv) OtherRegions() []string {

func NewTestEnvFromEnv(t testing.TB) *FlyctlTestEnv {
tempDir := socketSafeTempDir(t)
_, noHistoryOnFail := os.LookupEnv("FLY_PREFLIGHT_TEST_NO_PRINT_HISTORY_ON_FAIL")
env := NewTestEnvFromConfig(t, TestEnvConfig{
homeDir: tempDir,
workDir: tempDir,
flyctlBin: os.Getenv("FLY_PREFLIGHT_TEST_FLYCTL_BINARY_PATH"),
orgSlug: os.Getenv("FLY_PREFLIGHT_TEST_FLY_ORG"),
primaryRegion: primaryRegionFromEnv(),
otherRegions: otherRegionsFromEnv(),
accessToken: os.Getenv("FLY_PREFLIGHT_TEST_ACCESS_TOKEN"),
logLevel: os.Getenv("FLY_PREFLIGHT_TEST_LOG_LEVEL"),
homeDir: tempDir,
workDir: tempDir,
flyctlBin: os.Getenv("FLY_PREFLIGHT_TEST_FLYCTL_BINARY_PATH"),
orgSlug: os.Getenv("FLY_PREFLIGHT_TEST_FLY_ORG"),
primaryRegion: primaryRegionFromEnv(),
otherRegions: otherRegionsFromEnv(),
accessToken: os.Getenv("FLY_PREFLIGHT_TEST_ACCESS_TOKEN"),
logLevel: os.Getenv("FLY_PREFLIGHT_TEST_LOG_LEVEL"),
noHistoryOnFail: noHistoryOnFail,
})
return env
}

type TestEnvConfig struct {
homeDir string
workDir string
flyctlBin string
orgSlug string
primaryRegion string
otherRegions []string
accessToken string
logLevel string
homeDir string
workDir string
flyctlBin string
orgSlug string
primaryRegion string
otherRegions []string
accessToken string
logLevel string
noHistoryOnFail bool
}

func NewTestEnvFromConfig(t testing.TB, cfg TestEnvConfig) *FlyctlTestEnv {
Expand Down Expand Up @@ -107,6 +111,7 @@ func NewTestEnvFromConfig(t testing.TB, cfg TestEnvConfig) *FlyctlTestEnv {
homeDir: cfg.homeDir,
workDir: cfg.workDir,
originalAccessToken: cfg.accessToken,
noHistoryOnFail: cfg.noHistoryOnFail,
}
testEnv.verifyTestOrgExists()
t.Cleanup(func() {
Expand Down Expand Up @@ -198,7 +203,7 @@ func (f *FlyctlTestEnv) ResetAuthAccessToken() {

func (f *FlyctlTestEnv) DebugPrintHistory() {
f.t.Helper()
if f.Failed() {
if f.Failed() || f.noHistoryOnFail {
return
}
for i, r := range f.cmdHistory {
Expand Down

0 comments on commit 9a0e2d2

Please sign in to comment.