From 3d77f69b803613bfabcf808876c0b64f1ecc6fce Mon Sep 17 00:00:00 2001 From: Ram Lavi Date: Mon, 9 Sep 2024 11:34:11 +0300 Subject: [PATCH] tools/bumper: Fix latest vtag check In the bumper logic, in case either currentReleaseVersion or latestReleaseVersion are in virtual-tag format (i.e. v0.44.1-1-g4cd33665) - then the bump should be initiated. However the logic implementing it is wrong. Fixing logic, adding unit tests. Signed-off-by: Ram Lavi --- tools/bumper/cnao_repo_commands.go | 4 ++-- tools/bumper/cnao_repo_commands_test.go | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/bumper/cnao_repo_commands.go b/tools/bumper/cnao_repo_commands.go index cc3129436..002e31b7f 100644 --- a/tools/bumper/cnao_repo_commands.go +++ b/tools/bumper/cnao_repo_commands.go @@ -136,7 +136,7 @@ func (cnaoRepoOps *gitCnaoRepo) isComponentBumpNeeded(currentReleaseVersion, lat // if one of the tags is in vtag format (e.g 0.39.0-32-g1fcbe815), and not equal, then always bump if isVtagFormat(currentReleaseVersion) || isVtagFormat(latestReleaseVersion) { - return currentReleaseVersion == latestReleaseVersion, nil + return currentReleaseVersion != latestReleaseVersion, nil } currentVersion, err := canonicalizeVersion(currentReleaseVersion) @@ -378,7 +378,7 @@ func canonicalizeVersion(version string) (*semver.Version, error) { // check vtag format (example: 0.39.0-32-g1fcbe815) func isVtagFormat(tagVersion string) bool { - var vtagSyntax = regexp.MustCompile(`^[0-9]\.[0-9]+\.*[0-9]*-[0-9]+-g[0-9,a-f]{7}`) + var vtagSyntax = regexp.MustCompile(`^v[0-9]\.[0-9]+\.*[0-9]*-[0-9]+-g[0-9,a-f]{8}`) return vtagSyntax.MatchString(tagVersion) } diff --git a/tools/bumper/cnao_repo_commands_test.go b/tools/bumper/cnao_repo_commands_test.go index 467558563..2c3af0b68 100644 --- a/tools/bumper/cnao_repo_commands_test.go +++ b/tools/bumper/cnao_repo_commands_test.go @@ -189,7 +189,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { expectedResult: false, }), Entry("When using vtag version format, Should recognize as vtag format", isVtagFormatParams{ - version: "0.39.0-32-g1fcbe815", + version: "v0.39.0-32-g1fcbe815", expectedResult: true, }), ) @@ -228,14 +228,30 @@ var _ = Describe("Testing internal git CNAO Repo", func() { isBumpExpected: false, isValid: true, }), - Entry("Should not bump since there is updatePolicy static (vtag-format)", isComponentBumpNeededParams{ - currentReleaseVersion: "v0.11.0-3-g1be91ab", - latestReleaseVersion: "v0.11.0-4-g1ar46a5", + Entry("Should bump when latestReleaseVersion is in vtag-format", isComponentBumpNeededParams{ + currentReleaseVersion: "v0.20.9", + latestReleaseVersion: "v0.20.9-1-g4cd31235", + updatePolicy: "latest", + prTitle: dummyPRTitle, + isBumpExpected: true, + isValid: true, + }), + Entry("Should bump when currentReleaseVersion is in vtag-format", isComponentBumpNeededParams{ + currentReleaseVersion: "v0.44.1-4-g4cd33665", + latestReleaseVersion: "v0.43.1", updatePolicy: "latest", prTitle: dummyPRTitle, isBumpExpected: true, isValid: true, }), + Entry("Should not bump when currentReleaseVersion is in vtag-format and equals latestReleaseVersion", isComponentBumpNeededParams{ + currentReleaseVersion: "v0.36.2-5-g4cd4566", + latestReleaseVersion: "v0.36.2-5-g4cd4566", + updatePolicy: "latest", + prTitle: dummyPRTitle, + isBumpExpected: false, + isValid: true, + }), Entry("Should not bump since latest version is the same as current", isComponentBumpNeededParams{ currentReleaseVersion: "v3.6.2", latestReleaseVersion: "v3.6.2",