Skip to content

Commit 2662808

Browse files
committed
Go: Output setup-go compatible pre-release identifiers
1 parent c0142c1 commit 2662808

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

go/extractor/util/semver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,10 @@ func (ver semVer) MajorMinor() SemVer {
132132
}
133133

134134
func (ver semVer) StandardSemVer() string {
135-
return string(ver)[1:]
135+
// Drop the 'v' prefix from the version string.
136+
result := string(ver)[1:]
137+
138+
// Correct the pre-release identifier for use with `setup-go`, if one is present.
139+
// This still remains a standard semantic version.
140+
return strings.Replace(result, "-rc", "-rc.", 1)
136141
}

go/extractor/util/semver_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package util
22

33
import (
4+
"strings"
45
"testing"
56

67
"golang.org/x/mod/semver"
@@ -52,6 +53,8 @@ func TestNewSemVer(t *testing.T) {
5253
result,
5354
)
5455
}
56+
57+
expected = strings.Replace(expected, "-rc1", "-rc.1", 1)
5558
if result.StandardSemVer() != expected[1:] {
5659
t.Errorf(
5760
"Expected NewSemVer(\"%s\").StandardSemVer() to return \"%s\", but got \"%s\".",

0 commit comments

Comments
 (0)