From 5f831a622337d6a1d33a28a21391ba682030f21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 5 Jul 2017 10:23:07 +0200 Subject: releaser: Replace the magic version handling Take the new version as a string value. --- releaser/releaser.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'releaser/releaser.go') diff --git a/releaser/releaser.go b/releaser/releaser.go index 52a74dc7e..52589e8b7 100644 --- a/releaser/releaser.go +++ b/releaser/releaser.go @@ -31,7 +31,7 @@ import ( const commitPrefix = "releaser:" type ReleaseHandler struct { - patch int + cliVersion string // If set, we do the releases in 3 steps: // 1: Create and write a draft release notes @@ -62,24 +62,16 @@ func (r ReleaseHandler) shouldPrepareVersions() bool { return r.step < 1 || r.step == 2 } -func (r ReleaseHandler) calculateVersions(current helpers.HugoVersion) (helpers.HugoVersion, helpers.HugoVersion) { - var ( - newVersion = current - finalVersion = current - ) +func (r ReleaseHandler) calculateVersions() (helpers.HugoVersion, helpers.HugoVersion) { + + newVersion := helpers.MustParseHugoVersion(r.cliVersion) + finalVersion := newVersion + finalVersion.PatchLevel = 0 newVersion.Suffix = "" - if r.shouldContinue() { - // The version in the current code base is in the state we want for - // the release. - if r.patch == 0 { - finalVersion = newVersion.Next() - } - } else if r.patch > 0 { - newVersion = helpers.CurrentHugoVersion.NextPatchLevel(r.patch) - } else { - finalVersion = newVersion.Next() + if newVersion.PatchLevel == 0 { + finalVersion = finalVersion.Next() } finalVersion.Suffix = "-DEV" @@ -87,8 +79,8 @@ func (r ReleaseHandler) calculateVersions(current helpers.HugoVersion) (helpers. return newVersion, finalVersion } -func New(patch, step int, skipPublish, try bool) *ReleaseHandler { - rh := &ReleaseHandler{patch: patch, step: step, skipPublish: skipPublish, try: try} +func New(version string, step int, skipPublish, try bool) *ReleaseHandler { + rh := &ReleaseHandler{cliVersion: version, step: step, skipPublish: skipPublish, try: try} if try { rh.git = func(args ...string) (string, error) { @@ -107,7 +99,7 @@ func (r *ReleaseHandler) Run() error { return errors.New("GITHUB_TOKEN not set, create one here with the repo scope selected: https://github.com/settings/tokens/new") } - newVersion, finalVersion := r.calculateVersions(helpers.CurrentHugoVersion) + newVersion, finalVersion := r.calculateVersions() version := newVersion.String() tag := "v" + version -- cgit v1.2.3