Skip to content

fix: CalVer not working correctly with zero-padded formats (fixes #320)#321

Open
oharo3109 wants to merge 1 commit intoSongmu:mainfrom
oharo3109:main
Open

fix: CalVer not working correctly with zero-padded formats (fixes #320)#321
oharo3109 wants to merge 1 commit intoSongmu:mainfrom
oharo3109:main

Conversation

@oharo3109
Copy link

Problem

When using CalVer formats with zero-padded components (e.g., YYYY.0M0D.MICRO), tagpr was
generating PRs with the same version as the current one instead of the expected new CalVer
date-based version.

Example: With format YYYY.0M0D.MICRO and current tag v2026.0227.10, running tagpr
on March 2nd should produce v2026.0302.0, but instead it produced v2026.0227.10.

Changes

  • semver.go: Naked() falls back to originalVersion when asCalendarVersion=true
    and cv==nil, preserving zero-padded components like 0M0D.
  • tagpr.go: After cherry-picks, CalVer mode re-applies bumpVersionFile instead of
    reading from the file to override nextVer.
  • calver_test.go: Added test cases covering zero-padded formats (YYYY.0M0D.MICRO,
    YYYY.0M.MICRO) including cross-date scenarios (the exact user-reported bug scenario).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves Calendar Versioning (CalVer) behavior so zero-padded versions (e.g., 2026.0302.0) are preserved when rendering/tagging versions, and attempts to ensure version files are bumped appropriately in CalVer mode.

Changes:

  • Update (*semv).Naked() to preserve the original CalVer string (including zero-padding) when a parsed calver.Calver instance isn’t available.
  • In tagpr.Run, add a CalVer-specific path intended to bump configured version files after reloading config (post cherry-pick).
  • Add tests covering cross-date CalVer bumping and zero-padding preservation for Naked()/Tag().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tagpr.go Adds CalVer-specific version-file bumping behavior after config reload in Run().
semver.go Adjusts Naked() to preserve original CalVer formatting (zero-padding) when cv is nil.
calver_test.go Adds regression tests for CalVer cross-date behavior and zero-padding preservation.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +751 to +756
if tp.cfg.CalendarVersioning() {
for _, vfile := range vfiles {
if err := bumpVersionFile(vfile, currVer, nextVer); err != nil {
return err
}
}
}
}
} else {
nVer, _ := retrieveVersionFromFile(vfiles[0], nextVer.vPrefix)
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.

2 participants