feat: implement optimization #4 - version-tag consistency check

Add version-tag consistency validation to prevent mismatched releases:

- Integrate validate_changelog_version() into create_tag() workflow
  to ensure CHANGELOG has version section before creating git tag
- Add check_version_consistency() method to ReleaseManager for
  manual consistency verification
- Add 'release check-consistency --version X.Y.Z' CLI command to
  verify CHANGELOG and git tag alignment
- Prevent tag creation if CHANGELOG missing version section
- Provide helpful tips when validation fails

This ensures git tags and CHANGELOG versions stay synchronized,
preventing incomplete or inconsistent releases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-06 21:14:33 +01:00
parent 599de22f59
commit 0b5098370a
2 changed files with 46 additions and 1 deletions

View File

@@ -261,5 +261,30 @@ def version_info(ctx, suggest: bool):
print(f" {key.replace('_', ' ').title()}: {value}")
@main.command('check-consistency')
@click.option('--version', required=True, help='Version to check (e.g., 0.10.0)')
@click.pass_context
def check_consistency(ctx, version: str):
"""Check consistency between CHANGELOG version and git tags."""
manager = ReleaseManager(
project_root=ctx.obj['project_root'],
dry_run=ctx.obj['dry_run'],
force=ctx.obj['force']
)
is_consistent, issues = manager.check_version_consistency(version)
if is_consistent:
print(f"✅ Version {version} is consistent:")
print(f" - CHANGELOG has section for {version}")
print(f" - Git tag v{version} exists")
print(f" - [Unreleased] section present")
else:
print(f"❌ Version {version} has consistency issues:")
for issue in issues:
print(f" - {issue}")
sys.exit(1)
if __name__ == '__main__':
main()

View File

@@ -94,6 +94,15 @@ class ReleaseManager:
print(f" - {issue}")
return False
# Check version-tag consistency (ensure CHANGELOG has version section)
changelog_valid, changelog_issues = self.validator.validate_changelog_version(version)
if not changelog_valid and not self.force:
print(f"❌ Cannot create tag for version {version}:")
for issue in changelog_issues:
print(f" - {issue}")
print("\n💡 Tip: Add a section for version {version} to CHANGELOG.md before tagging")
return False
return self.git_manager.create_tag(version, message, push=push)
def build_packages(self) -> bool:
@@ -213,4 +222,15 @@ class ReleaseManager:
Returns:
List of commit messages since last tag
"""
return self.git_manager.get_commits_since_tag()
return self.git_manager.get_commits_since_tag()
def check_version_consistency(self, version: str) -> Tuple[bool, List[str]]:
"""Check consistency between CHANGELOG version and git tags.
Args:
version: Version to check (e.g., "0.10.0")
Returns:
Tuple of (is_consistent, list_of_issues)
"""
return self.validator.check_version_tag_consistency(version)