From 3e4fbbaae44cb0e0e59d60ca9385757c356b942b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 26 Dec 2016 14:03:50 +0100 Subject: [PATCH] helpers: Add patch version Fixes #2832 --- helpers/hugo.go | 24 ++++++++++++++++++------ helpers/hugo_test.go | 10 +++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/helpers/hugo.go b/helpers/hugo.go index 0a6fdebc7..25abd2bce 100644 --- a/helpers/hugo.go +++ b/helpers/hugo.go @@ -19,7 +19,13 @@ import ( // HugoVersionNumber represents the current build version. // This should be the only one -const HugoVersionNumber = 0.19 +const ( + // Major and minor version. + HugoVersionNumber = 0.19 + + // Increment this for bug releases + HugoPatchVersion = 0 +) // HugoVersionSuffix is the suffix used in the Hugo version string. // It will be blank for release versions. @@ -29,23 +35,29 @@ const HugoVersionSuffix = "-DEV" // use this when not doing a release // HugoVersion returns the current Hugo version. It will include // a suffix, typically '-DEV', if it's development version. func HugoVersion() string { - return hugoVersion(HugoVersionNumber, HugoVersionSuffix) + return hugoVersion(HugoVersionNumber, HugoPatchVersion, HugoVersionSuffix) } // HugoReleaseVersion is same as HugoVersion, but no suffix. func HugoReleaseVersion() string { - return hugoVersionNoSuffix(HugoVersionNumber) + return hugoVersionNoSuffix(HugoVersionNumber, HugoPatchVersion) } // NextHugoReleaseVersion returns the next Hugo release version. func NextHugoReleaseVersion() string { - return hugoVersionNoSuffix(HugoVersionNumber + 0.01) + return hugoVersionNoSuffix(HugoVersionNumber+0.01, 0) } -func hugoVersion(version float32, suffix string) string { +func hugoVersion(version float32, patchVersion int, suffix string) string { + if patchVersion > 0 { + return fmt.Sprintf("%.2g.%d%s", version, patchVersion, suffix) + } return fmt.Sprintf("%.2g%s", version, suffix) } -func hugoVersionNoSuffix(version float32) string { +func hugoVersionNoSuffix(version float32, patchVersion int) string { + if patchVersion > 0 { + return fmt.Sprintf("%.2g.%d", version, patchVersion) + } return fmt.Sprintf("%.2g", version) } diff --git a/helpers/hugo_test.go b/helpers/hugo_test.go index a0012acdf..8dfa7f434 100644 --- a/helpers/hugo_test.go +++ b/helpers/hugo_test.go @@ -14,11 +14,15 @@ package helpers import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestHugoVersion(t *testing.T) { - assert.Equal(t, "0.15-DEV", hugoVersion(0.15, "-DEV")) - assert.Equal(t, "0.17", hugoVersionNoSuffix(0.16+0.01)) + assert.Equal(t, "0.15-DEV", hugoVersion(0.15, 0, "-DEV")) + assert.Equal(t, "0.17", hugoVersionNoSuffix(0.16+0.01, 0)) + + assert.Equal(t, "0.15.2-DEV", hugoVersion(0.15, 2, "-DEV")) + assert.Equal(t, "0.17.3", hugoVersionNoSuffix(0.16+0.01, 3)) }