Skip to content

Commit 9865633

Browse files
authored
internal/repotools: Tombstone Module Support (#1285)
1 parent 990263b commit 9865633

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

internal/repotools/release/calculate.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log"
1010
"path"
1111
"path/filepath"
12+
"sort"
1213
)
1314

1415
// ModuleFinder is a type that
@@ -36,6 +37,13 @@ func Calculate(finder ModuleFinder, tags git.ModuleTags, config repotools.Config
3637
}
3738

3839
modules := make(map[string]*Module)
40+
var repositoryModuleTombstonePaths []string
41+
42+
for moduleDir := range tags {
43+
if _, ok := repositoryModules[moduleDir]; !ok {
44+
repositoryModuleTombstonePaths = append(repositoryModuleTombstonePaths, moduleDir)
45+
}
46+
}
3947

4048
for moduleDir := range repositoryModules {
4149
moduleFile, err := gomod.LoadModuleFile(filepath.Join(rootDir, moduleDir), nil, true)
@@ -63,14 +71,25 @@ func Calculate(finder ModuleFinder, tags git.ModuleTags, config repotools.Config
6371
log.Fatalf("failed to get git changes: %v", err)
6472
}
6573

66-
hasChanges, err = gomod.IsModuleChanged(moduleDir, repositoryModules[moduleDir], changes)
74+
subModulePaths := repositoryModules[moduleDir]
75+
76+
ignoredModulePaths := make([]string, 0, len(subModulePaths)+len(repositoryModuleTombstonePaths))
77+
ignoredModulePaths = append(ignoredModulePaths, subModulePaths...)
78+
79+
if len(repositoryModuleTombstonePaths) > 0 {
80+
ignoredModulePaths = append(ignoredModulePaths, repositoryModuleTombstonePaths...)
81+
// IsModuleChanged expects the provided list of ignored modules paths to be sorted
82+
sort.Strings(ignoredModulePaths)
83+
}
84+
85+
hasChanges, err = gomod.IsModuleChanged(moduleDir, ignoredModulePaths, changes)
6786
if err != nil {
6887
return nil, fmt.Errorf("failed to determine module changes: %w", err)
6988
}
7089

7190
if !hasChanges {
7291
// Check if any of the submodules have been "carved out" of this module since the last tagged release
73-
for _, subModuleDir := range repositoryModules[moduleDir] {
92+
for _, subModuleDir := range subModulePaths {
7493
if _, ok := tags.Latest(subModuleDir); ok {
7594
continue
7695
}

0 commit comments

Comments
 (0)