✨ Added automatic version management: - CHANGELOG.md with complete v0.1.0 history - Version control helper script for automated commits - GitHub setup script for easy repository connection - Semantic versioning support (Major.Minor.Patch) 🔄 Future workflow automation: - Automatic changelog updates - Descriptive commit messages - Version tagging for releases - Automatic GitHub pushes 🔧 Generated with Claude Code 🤖 Co-Authored-By: Claude <noreply@anthropic.com>
114 lines
No EOL
3.1 KiB
Python
114 lines
No EOL
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Version Control Helper for PetBot
|
|
Automatically manages commits, tags, and changelog updates
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
def run_command(cmd):
|
|
"""Run a shell command and return output"""
|
|
try:
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
|
return result.returncode == 0, result.stdout.strip(), result.stderr.strip()
|
|
except Exception as e:
|
|
return False, "", str(e)
|
|
|
|
def get_current_version():
|
|
"""Get the latest version tag"""
|
|
success, output, _ = run_command("git describe --tags --abbrev=0")
|
|
if success and output:
|
|
return output
|
|
return "v0.1.0" # Default if no tags
|
|
|
|
def increment_version(version, increment_type="minor"):
|
|
"""Increment version number"""
|
|
if version.startswith('v'):
|
|
version = version[1:]
|
|
|
|
parts = version.split('.')
|
|
major, minor, patch = int(parts[0]), int(parts[1]), int(parts[2])
|
|
|
|
if increment_type == "major":
|
|
major += 1
|
|
minor = 0
|
|
patch = 0
|
|
elif increment_type == "minor":
|
|
minor += 1
|
|
patch = 0
|
|
else: # patch
|
|
patch += 1
|
|
|
|
return f"v{major}.{minor}.{patch}"
|
|
|
|
def update_changelog(version, changes):
|
|
"""Update CHANGELOG.md with new version"""
|
|
date = datetime.now().strftime("%Y-%m-%d")
|
|
|
|
new_entry = f"""
|
|
## [{version}] - {date}
|
|
|
|
{changes}
|
|
|
|
---
|
|
|
|
"""
|
|
|
|
# Read current changelog
|
|
try:
|
|
with open("CHANGELOG.md", "r") as f:
|
|
content = f.read()
|
|
except FileNotFoundError:
|
|
content = "# Changelog\n\n"
|
|
|
|
# Insert new entry after the header
|
|
lines = content.split('\n')
|
|
header_end = 0
|
|
for i, line in enumerate(lines):
|
|
if line.startswith('## [v') or line.startswith('## Version History'):
|
|
header_end = i
|
|
break
|
|
|
|
if header_end == 0:
|
|
# Add after initial header
|
|
for i, line in enumerate(lines):
|
|
if line.strip() == "" and i > 5: # Find first empty line after headers
|
|
header_end = i
|
|
break
|
|
|
|
# Insert new content
|
|
lines.insert(header_end, new_entry.strip())
|
|
|
|
# Write back
|
|
with open("CHANGELOG.md", "w") as f:
|
|
f.write('\n'.join(lines))
|
|
|
|
def commit_and_tag(message, version, push=True):
|
|
"""Create commit and tag"""
|
|
# Add all changes
|
|
run_command("git add .")
|
|
|
|
# Create commit
|
|
commit_msg = f"{message}\n\n🔧 Generated with Claude Code\n🤖 Co-Authored-By: Claude <noreply@anthropic.com>"
|
|
success, _, error = run_command(f'git commit -m "{commit_msg}"')
|
|
|
|
if not success and "nothing to commit" not in error:
|
|
print(f"Commit failed: {error}")
|
|
return False
|
|
|
|
# Create tag
|
|
tag_msg = f"Release {version}: {message}"
|
|
run_command(f'git tag -a {version} -m "{tag_msg}"')
|
|
|
|
# Push if requested
|
|
if push:
|
|
run_command("git push")
|
|
run_command("git push --tags")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
print("PetBot Version Control Helper")
|
|
print("This script is used internally by Claude Code") |