Skip to content

Commit

Permalink
mageutils:bugfix - major rc or beta was not working
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
  • Loading branch information
nathanmartinszup committed Nov 22, 2021
1 parent 936f43c commit 73764ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
10 changes: 4 additions & 6 deletions pkg/utils/mageutils/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func CreateLocalTag(tag string) (err error) {
return sh.RunV("git", "tag", "-s", tag, "-m", "release "+tag)
}


// CheckoutReleaseBranch creates if not exists a release branch and then checkout
// @TODO validate release branch name with regex
func CheckoutReleaseBranch(branchName string) error {
mg.Deps(isGitExistent)

Expand All @@ -57,15 +59,11 @@ func CheckoutReleaseBranch(branchName string) error {
return nil
}

// GitPushAll executes "git", "push", "--all" and "git", "push", "--tags"
// GitPushAll executes "git", "push", "--all"
func GitPushAll() error {
mg.Deps(isGitExistent)

if err := sh.RunV("git", "push", "--all"); err != nil {
return err
}

return sh.RunV("git", "push", "--tags")
return sh.RunV("git", "push", "--all")
}

// GitConfig configures global email and user for git
Expand Down
20 changes: 16 additions & 4 deletions pkg/utils/mageutils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,29 @@ func (u *upVersions) upVersionNextBetaAndRc() {
}
}

// upVersionBeta increase the actual beta number by 1 and set next beta version
// upVersionBeta increase the actual beta number by 1 and set next beta version, for majors also check for new beta cont
// by verifying if the actual beta it's lower than the actual release.
func (u *upVersions) upVersionBeta() {
major, minor, patch, beta := u.getSplittedVersionBetaOrRC(u.actualBetaVersion)
if u.releaseType == majorType && u.isOlderThanActualRelease(u.actualBetaVersion) {
u.nextBetaVersion = fmt.Sprintf("%s-beta.0", u.nextReleaseVersion)

return
}

major, minor, patch, beta := u.getSplittedVersionBetaOrRC(u.actualBetaVersion)
u.nextBetaVersion = fmt.Sprintf("v%s.%s.%s-beta.%s", major, minor, patch, u.upVersion(beta))
}

// upVersionRC increase the actual rc number by 1 and set next rc version
// upVersionRC increase the actual rc number by 1 and set next rc version, for majors also check for new rc cont
// by verifying if the actual RC it's lower than the actual release.
func (u *upVersions) upVersionRC() {
major, minor, patch, rc := u.getSplittedVersionBetaOrRC(u.actualRCVersion)
if u.releaseType == majorType && u.isOlderThanActualRelease(u.actualRCVersion) {
u.nextRCVersion = fmt.Sprintf("%s-rc.0", u.nextReleaseVersion)

return
}

major, minor, patch, rc := u.getSplittedVersionBetaOrRC(u.actualRCVersion)
u.nextRCVersion = fmt.Sprintf("v%s.%s.%s-rc.%s", major, minor, patch, u.upVersion(rc))
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/utils/mageutils/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,23 @@ func TestVersion(t *testing.T) {
{
releaseType: "patch",
repositoryRelease: newMockRelease("v7.8.1"),
repositoryTags: newMockTags([]string{"v7.8.2-rc.2", "vv7.8.2-rc.1", "vv7.8.2-beta.3", "vv7.8.2-beta.2", "vv7.8.2-beta.1", "v7.8.1", "v7.8.0", "v7.8.0-rc.1", "v7.8.0-beta.1"}),
repositoryTags: newMockTags([]string{"v7.8.2-rc.2", "vv7.8.2-rc.1", "v7.8.2-beta.3", "v7.8.2-beta.2", "v7.8.2-beta.1", "v7.8.1", "v7.8.0", "v7.8.0-rc.1", "v7.8.0-beta.1"}),
expectedNextReleaseVersion: "v7.8.2",
expectedNextReleaseVersionStripped: "7.8.2",
expectedNextReleaseBranchName: "release/v7.8",
expectedNextBetaVersion: "v7.8.2-beta.4",
expectedNextRCVersion: "v7.8.2-rc.3",
},
{
releaseType: "minor",
repositoryRelease: newMockRelease("v2.3.9"),
repositoryTags: newMockTags([]string{"v2.4.0-beta.1", "v2.3.9"}),
expectedNextReleaseVersion: "v2.4.0",
expectedNextReleaseVersionStripped: "2.4.0",
expectedNextReleaseBranchName: "release/v2.4",
expectedNextBetaVersion: "v2.4.0-beta.2",
expectedNextRCVersion: "v2.4.0-rc.1",
},
}

for index, testCase := range testCases {
Expand Down

0 comments on commit 73764ac

Please sign in to comment.