Skip to content

Update version parsing for beta prereleases #1075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/k8s-integration/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ var (
versionNum = `(0|[1-9][0-9]*)`
internalPatchVersion = `(\-gke\.[0-9]+)`

versionRegex = regexp.MustCompile(`^` + versionNum + `\.` + versionNum + `\.` + versionNum + internalPatchVersion + "?$")
minorVersionRegex = regexp.MustCompile(`^` + versionNum + `\.` + versionNum + `$`)
alphaVersionRegex = regexp.MustCompile(`^` + versionNum + `\.` + versionNum + `\.` + versionNum + `-alpha.*`)
gkeExtraVersionRegex = regexp.MustCompile(`^(?:gke)\.(0|[1-9][0-9]*)$`)
versionRegex = regexp.MustCompile(`^` + versionNum + `\.` + versionNum + `\.` + versionNum + internalPatchVersion + "?$")
minorVersionRegex = regexp.MustCompile(`^` + versionNum + `\.` + versionNum + `$`)
prereleaseVersionRegex = regexp.MustCompile(`^` + versionNum + `\.` + versionNum + `\.` + versionNum + `-(?:alpha|beta).*`)
gkeExtraVersionRegex = regexp.MustCompile(`^(?:gke)\.(0|[1-9][0-9]*)$`)
)

type version struct {
Expand All @@ -26,7 +26,7 @@ type version struct {

func (v *version) String() string {
if v.version[3] == -2 {
return fmt.Sprintf("%d.%d.%d-alpha", v.version[0], v.version[1], v.version[2])
return fmt.Sprintf("%d.%d.%d-prerelease", v.version[0], v.version[1], v.version[2])
} else if v.version[3] != -1 {
return fmt.Sprintf("%d.%d.%d-gke.%d", v.version[0], v.version[1], v.version[2], v.version[3])
}
Expand Down Expand Up @@ -85,8 +85,8 @@ func parseVersion(vs string) (*version, error) {
case versionRegex.MatchString(vs):
submatches = versionRegex.FindStringSubmatch(vs)
lastIndex = 4
case alphaVersionRegex.MatchString(vs):
submatches = alphaVersionRegex.FindStringSubmatch(vs)
case prereleaseVersionRegex.MatchString(vs):
submatches = prereleaseVersionRegex.FindStringSubmatch(vs)
v.version[3] = -2
lastIndex = 4
case minorVersionRegex.MatchString(vs):
Expand All @@ -106,7 +106,7 @@ func parseVersion(vs string) (*version, error) {
}
}

if minorVersionRegex.MatchString(vs) || alphaVersionRegex.MatchString(vs) {
if minorVersionRegex.MatchString(vs) || prereleaseVersionRegex.MatchString(vs) {
return &v, nil
}

Expand Down
10 changes: 8 additions & 2 deletions test/k8s-integration/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func TestParseVersion(t *testing.T) {
version: [4]int{1, 26, 0, -2},
},
},
{
version: "v1.26.0-beta.0.25+4b1b42624e06a9",
expectedV: version{
version: [4]int{1, 26, 0, -2},
},
},
// Negative test cases
{
version: "1",
Expand Down Expand Up @@ -112,11 +118,11 @@ func TestParseVersion(t *testing.T) {
expectErr: true,
},
{
version: "1.18.0-beta.x",
version: "1.18.0-zeta.x",
expectErr: true,
},
{
version: "1.18.0-beta.alpha.1",
version: "1.18.0-zeta.alpha.1",
expectErr: true,
},
{
Expand Down