mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
99e5fc63c2
commit
3e4fbbaae4
2 changed files with 25 additions and 9 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue