Skip to content

Commit

Permalink
tools/bumper: Fix latest vtag check
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
RamLavi committed Sep 9, 2024
1 parent 37d8690 commit 3d77f69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/bumper/cnao_repo_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
24 changes: 20 additions & 4 deletions tools/bumper/cnao_repo_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3d77f69

Please sign in to comment.