Open trajan0x opened 10 months ago
To sort changed_modules
by diff size, follow these steps:
Modify detector.go
:
DetectChangedModules
to return a map of module paths to their diff sizes.
func DetectChangedModules(repoPath string, ct tree.Tree, includeDeps bool) (modules map[string]int, err error) {
modules = make(map[string]int)
// existing code...
for _, module := range parsedWorkFile.Use {
diffSize := 0
if ct.HasPath(module.Path) {
diffSize = ct.GetDiffSize(module.Path) // hypothetical function to get diff size
}
if includeDeps {
deps := depGraph[module.Path]
for _, dep := range deps {
if ct.HasPath(dep) {
diffSize += ct.GetDiffSize(dep)
}
}
}
modules[module.Path] = diffSize
}
return modules, nil
}
Modify main.go
:
outputModuleChanges
to sort modules by diff size.
func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool, dependencyLevelResolution string) (changedJSON string, unchangedJSON string, err error) {
var modules map[string]int
// existing code...
var changedModules, unchangedModules []string
for module, diffSize := range modules {
modName := strings.TrimPrefix(module, "./")
if diffSize > 0 {
changedModules = append(changedModules, modName)
} else {
unchangedModules = append(unchangedModules, modName)
}
}
sort.Slice(changedModules, func(i, j int) bool {
return modules[changedModules[i]] > modules[changedModules[j]]
})
// existing code...
return string(marshalledChanged), string(marshalledUnchanged), nil
}
Update tree.Tree
:
GetDiffSize
to return the size of the diff for a given path.
func (t *Tree) GetDiffSize(path string) int {
// logic to calculate and return diff size
}
/contrib/git-changes-action/main.go /contrib/git-changes-action/detector/module/detector.go /contrib/git-changes-action
To allow faster operation on modules we care about when using max-paralell