diff --git a/go.mod b/go.mod index c77cae2..1d2ceac 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/metal-stack/metal-robot go 1.21 require ( + github.com/Masterminds/semver/v3 v3.2.1 github.com/atedja/go-multilock v0.0.0-20170315063113-31d195f255fb - github.com/blang/semver/v4 v4.0.0 github.com/bradleyfalzon/ghinstallation/v2 v2.8.0 github.com/go-git/go-billy/v5 v5.5.0 // IMPORTANT: keep this version as long as https://github.com/go-git/go-git/issues/328 is open diff --git a/go.sum b/go.sum index 53c6f57..7169992 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= +github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= @@ -51,8 +53,6 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/atedja/go-multilock v0.0.0-20170315063113-31d195f255fb h1:osgVLyVcO3XUghYODTtWUjV7O+vmwX70MMtUO2Jiq9E= github.com/atedja/go-multilock v0.0.0-20170315063113-31d195f255fb/go.mod h1:fFkhuoU3CiRTrgW+OwPwWffezYpVbEF5CREAwKuieRc= -github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= -github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bradleyfalzon/ghinstallation/v2 v2.8.0 h1:yUmoVv70H3J4UOqxqsee39+KlXxNEDfTbAp8c/qULKk= github.com/bradleyfalzon/ghinstallation/v2 v2.8.0/go.mod h1:fmPmvCiBWhJla3zDv9ZTQSZc8AbwyRnGW1yg5ep1Pcs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/pkg/webhooks/github/actions/aggregate_releases.go b/pkg/webhooks/github/actions/aggregate_releases.go index 04b5aa5..77f368e 100644 --- a/pkg/webhooks/github/actions/aggregate_releases.go +++ b/pkg/webhooks/github/actions/aggregate_releases.go @@ -9,8 +9,8 @@ import ( "errors" + "github.com/Masterminds/semver/v3" "github.com/atedja/go-multilock" - "github.com/blang/semver/v4" v3 "github.com/google/go-github/v56/github" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" @@ -113,12 +113,17 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe tag := p.TagName trimmed := strings.TrimPrefix(tag, "v") - _, err := semver.Make(trimmed) + parsedVersion, err := semver.NewVersion(trimmed) if err != nil { r.logger.Infow("skip applying release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) return nil //nolint:nilerr } + if parsedVersion.Prerelease() != "" { + r.logger.Infow("skip applying release actions to aggregation repo because is a pre-release", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) + return nil //nolint:nilerr + } + // preventing concurrent git repo modifications var once sync.Once r.lock.Lock() diff --git a/pkg/webhooks/github/actions/release_drafter.go b/pkg/webhooks/github/actions/release_drafter.go index 06c112e..6350bfa 100644 --- a/pkg/webhooks/github/actions/release_drafter.go +++ b/pkg/webhooks/github/actions/release_drafter.go @@ -6,7 +6,7 @@ import ( "regexp" "strings" - "github.com/blang/semver/v4" + "github.com/Masterminds/semver/v3" "github.com/google/go-github/v56/github" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" @@ -142,7 +142,7 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err return nil } trimmedVersion := strings.TrimPrefix(componentTag, "v") - componentSemver, err := semver.Parse(trimmedVersion) + componentSemver, err := semver.NewVersion(trimmedVersion) if err != nil { r.logger.Debugw("skip adding release draft because tag is not semver compatible", "repo", p.RepositoryName, "release", componentTag) return nil //nolint:nilerr @@ -158,7 +158,7 @@ func (r *releaseDrafter) draft(ctx context.Context, p *releaseDrafterParams) err return r.createOrUpdateRelease(ctx, infos, body, p) } -func (r *releaseDrafter) updateReleaseBody(org string, priorBody string, component string, componentVersion semver.Version, componentBody *string, releaseURL string) string { +func (r *releaseDrafter) updateReleaseBody(org string, priorBody string, component string, componentVersion *semver.Version, componentBody *string, releaseURL string) string { m := markdown.Parse(priorBody) releaseSection := ensureReleaseSection(m, r.draftHeadline) @@ -213,8 +213,8 @@ func (r *releaseDrafter) updateReleaseBody(org string, priorBody string, compone groups := utils.RegexCapture(utils.SemanticVersionMatcher, section.Heading) old := groups["full_match"] old = strings.TrimPrefix(old, "v") - oldVersion, err := semver.Parse(old) - if err == nil && componentVersion.GT(oldVersion) { + oldVersion, err := semver.NewVersion(old) + if err == nil && componentVersion.GreaterThan(oldVersion) { // in this case we need to merge contents together and update the headline section.Heading = heading section.AppendContent(body) @@ -404,12 +404,11 @@ func (r *releaseDrafter) guessNextVersionFromLatestRelease(ctx context.Context) groups := utils.RegexCapture(utils.SemanticVersionMatcher, *latest.TagName) t := groups["full_match"] t = strings.TrimPrefix(t, "v") - latestTag, err := semver.Parse(t) + latestTag, err := semver.NewVersion(t) if err != nil { r.logger.Warnw("latest release of repository was not a semver tag", "repository", r.repoName, "latest-tag", *latest.TagName) } else { - latestTag.Patch = latestTag.Patch + 1 - return "v" + latestTag.String(), nil + return "v" + latestTag.IncPatch().String(), nil } } return "v0.0.1", nil diff --git a/pkg/webhooks/github/actions/release_drafter_test.go b/pkg/webhooks/github/actions/release_drafter_test.go index 7538c99..2ed17a7 100644 --- a/pkg/webhooks/github/actions/release_drafter_test.go +++ b/pkg/webhooks/github/actions/release_drafter_test.go @@ -3,7 +3,7 @@ package actions import ( "testing" - "github.com/blang/semver/v4" + "github.com/Masterminds/semver/v3" "github.com/google/go-cmp/cmp" v3 "github.com/google/go-github/v56/github" "go.uber.org/zap/zaptest" @@ -16,7 +16,7 @@ func TestReleaseDrafter_updateReleaseBody(t *testing.T) { headline string priorBody string component string - componentVersion semver.Version + componentVersion *semver.Version componentBody *string releaseURL string diff --git a/pkg/webhooks/github/actions/yaml_translate_releases.go b/pkg/webhooks/github/actions/yaml_translate_releases.go index 7e2f490..1a260f3 100644 --- a/pkg/webhooks/github/actions/yaml_translate_releases.go +++ b/pkg/webhooks/github/actions/yaml_translate_releases.go @@ -9,8 +9,8 @@ import ( "errors" + "github.com/Masterminds/semver/v3" "github.com/atedja/go-multilock" - "github.com/blang/semver/v4" v3 "github.com/google/go-github/v56/github" "github.com/metal-stack/metal-robot/pkg/clients" "github.com/metal-stack/metal-robot/pkg/config" @@ -139,7 +139,7 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra tag := p.TagName trimmed := strings.TrimPrefix(tag, "v") - _, err := semver.Make(trimmed) + _, err := semver.NewVersion(trimmed) if err != nil { r.logger.Infow("skip applying translate release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName) return nil //nolint:nilerr diff --git a/pkg/webhooks/modifiers/file-patchers/yaml_path_patch.go b/pkg/webhooks/modifiers/file-patchers/yaml_path_patch.go index bf35a31..3a1ab10 100644 --- a/pkg/webhooks/modifiers/file-patchers/yaml_path_patch.go +++ b/pkg/webhooks/modifiers/file-patchers/yaml_path_patch.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/blang/semver/v4" + "github.com/Masterminds/semver/v3" "github.com/metal-stack/metal-robot/pkg/config" "github.com/metal-stack/metal-robot/pkg/utils" "github.com/mitchellh/mapstructure" @@ -57,7 +57,7 @@ func (p YAMLPathPatch) Apply(cn ContentReader, cw ContentWriter, newValue string if p.versionCompare { trimmedValue := strings.TrimPrefix(newValue, "v") - newVersion, err := semver.Parse(trimmedValue) + newVersion, err := semver.NewVersion(trimmedValue) if err != nil { return err } @@ -73,9 +73,9 @@ func (p YAMLPathPatch) Apply(cn ContentReader, cw ContentWriter, newValue string } old = strings.TrimPrefix(old, "v") - oldVersion, err := semver.Parse(old) + oldVersion, err := semver.NewVersion(old) if err == nil { - if !newVersion.GT(oldVersion) { + if !newVersion.GreaterThan(oldVersion) { return nil } }