Skip to content

Commit cebab81

Browse files
committed
Exclude directories with changed .go files which aren't returned by go list
1 parent c745edb commit cebab81

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

find-affected-packages.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ func main() {
3333
func calcAffectedPackages(localPackagesToDeps packagesToDepMap, changedLocalPackages, changedModules []string) []string {
3434
affectedPackageMap := make(map[string]bool)
3535
for _, pkg := range changedLocalPackages {
36-
// Any directly changed package is affected (obviously)
37-
affectedPackageMap[pkg] = true
36+
if _, ok := localPackagesToDeps[pkg]; ok {
37+
// Any directly changed package is affected, as long as it came back from `go list <filterPackages>`
38+
affectedPackageMap[pkg] = true
39+
}
3840

3941
// Add all packages which depend on this changed package (including indirectly)
4042
for pkgPath, pkgDeps := range localPackagesToDeps {

find-affected-packages_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ func TestCalcAffectedPackages(t *testing.T) {
2626
"github.com/orgA/repoA/subPkg3": true,
2727
},
2828
}
29-
changedLocalPackages := []string{"github.com/orgA/repoA/subPkg3"}
29+
changedLocalPackages := []string{
30+
"github.com/orgA/repoA/subPkg3",
31+
"github.com/orgA/repoA/notRealPkg", // To simulate cases where we see a .go file changed somewhere that isn't a package go list returned
32+
}
3033
changedModules := []string{"github.com/orgB/repoB"}
3134

3235
affectedPackages := calcAffectedPackages(packagesToDeps, changedLocalPackages, changedModules)

0 commit comments

Comments
 (0)