Skip to content

Commit

Permalink
Merge pull request #1888 from RamLavi/fix_vtag_logic
Browse files Browse the repository at this point in the history
tools/bumper: Fix latest vtag check
  • Loading branch information
RamLavi authored Sep 9, 2024
2 parents 44a83fa + 9e6abcf commit 1b6e3cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 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
48 changes: 28 additions & 20 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,22 +228,14 @@ 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 not bump since latest version is the same as current", isComponentBumpNeededParams{
currentReleaseVersion: "v3.6.2",
latestReleaseVersion: "v3.6.2",
updatePolicy: "tagged",
prTitle: dummyPRTitle,
isBumpExpected: false,
isValid: true,
}),
Entry("Should not bump since latest version is not bigger than current", isComponentBumpNeededParams{
currentReleaseVersion: "v3.6.2",
latestReleaseVersion: "v3.5.2",
Expand All @@ -268,14 +260,6 @@ var _ = Describe("Testing internal git CNAO Repo", func() {
isBumpExpected: true,
isValid: true,
}),
Entry("Should bump since latest is in vtag-format and different than current", isComponentBumpNeededParams{
currentReleaseVersion: "v0.11.0-3-g1be91ab",
latestReleaseVersion: "v0.11.0-4-g1ar46a5",
updatePolicy: "latest",
prTitle: dummyPRTitle,
isBumpExpected: true,
isValid: true,
}),
Entry("Should return error since current is not in correct semver version format", isComponentBumpNeededParams{
currentReleaseVersion: "ver1.2.3",
latestReleaseVersion: "v3.6.2",
Expand All @@ -292,6 +276,30 @@ var _ = Describe("Testing internal git CNAO Repo", func() {
isBumpExpected: false,
isValid: false,
}),
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",
updatePolicy: "tagged",
prTitle: dummyPRTitle,
isBumpExpected: false,
isValid: true,
}),
)

type resetInAllowedListParams struct {
Expand Down

0 comments on commit 1b6e3cd

Please sign in to comment.