Skip to content

Commit

Permalink
Sort output of check command
Browse files Browse the repository at this point in the history
  • Loading branch information
tomleb committed May 3, 2024
1 parent 9fdfa48 commit 2004261
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ func checkCmd() cli.Command {
return err
}

hasError := false

if local.GoVersion != k8s.GoVersion {
log.Printf("Go version is different, local=%s vs upstream=%s\n", local.GoVersion, k8s.GoVersion)
}
Expand All @@ -350,6 +348,13 @@ func checkCmd() cli.Command {
}
}

type modDiff struct {
Path string
LocalVersion string
UpstreamVersion string
}

differences := []modDiff{}
for kpkg, kver := range k8s.Deps {
lver, exists := local.Deps[kpkg]
if !exists {
Expand All @@ -362,12 +367,22 @@ func checkCmd() cli.Command {
}

if kver != lver {
log.Printf("Package %q is different, local=%s vs upstream=%s\n", kpkg, lver, kver)
hasError = true
differences = append(differences, modDiff{
Path: kpkg,
LocalVersion: lver,
UpstreamVersion: kver,
})
}
}

if hasError {
sort.Slice(differences, func(i, j int) bool {
return differences[i].Path < differences[j].Path
})

if len(differences) > 0 {
for _, diff := range differences {
log.Printf("Package %q is different, local=%s vs upstream=%s\n", diff.Path, diff.LocalVersion, diff.UpstreamVersion)
}
return fmt.Errorf("some dependencies are not pinned to k8s upstream's version")
}

Expand Down

0 comments on commit 2004261

Please sign in to comment.