Skip to content

Commit

Permalink
feat: enable workflow input to define dependency level resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverqx committed Apr 3, 2024
1 parent 12dc6f5 commit 4a316fd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions contrib/git-changes-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

moduledetector "github.com/synapsecns/sanguine/contrib/git-changes-action/detector/module"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/package"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/tree"

Expand All @@ -21,6 +22,7 @@ const defaultTimeout = "1m"

func main() {
token := githubactions.GetInput("github_token")
dependencyLevelResolution := githubactions.GetInput("dependencyLevelResolution")

workingDirectory, err := os.Getwd()
if err != nil {
Expand All @@ -43,12 +45,12 @@ func main() {
panic(err)
}

noDepChanged, noDepUnchanged, err := outputModuleChanges(workingDirectory, ct, false)
noDepChanged, noDepUnchanged, err := outputModuleChanges(workingDirectory, ct, false, dependencyLevelResolution)
if err != nil {
panic(err)
}

depChanged, depUnchanged, err := outputModuleChanges(workingDirectory, ct, true)
depChanged, depUnchanged, err := outputModuleChanges(workingDirectory, ct, true, dependencyLevelResolution)
if err != nil {
panic(err)
}
Expand All @@ -63,8 +65,15 @@ func main() {
// outputModuleChanges outputs the changed modules.
// this wraps detector.DetectChangedModules and handles the output formatting to be parsable by github actions.
// the final output is a json array of strings.
func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool) (changedJSON string, unchangedJson string, err error) {
modules, err := packagedetector.DetectChangedModules(workingDirectory, ct, includeDeps)
func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool, dependencyLevelResolution string) (changedJSON string, unchangedJson string, err error) {
var modules map[string]bool

if (dependencyLevelResolution == "packages") {
modules, err = packagedetector.DetectChangedModules(workingDirectory, ct, includeDeps)
} else {
modules, err = moduledetector.DetectChangedModules(workingDirectory, ct, includeDeps)
}

if err != nil {
return changedJSON, unchangedJson, fmt.Errorf("failed to detect changed modules w/ include deps set to %v: %w", includeDeps, err)
}
Expand Down

0 comments on commit 4a316fd

Please sign in to comment.