From 8762bd151574a7e2fe365f90caa581e2738d3c93 Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Sat, 11 Oct 2025 11:31:43 -0700 Subject: [PATCH] changed tests always are flagged as affected tests --- .github/workflows/build-test.yaml | 26 +++++++ .github/workflows/regression-test.yaml | 2 +- scripts/affected-packages.go | 102 ++++++++++++++++++++++--- 3 files changed, 118 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index b4a3db74..9e5af070 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -47,6 +47,19 @@ jobs: - uses: actions/checkout@v5 - uses: ./.github/actions/setup-go + - name: Cache Go build and modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Go mod download + run: go mod download + - name: Check go mod tidy run: | go mod tidy @@ -91,6 +104,19 @@ jobs: steps: - uses: actions/checkout@v5 - uses: ./.github/actions/setup-go + + - name: Cache Go build and modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Go mod download + run: go mod download - run: make build - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/regression-test.yaml b/.github/workflows/regression-test.yaml index 5f7f328b..d1f19507 100644 --- a/.github/workflows/regression-test.yaml +++ b/.github/workflows/regression-test.yaml @@ -2,7 +2,7 @@ name: Regression Test Suite on: push: - branches: [main, v1beta3] + branches: [main] workflow_dispatch: inputs: update_baselines: diff --git a/scripts/affected-packages.go b/scripts/affected-packages.go index 100dfe85..394b9a99 100644 --- a/scripts/affected-packages.go +++ b/scripts/affected-packages.go @@ -352,7 +352,8 @@ func main() { fmt.Println(p) } case "suites": - // Determine impacted suites by dependency mapping, then print exact test names for those suites. + // Determine impacted suites by dependency mapping and direct e2e test changes, + // then print exact test names for those suites. preflightRoot := "github.com/replicatedhq/troubleshoot/cmd/preflight" supportRoot := "github.com/replicatedhq/troubleshoot/cmd/troubleshoot" @@ -369,6 +370,54 @@ func main() { preflightHit := false supportHit := false + + // Track whether e2e test files were directly changed per suite and collect specific test names + changedPreflightTests := make(map[string]struct{}) + changedSupportTests := make(map[string]struct{}) + preflightE2EChangedNonGo := false + supportE2EChangedNonGo := false + for _, f := range files { + if strings.HasPrefix(f, "test/e2e/preflight/") { + if strings.HasSuffix(f, "_test.go") { + // Extract test names from just this file + b, err := os.ReadFile(f) + if err == nil { // ignore read errors; they will be caught later if needed + scanner := bufio.NewScanner(bytes.NewReader(b)) + re := regexp.MustCompile(`^func\s+(Test[\w\d_]+)\s*\(`) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if m := re.FindStringSubmatch(line); m != nil { + changedPreflightTests[m[1]] = struct{}{} + } + } + } + preflightHit = true + } else { + // Non-go change under preflight e2e; run whole suite + preflightE2EChangedNonGo = true + preflightHit = true + } + } + if strings.HasPrefix(f, "test/e2e/support-bundle/") { + if strings.HasSuffix(f, "_test.go") { + b, err := os.ReadFile(f) + if err == nil { + scanner := bufio.NewScanner(bytes.NewReader(b)) + re := regexp.MustCompile(`^func\s+(Test[\w\d_]+)\s*\(`) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if m := re.FindStringSubmatch(line); m != nil { + changedSupportTests[m[1]] = struct{}{} + } + } + } + supportHit = true + } else { + supportE2EChangedNonGo = true + supportHit = true + } + } + } for changed := range directPkgs { if !preflightHit { if _, ok := preflightDeps[changed]; ok { @@ -414,22 +463,53 @@ func main() { // Collect tests for impacted suites and print as `:` if preflightHit || supportHit { if preflightHit { - preTests, err := listTestFunctions("test/e2e/preflight") - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(2) + toPrint := make(map[string]struct{}) + if preflightE2EChangedNonGo || len(changedPreflightTests) == 0 { + // Run full suite if e2e non-go assets changed or no specific test names collected + preTests, err := listTestFunctions("test/e2e/preflight") + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(2) + } + for _, t := range preTests { + toPrint[t] = struct{}{} + } + } else { + for t := range changedPreflightTests { + toPrint[t] = struct{}{} + } } - for _, tname := range preTests { + var list []string + for t := range toPrint { + list = append(list, t) + } + sort.Strings(list) + for _, tname := range list { fmt.Printf("preflight:%s\n", tname) } } if supportHit { - sbTests, err := listTestFunctions("test/e2e/support-bundle") - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(2) + toPrint := make(map[string]struct{}) + if supportE2EChangedNonGo || len(changedSupportTests) == 0 { + sbTests, err := listTestFunctions("test/e2e/support-bundle") + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(2) + } + for _, t := range sbTests { + toPrint[t] = struct{}{} + } + } else { + for t := range changedSupportTests { + toPrint[t] = struct{}{} + } } - for _, tname := range sbTests { + var list []string + for t := range toPrint { + list = append(list, t) + } + sort.Strings(list) + for _, tname := range list { fmt.Printf("support-bundle:%s\n", tname) } }