Skip to content

Commit

Permalink
Add prefix safety to version bumper
Browse files Browse the repository at this point in the history
Avoid matching too many Go version strings in the Dockerfiles by adding
a prefix match to the Go version bumper function.

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ committed Aug 24, 2023
1 parent a9864f1 commit c3d6347
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cmd/builder-bumper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func majorVersionReplacer(old, new *goVersion) func(string) (string, error) {
}
}

func golangVersionReplacer(old, new *goVersion) func(string) (string, error) {
func golangVersionReplacer(prefix string, old, new *goVersion) func(string) (string, error) {
return func(out string) (string, error) {
return strings.ReplaceAll(out, old.golangVersion(), new.golangVersion()), nil
return strings.ReplaceAll(out, prefix+old.golangVersion(), prefix+new.golangVersion()), nil
}
}

Expand All @@ -237,11 +237,18 @@ func replaceMajor(old, current, next *goVersion) error {
},
)
}
if info.Name() == "Dockerfile" {
return replace(path,
[]func(string) (string, error){
golangVersionReplacer("GOLANG_VERSION ", old, next),
shaReplacer(old, next),
},
)
}
return replace(path,
[]func(string) (string, error){
golangVersionReplacer(old, next),
golangVersionReplacer("", old, next),
majorVersionReplacer(old, next),
shaReplacer(old, next),
},
)
})
Expand Down Expand Up @@ -304,7 +311,7 @@ func updateNextMinor(dir string) (*goVersion, error) {

err = replace(filepath.Join(current.Major(), "base/Dockerfile"),
[]func(string) (string, error){
golangVersionReplacer(current, next),
golangVersionReplacer("GOLANG_VERSION ", current, next),
shaReplacer(current, next),
},
)
Expand Down

0 comments on commit c3d6347

Please sign in to comment.