diff --git a/catalog-info.yaml b/catalog-info.yaml new file mode 100644 index 0000000..172e77c --- /dev/null +++ b/catalog-info.yaml @@ -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 diff --git a/version.go b/version.go index e87df69..14d2dcf 100644 --- a/version.go +++ b/version.go @@ -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\-~]+)*))?` + `?` diff --git a/version_test.go b/version_test.go index 08cbf01..3e3e13f 100644 --- a/version_test.go +++ b/version_test.go @@ -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 { @@ -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 { @@ -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 {