Skip to content

Commit 8762bd1

Browse files
committed
changed tests always are flagged as affected tests
1 parent a2a424b commit 8762bd1

File tree

3 files changed

+118
-12
lines changed

3 files changed

+118
-12
lines changed

.github/workflows/build-test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ jobs:
4747
- uses: actions/checkout@v5
4848
- uses: ./.github/actions/setup-go
4949

50+
- name: Cache Go build and modules
51+
uses: actions/cache@v4
52+
with:
53+
path: |
54+
~/.cache/go-build
55+
~/go/pkg/mod
56+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
57+
restore-keys: |
58+
${{ runner.os }}-go-
59+
60+
- name: Go mod download
61+
run: go mod download
62+
5063
- name: Check go mod tidy
5164
run: |
5265
go mod tidy
@@ -91,6 +104,19 @@ jobs:
91104
steps:
92105
- uses: actions/checkout@v5
93106
- uses: ./.github/actions/setup-go
107+
108+
- name: Cache Go build and modules
109+
uses: actions/cache@v4
110+
with:
111+
path: |
112+
~/.cache/go-build
113+
~/go/pkg/mod
114+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
115+
restore-keys: |
116+
${{ runner.os }}-go-
117+
118+
- name: Go mod download
119+
run: go mod download
94120
- run: make build
95121
- uses: actions/upload-artifact@v4
96122
with:

.github/workflows/regression-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Regression Test Suite
22

33
on:
44
push:
5-
branches: [main, v1beta3]
5+
branches: [main]
66
workflow_dispatch:
77
inputs:
88
update_baselines:

scripts/affected-packages.go

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ func main() {
352352
fmt.Println(p)
353353
}
354354
case "suites":
355-
// Determine impacted suites by dependency mapping, then print exact test names for those suites.
355+
// Determine impacted suites by dependency mapping and direct e2e test changes,
356+
// then print exact test names for those suites.
356357
preflightRoot := "github.com/replicatedhq/troubleshoot/cmd/preflight"
357358
supportRoot := "github.com/replicatedhq/troubleshoot/cmd/troubleshoot"
358359

@@ -369,6 +370,54 @@ func main() {
369370

370371
preflightHit := false
371372
supportHit := false
373+
374+
// Track whether e2e test files were directly changed per suite and collect specific test names
375+
changedPreflightTests := make(map[string]struct{})
376+
changedSupportTests := make(map[string]struct{})
377+
preflightE2EChangedNonGo := false
378+
supportE2EChangedNonGo := false
379+
for _, f := range files {
380+
if strings.HasPrefix(f, "test/e2e/preflight/") {
381+
if strings.HasSuffix(f, "_test.go") {
382+
// Extract test names from just this file
383+
b, err := os.ReadFile(f)
384+
if err == nil { // ignore read errors; they will be caught later if needed
385+
scanner := bufio.NewScanner(bytes.NewReader(b))
386+
re := regexp.MustCompile(`^func\s+(Test[\w\d_]+)\s*\(`)
387+
for scanner.Scan() {
388+
line := strings.TrimSpace(scanner.Text())
389+
if m := re.FindStringSubmatch(line); m != nil {
390+
changedPreflightTests[m[1]] = struct{}{}
391+
}
392+
}
393+
}
394+
preflightHit = true
395+
} else {
396+
// Non-go change under preflight e2e; run whole suite
397+
preflightE2EChangedNonGo = true
398+
preflightHit = true
399+
}
400+
}
401+
if strings.HasPrefix(f, "test/e2e/support-bundle/") {
402+
if strings.HasSuffix(f, "_test.go") {
403+
b, err := os.ReadFile(f)
404+
if err == nil {
405+
scanner := bufio.NewScanner(bytes.NewReader(b))
406+
re := regexp.MustCompile(`^func\s+(Test[\w\d_]+)\s*\(`)
407+
for scanner.Scan() {
408+
line := strings.TrimSpace(scanner.Text())
409+
if m := re.FindStringSubmatch(line); m != nil {
410+
changedSupportTests[m[1]] = struct{}{}
411+
}
412+
}
413+
}
414+
supportHit = true
415+
} else {
416+
supportE2EChangedNonGo = true
417+
supportHit = true
418+
}
419+
}
420+
}
372421
for changed := range directPkgs {
373422
if !preflightHit {
374423
if _, ok := preflightDeps[changed]; ok {
@@ -414,22 +463,53 @@ func main() {
414463
// Collect tests for impacted suites and print as `<suite>:<TestName>`
415464
if preflightHit || supportHit {
416465
if preflightHit {
417-
preTests, err := listTestFunctions("test/e2e/preflight")
418-
if err != nil {
419-
fmt.Fprintln(os.Stderr, err)
420-
os.Exit(2)
466+
toPrint := make(map[string]struct{})
467+
if preflightE2EChangedNonGo || len(changedPreflightTests) == 0 {
468+
// Run full suite if e2e non-go assets changed or no specific test names collected
469+
preTests, err := listTestFunctions("test/e2e/preflight")
470+
if err != nil {
471+
fmt.Fprintln(os.Stderr, err)
472+
os.Exit(2)
473+
}
474+
for _, t := range preTests {
475+
toPrint[t] = struct{}{}
476+
}
477+
} else {
478+
for t := range changedPreflightTests {
479+
toPrint[t] = struct{}{}
480+
}
481+
}
482+
var list []string
483+
for t := range toPrint {
484+
list = append(list, t)
421485
}
422-
for _, tname := range preTests {
486+
sort.Strings(list)
487+
for _, tname := range list {
423488
fmt.Printf("preflight:%s\n", tname)
424489
}
425490
}
426491
if supportHit {
427-
sbTests, err := listTestFunctions("test/e2e/support-bundle")
428-
if err != nil {
429-
fmt.Fprintln(os.Stderr, err)
430-
os.Exit(2)
492+
toPrint := make(map[string]struct{})
493+
if supportE2EChangedNonGo || len(changedSupportTests) == 0 {
494+
sbTests, err := listTestFunctions("test/e2e/support-bundle")
495+
if err != nil {
496+
fmt.Fprintln(os.Stderr, err)
497+
os.Exit(2)
498+
}
499+
for _, t := range sbTests {
500+
toPrint[t] = struct{}{}
501+
}
502+
} else {
503+
for t := range changedSupportTests {
504+
toPrint[t] = struct{}{}
505+
}
506+
}
507+
var list []string
508+
for t := range toPrint {
509+
list = append(list, t)
431510
}
432-
for _, tname := range sbTests {
511+
sort.Strings(list)
512+
for _, tname := range list {
433513
fmt.Printf("support-bundle:%s\n", tname)
434514
}
435515
}

0 commit comments

Comments
 (0)