Skip to content

Commit 3994757

Browse files
committed
fix: make the order of upgradeable sauces deterministic
1 parent 7e010fe commit 3994757

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

internal/cli/check.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
117117
cmd.Println("Checking for new versions...")
118118

119119
errorsFound := false
120-
upgrades := make(map[*recipe.Sauce]string)
120+
latestSauceVersions := make(map[*recipe.Sauce]string)
121121
for _, sauce := range sauces {
122122
versions, err := recipeutil.CheckForUpdates(sauce, opts.OCIRepository)
123123
if err != nil {
@@ -126,18 +126,28 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
126126

127127
} else if len(versions) > 0 {
128128
cmd.Printf("🔄 %s: new versions found: %s\n", sauce.Recipe.Name, strings.Join(versions, ", "))
129-
upgrades[sauce] = versions[len(versions)-1]
129+
latestSauceVersions[sauce] = versions[len(versions)-1]
130130

131131
} else {
132132
cmd.Printf("👍 %s: no new versions found\n", sauce.Recipe.Name)
133133
}
134134
}
135135

136+
cmd.Println()
137+
138+
// Construct a list of upgradeable sauces so the order is deterministic when we list them
139+
upgradeableSauces := make([]*recipe.Sauce, 0, len(latestSauceVersions))
140+
for _, sauce := range sauces {
141+
if _, ok := latestSauceVersions[sauce]; ok {
142+
upgradeableSauces = append(upgradeableSauces, sauce)
143+
}
144+
}
145+
136146
if !opts.Upgrade {
137-
if len(upgrades) > 0 {
138-
cmd.Println("\nTo upgrade recipes to the latest version run:")
139-
for sauce, version := range upgrades {
140-
cmd.Printf(" %s upgrade %s:%s\n", os.Args[0], sauce.CheckFrom, version)
147+
if len(latestSauceVersions) > 0 {
148+
cmd.Println("To upgrade recipes to the latest version run:")
149+
for _, sauce := range upgradeableSauces {
150+
cmd.Printf(" %s upgrade %s:%s\n", os.Args[0], sauce.CheckFrom, latestSauceVersions[sauce])
141151
}
142152
cmd.Println("\nor rerun the command with '--upgrade' flag to upgrade all recipes to the latest version.")
143153
}
@@ -146,7 +156,7 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
146156
switch {
147157
case errorsFound:
148158
exitCode = ExitCodeError
149-
case len(upgrades) > 0 && opts.UseDetailedExitCode:
159+
case len(latestSauceVersions) > 0 && opts.UseDetailedExitCode:
150160
exitCode = ExitCodeUpdatesAvailable
151161
default:
152162
exitCode = ExitCodeOK
@@ -158,11 +168,10 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
158168
return nil
159169
}
160170

161-
cmd.Println()
162171
n := 0
163-
for sauce, version := range upgrades {
172+
for _, sauce := range upgradeableSauces {
164173
err := runUpgrade(cmd, upgradeOptions{
165-
RecipeURL: fmt.Sprintf("%s:%s", sauce.CheckFrom, version),
174+
RecipeURL: fmt.Sprintf("%s:%s", sauce.CheckFrom, latestSauceVersions[sauce]),
166175
SauceID: sauce.ID.String(),
167176
ReuseOldValues: true,
168177
Common: opts.Common,
@@ -174,7 +183,7 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
174183
}
175184

176185
n++
177-
if n <= len(upgrades) {
186+
if n <= len(latestSauceVersions) {
178187
cmd.Print("\n- - - - - - - - - -\n\n")
179188
}
180189
}

0 commit comments

Comments
 (0)