-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.py
More file actions
executable file
·161 lines (130 loc) · 4.68 KB
/
publish.py
File metadata and controls
executable file
·161 lines (130 loc) · 4.68 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
#!/usr/bin/env python3
"""
Script to help publish the gemini-gen-mcp package to PyPI.
Usage:
python publish.py --bump # Bump the package version
python publish.py --release # Create a GitHub Release
python publish.py --build # Just build the package
"""
import argparse
import os
import subprocess
import sys
def run_command(cmd, check=True):
"""Run a shell command and return the result."""
print(f"Running: {cmd}")
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
if check and result.returncode != 0:
print(f"Error running command: {cmd}")
print(f"stdout: {result.stdout}")
print(f"stderr: {result.stderr}")
sys.exit(1)
return result
def clean_build():
"""Clean previous build artifacts."""
print("Cleaning previous build artifacts...")
run_command("rm -rf build/ dist/ *.egg-info/", check=False)
def build_package():
"""Build the package."""
print("Building package...")
run_command("python -m build")
def check_dependencies():
"""Check if required tools are installed."""
try:
import build
except ImportError as e:
print(f"Missing dependency: {e}")
print("Please install required dependencies:")
print("pip install build twine")
sys.exit(1)
def get_current_version():
"""Get the current version from pyproject.toml."""
import re
version_file = "pyproject.toml"
with open(version_file, encoding="utf-8") as f:
content = f.read()
version = re.search(r"version = \"(\d+\.\d+\.\d+)\"", content).group(1)
return version
def bump_version():
"""
Bump the package version.
This function should implement version bumping logic by
- extracting version from pyproject.toml
- incrementing patch version
- Use string search/replace to replace old version with new version in:
- pyproject.toml
"""
print("Bumping package version...")
import re
version_file = "pyproject.toml"
with open(version_file, encoding="utf-8") as f:
content = f.read()
version = re.search(r"version = \"(\d+\.\d+\.\d+)\"", content).group(1)
print(f"Current version: {version}")
major, minor, patch = map(int, version.split("."))
patch += 1
new_version = f"{major}.{minor}.{patch}"
print(f"New version: {new_version}")
content = content.replace(version, new_version)
with open(version_file, "w", encoding="utf-8") as f:
f.write(content)
# Update other files
files_to_update = [] # "setup.py"
for file in files_to_update:
with open(file, encoding="utf-8") as f:
content = f.read()
content = content.replace(version, new_version)
with open(file, "w", encoding="utf-8") as f:
f.write(content)
print("Version bumped successfully.")
# Create git commit and tag
run_command(f'git commit -am "Bump version to {new_version}"')
run_command(f"git tag v{new_version}")
run_command("git push --tags")
run_command("git push")
def create_release():
"""
Create a GitHub Release using the latest version.
This should be run after bump_version().
"""
print("Creating GitHub Release...")
version = get_current_version()
tag = f"v{version}"
print(f"Creating release for version {version} (tag: {tag})")
# Create GitHub release using gh CLI
# The release notes will be auto-generated from commits
release_cmd = (
f'gh release create {tag} --title "Release {version}" --generate-notes'
)
run_command(release_cmd)
print(f"GitHub Release {version} created successfully!")
print(f"View at: https://github.com/ServiceStack/gemini-gen-mcp/releases/tag/{tag}")
def main():
parser = argparse.ArgumentParser(description="Publish gemini-gen-mcp package to PyPI")
parser.add_argument("--build", action="store_true", help="Build the package")
parser.add_argument("--bump", action="store_true", help="Bump the package version")
parser.add_argument(
"--release",
action="store_true",
help="Create a GitHub Release (run after bump)",
)
args = parser.parse_args()
if not any([args.bump, args.release, args.build]):
parser.print_help()
sys.exit(1)
# Release doesn't need build steps
if args.release:
create_release()
return
if args.bump:
bump_version()
return
if args.build:
clean_build()
build_package()
print("\nPackage built successfully!")
print("Files created in dist/:")
for file in os.listdir("dist"):
print(f" {file}")
if __name__ == "__main__":
main()