Skip to content

fix: validate bumped version against tag pattern #1137

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 1 commit into
base: main
Choose a base branch
from

Conversation

peiqing6888
Copy link

When using --bumped-version with a tag pattern configured, git-cliff now validates the generated version against the pattern and returns an error if it doesn't match.

Fixes #1095

Description

Added validation for the bumped version against the configured tag pattern. When using --bumped-version with a tag pattern configured, git-cliff will now check if the generated version matches the pattern. If it doesn't match, it will return an error with a descriptive message instead of silently creating a non-compliant version.

Motivation and Context

Previously, when using --bumped-version with a tag pattern configured, git-cliff would generate a version (e.g. "0.1.0") without validating it against the configured tag pattern. This could lead to confusion when the generated version doesn't match the project's versioning scheme.

This change ensures that the generated version complies with the project's versioning pattern, providing better consistency and immediate feedback when there's a mismatch.

How Has This Been Tested?

Added a new test case test_bump_version_with_tag_pattern that verifies:

  • Version generation fails with appropriate error when the pattern doesn't match (e.g. pattern: "foo-[0-9]+.[0-9]+.[0-9]+")
  • Version generation succeeds when the pattern matches (e.g. pattern: "v[0-9]+.[0-9]+.[0-9]+")

The test covers both success and failure scenarios, ensuring proper error handling and pattern validation.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

When using --bumped-version with a tag pattern configured, git-cliff now validates the generated version against the pattern and returns an error if it doesn't match.

Fixes orhun#1095
@peiqing6888 peiqing6888 requested a review from orhun as a code owner April 28, 2025 05:07
Copy link

welcome bot commented Apr 28, 2025

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 40.14%. Comparing base (451a694) to head (aa3019e).

Files with missing lines Patch % Lines
git-cliff-core/src/changelog.rs 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1137      +/-   ##
==========================================
- Coverage   40.16%   40.14%   -0.02%     
==========================================
  Files          21       21              
  Lines        1900     1906       +6     
==========================================
+ Hits          763      765       +2     
- Misses       1137     1141       +4     
Flag Coverage Δ
unit-tests 40.14% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

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

Hello, thanks for the PR!

This looks good, however I'm not sure how it relates to #1095 - did you maybe link to an incorrect issue there?

Comment on lines +584 to +588
return Err(Error::ChangelogError(format!(
"Bumped version '{}' does not match configured tag pattern '{}'",
next_version,
tag_pattern
)));
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return Err(Error::ChangelogError(format!(
"Bumped version '{}' does not match configured tag pattern '{}'",
next_version,
tag_pattern
)));
return Err(Error::ChangelogError(format!(
"Bumped version '{next_version}' does not match \
configured tag pattern '{tag_version}'",
)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add offline/local version of --bumped-version
3 participants