Skip to content

Commit 366845a

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

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

internal/cli/check.go

+17-9
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,26 @@ 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+
// Construct a list of upgradeable sauces so the order is deterministic when we list them
137+
upgradeableSauces := make([]*recipe.Sauce, 0, len(latestSauceVersions))
138+
for _, sauce := range sauces {
139+
if _, ok := latestSauceVersions[sauce]; ok {
140+
upgradeableSauces = append(upgradeableSauces, sauce)
141+
}
142+
}
143+
136144
if !opts.Upgrade {
137-
if len(upgrades) > 0 {
145+
if len(latestSauceVersions) > 0 {
138146
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+
for _, sauce := range upgradeableSauces {
148+
cmd.Printf(" %s upgrade %s:%s\n", os.Args[0], sauce.CheckFrom, latestSauceVersions[sauce])
141149
}
142150
cmd.Println("\nor rerun the command with '--upgrade' flag to upgrade all recipes to the latest version.")
143151
}
@@ -146,7 +154,7 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
146154
switch {
147155
case errorsFound:
148156
exitCode = ExitCodeError
149-
case len(upgrades) > 0 && opts.UseDetailedExitCode:
157+
case len(latestSauceVersions) > 0 && opts.UseDetailedExitCode:
150158
exitCode = ExitCodeUpdatesAvailable
151159
default:
152160
exitCode = ExitCodeOK
@@ -160,9 +168,9 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
160168

161169
cmd.Println()
162170
n := 0
163-
for sauce, version := range upgrades {
171+
for _, sauce := range upgradeableSauces {
164172
err := runUpgrade(cmd, upgradeOptions{
165-
RecipeURL: fmt.Sprintf("%s:%s", sauce.CheckFrom, version),
173+
RecipeURL: fmt.Sprintf("%s:%s", sauce.CheckFrom, latestSauceVersions[sauce]),
166174
SauceID: sauce.ID.String(),
167175
ReuseOldValues: true,
168176
Common: opts.Common,
@@ -174,7 +182,7 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
174182
}
175183

176184
n++
177-
if n <= len(upgrades) {
185+
if n <= len(latestSauceVersions) {
178186
cmd.Print("\n- - - - - - - - - -\n\n")
179187
}
180188
}

0 commit comments

Comments
 (0)