Skip to content

🌱 Add validation for PREVIOUS_RELEASE_TAG in release-notes-tool #12380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tsuzu
Copy link
Contributor

@tsuzu tsuzu commented Jun 19, 2025

What this PR does / why we need it:
Add a validation logic for make release-notes

✅ Now Accepts:

  • tags/v1.0.0-alpha.1 (alpha pre-release)
  • tags/v1.0.0-beta.1 (beta pre-release)
  • tags/v1.0.0-rc.1 (release candidate)

❌ Now Rejects:

  • v1.0.0-alpha.1 (missing tags/ prefix)
  • tags/v1.0.0 (no pre-release identifier)
  • tags/v1.0.0-dev.1 (unsupported pre-release type)
  • invalid-version (malformed version)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #12278

/area release

@k8s-ci-robot k8s-ci-robot added area/release Issues or PRs related to releasing cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 19, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cprivitere for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 19, 2025
@tsuzu
Copy link
Contributor Author

tsuzu commented Jun 19, 2025

@chandankumar4
Is this a change you are expecting?
I appreciate it if you review this PR. Thanks!

@tsuzu tsuzu force-pushed the fix/12278-validate-previous-release-tag branch from 80ce3de to a36f7cf Compare June 19, 2025 15:05
@tsuzu
Copy link
Contributor Author

tsuzu commented Jun 19, 2025

/retest

Copy link
Member

@sivchari sivchari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments. PTAL.

preReleaseRC = "rc"
preReleaseBeta = "beta"
preReleaseAlpha = "alpha"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
preReleaseRC = "rc"
preReleaseBeta = "beta"
preReleaseAlpha = "alpha"
preReleaseAlpha = "alpha"
preReleaseBeta = "beta"
preReleaseRC = "rc"


versionStr := parts[1]

// Parse the version to check if it contains rc, beta, or alpha
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Parse the version to check if it contains rc, beta, or alpha
// Parse the version to check if it contains alpha, beta, or rc

func validatePreviousReleaseVersion(previousReleaseVersion string) error {
// Extract version string from ref format (e.g., "tags/v1.0.0-rc.1" -> "v1.0.0-rc.1")
if !strings.Contains(previousReleaseVersion, "/") {
return errors.New("--previous-release-version must be in ref format (e.g., tags/v1.0.0-rc.1)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.New("--previous-release-version must be in ref format (e.g., tags/v1.0.0-rc.1)")
return errors.New("--previous-release-version must be in ref format (e.g. tags/v1.0.0-rc.1)")

Same with other error messages.


// Check if the version has pre-release identifiers
if len(version.Pre) == 0 {
return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", preReleaseRC, preReleaseBeta, preReleaseAlpha)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", preReleaseRC, preReleaseBeta, preReleaseAlpha)
return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", , preReleaseAlpha, preReleaseBeta, preReleaseRC)

// Check if the first pre-release identifier is 'rc', 'beta', or 'alpha'
preReleaseType := version.Pre[0].VersionStr
if preReleaseType != preReleaseRC && preReleaseType != preReleaseBeta && preReleaseType != preReleaseAlpha {
return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", preReleaseRC, preReleaseBeta, preReleaseAlpha)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", preReleaseRC, preReleaseBeta, preReleaseAlpha)
return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", preReleaseAlpha, preReleaseBeta, preReleaseRC)

return errors.Errorf("--previous-release-version must contain '%s', '%s', or '%s' pre-release identifier", preReleaseRC, preReleaseBeta, preReleaseAlpha)
}

// Check if the first pre-release identifier is 'rc', 'beta', or 'alpha'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check if the first pre-release identifier is 'rc', 'beta', or 'alpha'
// Check if the first pre-release identifier is 'alpha', 'beta', or 'rc'

Comment on lines 302 to 305
if err == nil {
t.Errorf("expected error '%s', got no error", tt.errorMessage)
} else if !strings.Contains(err.Error(), tt.errorMessage) {
t.Errorf("expected error to contain '%s', got '%v'", tt.errorMessage, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err == nil {
t.Errorf("expected error '%s', got no error", tt.errorMessage)
} else if !strings.Contains(err.Error(), tt.errorMessage) {
t.Errorf("expected error to contain '%s', got '%v'", tt.errorMessage, err)
if err == nil || !strings.Contains(err.Error(), tt.errorMessage) {
t.Errorf("expected error '%s', got %v", tt.errorMessage, err)
}

@tsuzu tsuzu force-pushed the fix/12278-validate-previous-release-tag branch from a36f7cf to d74021f Compare June 22, 2025 18:36
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 22, 2025
Validate that PREVIOUS_RELEASE_TAG uses proper ref format and contains
alpha, beta, or rc pre-release identifier.

Co-authored-by: sivchari <[email protected]>
@tsuzu tsuzu force-pushed the fix/12278-validate-previous-release-tag branch from d74021f to 51a6c70 Compare June 22, 2025 18:41
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 22, 2025
@sivchari
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 23, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 73279cb64ee7f62263e788e108c8a03acd45214b

Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/assign @chandankumar4

},
wantErr: true,
errorMessage: "invalid --previous-release-version, is not a valid semver",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to add test case for beta version as well

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/release Issues or PRs related to releasing cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add check to validate the value of PREVIOUS_RELEASE_TAG in release-notes-tools
5 participants