Skip to content

Commit 5b33202

Browse files
authored
Trigger all builds when go.mod/go.sum changes (#4124)
## Why When dependencies changes (go.mod/go.sum), all Go test targets must run.
1 parent 100a4a6 commit 5b33202

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

tools/testmask/targets.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,43 @@ type targetMapping struct {
1111
target string
1212
}
1313

14+
// goTriggerPatterns lists patterns that trigger all Go-dependent targets.
15+
var goTriggerPatterns = []string{
16+
"go.mod",
17+
"go.sum",
18+
}
19+
1420
var fileTargetMappings = []targetMapping{
1521
{
16-
prefixes: []string{
22+
prefixes: slices.Concat(goTriggerPatterns, []string{
23+
// Specify files that match targets below and should still trigger the "test" target.
24+
}),
25+
target: "test",
26+
},
27+
{
28+
prefixes: slices.Concat(goTriggerPatterns, []string{
1729
"experimental/aitools/",
18-
},
30+
}),
1931
target: "test-exp-aitools",
2032
},
2133
{
22-
prefixes: []string{
34+
prefixes: slices.Concat(goTriggerPatterns, []string{
2335
"experimental/apps-mcp/",
24-
},
36+
}),
2537
target: "test-exp-apps-mcp",
2638
},
2739
{
28-
prefixes: []string{
40+
prefixes: slices.Concat(goTriggerPatterns, []string{
2941
"experimental/ssh/",
3042
"acceptance/ssh/",
31-
},
43+
}),
3244
target: "test-exp-ssh",
3345
},
3446
{
35-
prefixes: []string{
47+
prefixes: slices.Concat(goTriggerPatterns, []string{
3648
"cmd/pipelines/",
3749
"acceptance/pipelines/",
38-
},
50+
}),
3951
target: "test-pipelines",
4052
},
4153
}
@@ -46,6 +58,7 @@ func GetTargets(files []string) []string {
4658
unmatchedFiles := []string{}
4759

4860
for _, file := range files {
61+
// Check all mappings for this file (a file can match multiple targets).
4962
matched := false
5063
for _, mapping := range fileTargetMappings {
5164
for _, prefix := range mapping.prefixes {
@@ -55,9 +68,6 @@ func GetTargets(files []string) []string {
5568
break
5669
}
5770
}
58-
if matched {
59-
break
60-
}
6171
}
6272
if !matched {
6373
unmatchedFiles = append(unmatchedFiles, file)

tools/testmask/targets_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,26 @@ func TestGetTargets(t *testing.T) {
4747
targets: []string{"test"},
4848
},
4949
{
50-
name: "mixed_matching_and_unmatched",
50+
name: "go_mod_triggers_all",
51+
files: []string{
52+
"go.mod",
53+
},
54+
targets: []string{"test", "test-exp-aitools", "test-exp-apps-mcp", "test-exp-ssh", "test-pipelines"},
55+
},
56+
{
57+
name: "go_sum_triggers_all",
58+
files: []string{
59+
"go.sum",
60+
},
61+
targets: []string{"test", "test-exp-aitools", "test-exp-apps-mcp", "test-exp-ssh", "test-pipelines"},
62+
},
63+
{
64+
name: "go_mod_with_other_files_triggers_all",
5165
files: []string{
5266
"experimental/ssh/main.go",
5367
"go.mod",
5468
},
55-
targets: []string{"test", "test-exp-ssh"},
69+
targets: []string{"test", "test-exp-aitools", "test-exp-apps-mcp", "test-exp-ssh", "test-pipelines"},
5670
},
5771
{
5872
name: "empty_files",

0 commit comments

Comments
 (0)