Skip to content

Commit

Permalink
Merge pull request #258 from snyk/fix/stable-backstage-api-order
Browse files Browse the repository at this point in the history
fix: make order of apis in generated catalog-info stable
  • Loading branch information
jgresty authored Nov 28, 2022
2 parents 0d195c2 + 503755d commit 6fa536d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/cmd/backstage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sort"

"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -156,7 +157,17 @@ func processCatalog(ctx *cli.Context, w io.Writer) error {
return true
}
}
for _, apiConf := range proj.APIs {

// range over maps does not specify order and is not guaranteed to be the
// same from one iteration to the next, stability is important when
// generating catalog-info to produce reproducible results
var apiNames []string
for k := range proj.APIs {
apiNames = append(apiNames, k)
}
sort.Strings(apiNames)
for _, apiName := range apiNames {
apiConf := proj.APIs[apiName]
outputPaths := apiConf.Output.ResolvePaths()
for _, outputPath := range outputPaths {
outputPath = filepath.Join(projectDir, outputPath)
Expand Down

0 comments on commit 6fa536d

Please sign in to comment.