Permalink
Browse files

releaser: Fix version calculation

  • Loading branch information...
bep committed Apr 24, 2017
1 parent 37d4001 commit cb3c6b6f7670f85189a4a3637e7132901d1ed6e9
Showing with 47 additions and 13 deletions.
  1. +3 −0 helpers/hugo.go
  2. +9 −0 releaser/git.go
  3. +6 −0 releaser/git_test.go
  4. +0 −2 releaser/releasenotes_writer_test.go
  5. +3 −4 releaser/releaser.go
  6. +26 −7 releaser/releaser_test.go
View
@@ -56,6 +56,9 @@ func (v HugoVersion) Prev() HugoVersion {
// NextPatchLevel returns the next patch/bugfix Hugo version.
// This will be a patch increment on the previous Hugo version.
func (v HugoVersion) NextPatchLevel(level int) HugoVersion {
if v.PatchLevel > 0 {
return HugoVersion{Number: v.Number, PatchLevel: level}
}
return HugoVersion{Number: v.Number - 0.01, PatchLevel: level}
}
View
@@ -207,6 +207,15 @@ func (g gitInfos) ContribCountPerAuthor() contribCounts {
return c
}
func getCurrentBranch() (string, error) {
return gitShort("rev-parse", "--abbrev-ref", "HEAD")
}
func isMaster() bool {
curr, _ := getCurrentBranch()
return curr == "master"
}
func getGitInfosBefore(ref string, remote bool) (gitInfos, error) {
var g gitInfos
View
@@ -51,3 +51,9 @@ See #456
require.Equal(t, 543, issues[2])
}
func TestGetCurrentBranch(t *testing.T) {
curr, err := getCurrentBranch()
require.NoError(t, err)
require.Equal(t, (curr == "master"), isMaster())
}
@@ -18,7 +18,6 @@ package releaser
import (
"bytes"
"fmt"
"testing"
"runtime"
@@ -40,5 +39,4 @@ func TestReleaseNotesWriter(t *testing.T) {
require.NoError(t, writeReleaseNotes("0.20", infos, &b))
fmt.Println(">>>", b.String())
}
View
@@ -60,11 +60,10 @@ func (r ReleaseHandler) calculateVersions(current helpers.HugoVersion) (helpers.
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()
}
finalVersion = newVersion.Next()
} else if r.patch > 0 {
newVersion = helpers.CurrentHugoVersion.NextPatchLevel(r.patch)
newVersion = current.NextPatchLevel(r.patch)
finalVersion = newVersion.Next()
} else {
finalVersion = newVersion.Next()
}
View
@@ -17,6 +17,7 @@
package releaser
import (
"fmt"
"testing"
"github.com/spf13/hugo/helpers"
@@ -41,7 +42,7 @@ func TestCalculateVersions(t *testing.T) {
{
New(2, 0, true),
startVersion,
"0.20.2",
"0.19.2",
"0.20-DEV",
},
{
@@ -59,20 +60,38 @@ func TestCalculateVersions(t *testing.T) {
{
New(3, 1, true),
startVersion,
"0.20.3",
"0.19.3",
"0.20-DEV",
},
{
New(3, 2, true),
startVersion.Next(),
"0.21",
helpers.HugoVersion{Number: 0.20, PatchLevel: 2},
"0.20.2",
"0.21-DEV",
},
{
New(3, 0, true),
helpers.HugoVersion{Number: 0.20, Suffix: "", PatchLevel: 2},
"0.20.3",
"0.21-DEV",
},
{
New(3, 1, true),
helpers.HugoVersion{Number: 0.20, Suffix: "", PatchLevel: 2},
"0.20.3",
"0.21-DEV",
},
{
New(3, 2, true),
helpers.HugoVersion{Number: 0.20, Suffix: "", PatchLevel: 3},
"0.20.3",
"0.21-DEV",
},
}
for _, test := range tests {
for i, test := range tests {
v1, v2 := test.handler.calculateVersions(test.version)
require.Equal(t, test.v1, v1.String(), "Release version")
require.Equal(t, test.v2, v2.String(), "Final version")
require.Equal(t, test.v1, v1.String(), fmt.Sprintf("[%d] Release version", i))
require.Equal(t, test.v2, v2.String(), fmt.Sprintf("[%d] Final version", i))
}
}

0 comments on commit cb3c6b6

Please sign in to comment.