Go: Output setup-go compatible pre-release identifiers

This commit is contained in:
Michael B. Gale
2024-06-06 17:14:45 +00:00
parent c0142c1a91
commit 2662808629
2 changed files with 9 additions and 1 deletions

View File

@@ -132,5 +132,10 @@ func (ver semVer) MajorMinor() SemVer {
}
func (ver semVer) StandardSemVer() string {
return string(ver)[1:]
// Drop the 'v' prefix from the version string.
result := string(ver)[1:]
// Correct the pre-release identifier for use with `setup-go`, if one is present.
// This still remains a standard semantic version.
return strings.Replace(result, "-rc", "-rc.", 1)
}

View File

@@ -1,6 +1,7 @@
package util
import (
"strings"
"testing"
"golang.org/x/mod/semver"
@@ -52,6 +53,8 @@ func TestNewSemVer(t *testing.T) {
result,
)
}
expected = strings.Replace(expected, "-rc1", "-rc.1", 1)
if result.StandardSemVer() != expected[1:] {
t.Errorf(
"Expected NewSemVer(\"%s\").StandardSemVer() to return \"%s\", but got \"%s\".",