Skip to content
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

Add support for prefix of any character #79

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
14 changes: 14 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: go-version
description: |
A fork of tje go library `go-version` create by HashiCorp.
Original source code can be found here: https://github.com/hashicorp/go-version
The only reason we made a fork was because we had some other requirements in the regex being used in the original library.
annotations:
github.com/project-slug: BESTSELLER/go-version
spec:
type: library
lifecycle: production
owner: engineering-services
4 changes: 2 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ var (
// The raw regular expression string used for testing the validity
// of a version.
const (
VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
VersionRegexpRaw string = `(?:\w+\-)*v?([0-9]+(\.[0-9]+)*?)` +
`(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
`?`

// SemverRegexpRaw requires a separator between version and prerelease
SemverRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
SemverRegexpRaw string = `(?:\w+\-)*v?([0-9]+(\.[0-9]+)*?)` +
`(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
`?`
Expand Down
10 changes: 10 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestNewVersion(t *testing.T) {
{"1.7rc2", false},
{"v1.7rc2", false},
{"1.0-", false},
{"controller-v0.40.2", false},
{"azure-cli-v1.4.2", false},
}

for _, tc := range cases {
Expand Down Expand Up @@ -77,6 +79,8 @@ func TestNewSemver(t *testing.T) {
{"1.7rc2", true},
{"v1.7rc2", true},
{"1.0-", true},
{"controller-v0.40.2", false},
{"azure-cli-v1.4.2", false},
}

for _, tc := range cases {
Expand Down Expand Up @@ -144,6 +148,12 @@ func TestVersionCompare(t *testing.T) {
{"1.7rc2", "1.7rc1", 1},
{"1.7rc2", "1.7", -1},
{"1.2.0", "1.2.0-X-1.2.0+metadata~dist", 1},
{"controller-v0.40.2", "controller-v0.40.3", -1},
{"0.40.4", "controller-v0.40.2", 1},
{"0.40.4", "controller-v0.40.4", 0},
{"azure-cli-v1.4.2", "azure-cli-v1.4.2", 0},
{"azure-cli-v1.4.1", "azure-cli-v1.4.2", -1},
{"1.4.3", "azure-cli-v1.4.2", 1},
}

for _, tc := range cases {
Expand Down