From a62f4f076365adbc060216fd0c974c5607765ed7 Mon Sep 17 00:00:00 2001 From: yokomotod Date: Tue, 14 Feb 2023 02:26:16 +0900 Subject: [PATCH] sort modules.json for stable order (#32618) --- internal/modsdir/manifest.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/modsdir/manifest.go b/internal/modsdir/manifest.go index 2821ce804317..fbb35919cc79 100644 --- a/internal/modsdir/manifest.go +++ b/internal/modsdir/manifest.go @@ -8,6 +8,7 @@ import ( "log" "os" "path/filepath" + "sort" "strings" version "github.com/hashicorp/go-version" @@ -136,7 +137,14 @@ func ReadManifestSnapshotForDir(dir string) (Manifest, error) { func (m Manifest) WriteSnapshot(w io.Writer) error { var write manifestSnapshotFile - for _, record := range m { + var keys []string + for k := range m { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { + record := m[k] + // Make sure VersionStr is in sync with Version, since we encourage // callers to manipulate Version and ignore VersionStr. if record.Version != nil {