[v11.3.x] CI: Support more version formats in publishing (#94750)
CI: Support more version formats in publishing (#94575)
* cleanup dead code
* add tests and rewrite publish grafanacom steps to reuse
* add pkg/build tests; don't upload CDN assets on grafana releases
(cherry picked from commit 7a2edd35d5)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package versions
|
||||
|
||||
import "regexp"
|
||||
|
||||
var semverRegex = regexp.MustCompile(`^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
|
||||
|
||||
type Semver struct {
|
||||
Major string
|
||||
Minor string
|
||||
Patch string
|
||||
Prerelease string
|
||||
BuildMetadata string
|
||||
}
|
||||
|
||||
func ParseSemver(version string) Semver {
|
||||
matches := semverRegex.FindStringSubmatch(version)
|
||||
results := make(map[string]string)
|
||||
for i, name := range semverRegex.SubexpNames() {
|
||||
if i != 0 && name != "" {
|
||||
results[name] = matches[i]
|
||||
}
|
||||
}
|
||||
|
||||
return Semver{
|
||||
Major: results["major"],
|
||||
Minor: results["minor"],
|
||||
Patch: results["patch"],
|
||||
Prerelease: results["prerelease"],
|
||||
BuildMetadata: results["buildmetadata"],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user