-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrelease.py
More file actions
175 lines (145 loc) · 5.65 KB
/
release.py
File metadata and controls
175 lines (145 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
"""Script to help create a new release"""
import json
import re
import subprocess
import sys
from pathlib import Path
def get_current_version():
"""Get current version from setup.py"""
setup_py = Path("setup.py")
if setup_py.exists():
content = setup_py.read_text()
match = re.search(r'version="([^"]+)"', content)
if match:
return match.group(1)
return None
def update_version_in_file(file_path, old_version, new_version):
"""Update version in a specific file"""
file_path = Path(file_path)
if not file_path.exists():
print(f"⚠️ File {file_path} not found, skipping...")
return False
content = file_path.read_text()
if file_path.suffix == '.json':
# Handle JSON files
try:
data = json.loads(content)
if 'version' in data:
data['version'] = new_version
file_path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + '\n')
print(f"✅ Updated {file_path}")
return True
except json.JSONDecodeError:
print(f"❌ Failed to parse JSON in {file_path}")
return False
else:
# Handle Python files
patterns = [
(rf'version="{re.escape(old_version)}"', f'version="{new_version}"'),
(rf"version='{re.escape(old_version)}'", f"version='{new_version}'"),
]
updated = False
for pattern, replacement in patterns:
if re.search(pattern, content):
content = re.sub(pattern, replacement, content)
updated = True
if updated:
file_path.write_text(content)
print(f"✅ Updated {file_path}")
return True
else:
print(f"⚠️ No version found in {file_path}")
return False
def run_command(cmd):
"""Run a shell command"""
print(f"Running: {cmd}")
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
print(f"❌ Command failed: {result.stderr}")
return False
return True
def validate_version(version):
"""Validate version format"""
pattern = r'^\d+\.\d+\.\d+$'
return re.match(pattern, version) is not None
def main():
"""Main function"""
print("🚀 Release Helper Script")
print("=" * 50)
# Get current version
current_version = get_current_version()
if current_version:
print(f"📋 Current version: {current_version}")
else:
print("❌ Could not determine current version")
return 1
# Get new version from user
while True:
new_version = input(f"\n📝 Enter new version (current: {current_version}): ").strip()
if not new_version:
print("❌ Version cannot be empty")
continue
if not validate_version(new_version):
print("❌ Invalid version format. Use MAJOR.MINOR.PATCH (e.g., 1.2.3)")
continue
if new_version == current_version:
print("❌ New version must be different from current version")
continue
break
print(f"\n🔄 Updating version from {current_version} to {new_version}...")
# Files to update
files_to_update = [
"setup.py",
"pyproject.toml",
"mcp_server/server_config.json"
]
# Update version in files
success_count = 0
for file_path in files_to_update:
if update_version_in_file(file_path, current_version, new_version):
success_count += 1
if success_count == 0:
print("❌ No files were updated")
return 1
print(f"\n✅ Updated {success_count}/{len(files_to_update)} files")
# Ask if user wants to commit and create release
response = input("\n🔧 Do you want to commit changes and create a git tag? (y/N): ").strip().lower()
if response in ['y', 'yes']:
# Commit changes
if not run_command("git add ."):
return 1
commit_msg = f"Bump version to {new_version}"
if not run_command(f'git commit -m "{commit_msg}"'):
return 1
# Create tag
tag_name = f"v{new_version}"
if not run_command(f'git tag {tag_name}'):
return 1
print(f"\n✅ Created commit and tag {tag_name}")
# Ask about pushing
push_response = input("\n🚀 Do you want to push changes and tag to remote? (y/N): ").strip().lower()
if push_response in ['y', 'yes']:
if run_command("git push origin main") and run_command(f"git push origin {tag_name}"):
print(f"\n🎉 Successfully pushed version {new_version}!")
print("\n📋 Next steps:")
print("1. Go to GitHub repository")
print(f"2. Create a new release using tag {tag_name}")
print("3. GitHub Actions will automatically publish to PyPI")
else:
return 1
else:
print(f"\n📋 Changes committed locally with tag {tag_name}")
print("Run the following commands when ready to push:")
print(f" git push origin main")
print(f" git push origin {tag_name}")
else:
print("\n📋 Version updated in files. Remember to commit changes:")
print(f" git add .")
print(f' git commit -m "Bump version to {new_version}"')
print(f" git tag v{new_version}")
print(f" git push origin main")
print(f" git push origin v{new_version}")
return 0
if __name__ == "__main__":
sys.exit(main())