#!/usr/bin/env python3 """ Update bootc.spec file with new version and changelog entry """ import re import sys from datetime import datetime from pathlib import Path def update_spec(spec_path: str, version: str, jira_ticket: str, author: str = None) -> None: """ Update spec file with new version and changelog entry. Args: spec_path: Path to the spec file version: New version number (e.g., "1.5.2") jira_ticket: JIRA ticket number (e.g., "RHEL-104567") author: Changelog author (default: bootc-release-bot) """ if author is None: author = "bootc-release-bot " spec_file = Path(spec_path) if not spec_file.exists(): print(f"Error: Spec file not found: {spec_path}", file=sys.stderr) sys.exit(1) content = spec_file.read_text() # Update Version field (preserve spacing) content = re.sub( r'^(Version:\s+).*', rf'\g<1>{version}', content, flags=re.MULTILINE ) # Update Release field to 1%{?dist} content = re.sub( r'^(Release:\s+).*', r'\g<1>1%{?dist}', content, flags=re.MULTILINE ) # Generate changelog entry date_str = datetime.now().strftime('%a %b %d %Y') changelog_entry = f"""* {date_str} {author} - {version}-1 - Update to {version} - Resolves: #{jira_ticket} """ # Insert after %changelog line content = re.sub( r'(%changelog\n)', rf'\1{changelog_entry}', content ) # Write back spec_file.write_text(content) print(f"Updated {spec_path}:") print(f" Version: {version}") print(f" Release: 1%{{?dist}}") print(f" JIRA: {jira_ticket}") def main(): if len(sys.argv) < 4: print(f"Usage: {sys.argv[0]} [author]", file=sys.stderr) print(f"Example: {sys.argv[0]} bootc.spec 1.5.2 RHEL-104567", file=sys.stderr) sys.exit(1) spec_path = sys.argv[1] version = sys.argv[2] jira_ticket = sys.argv[3] author = sys.argv[4] if len(sys.argv) > 4 else None update_spec(spec_path, version, jira_ticket, author) if __name__ == '__main__': main()