Skip to content

Commit 7320843

Browse files
committed
Use new format for pypi workflow tags
1 parent ac6ec96 commit 7320843

File tree

2 files changed

+186
-4
lines changed

2 files changed

+186
-4
lines changed

.github/workflows/agent-memory-client.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
publish-testpypi:
5151
name: Publish to TestPyPI
5252
needs: test
53-
if: startsWith(github.ref, 'refs/tags/client/') && contains(github.ref, '-')
53+
if: startsWith(github.ref, 'refs/tags/client/') && contains(github.ref, '-test')
5454
runs-on: ubuntu-latest
5555
environment: testpypi
5656
permissions:
@@ -82,7 +82,7 @@ jobs:
8282
publish-pypi:
8383
name: Publish to PyPI
8484
needs: test
85-
if: startsWith(github.ref, 'refs/tags/client/') && !contains(github.ref, '-')
85+
if: startsWith(github.ref, 'refs/tags/client/') && !contains(github.ref, '-test')
8686
runs-on: ubuntu-latest
8787
environment: pypi
8888
permissions:
@@ -110,8 +110,17 @@ jobs:
110110
with:
111111
packages-dir: agent-memory-client/dist/
112112

113-
# Alternative: API Token Authentication (if trusted publishing doesn't work)
114-
# Uncomment the sections below and add these secrets to your repository:
113+
# Tag Format Guide:
114+
# - For TestPyPI (testing): client/v1.0.0-test
115+
# - For PyPI (production): client/v1.0.0
116+
#
117+
# Use the script: python scripts/tag_and_push_client.py --test (for TestPyPI)
118+
# python scripts/tag_and_push_client.py (for PyPI)
119+
#
120+
# Alternative: This project uses trusted publishing, but you can use API Token
121+
# Authentication (if trusted publishing doesn't work).
122+
#
123+
# To do so, uncomment the sections below and add these secrets to your repository:
115124
# - TEST_PYPI_API_TOKEN (for TestPyPI)
116125
# - PYPI_API_TOKEN (for PyPI)
117126
#

scripts/tag_and_push_client.py

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to tag and push agent-memory-client releases.
4+
5+
This script:
6+
1. Reads the current version from agent-memory-client/__init__.py
7+
2. Creates a git tag in the format: client/v{version}
8+
3. Pushes the tag to origin
9+
10+
Usage:
11+
python scripts/tag_and_push_client.py [--dry-run]
12+
"""
13+
14+
import argparse
15+
import re
16+
import subprocess
17+
import sys
18+
from pathlib import Path
19+
20+
21+
def get_client_version() -> str:
22+
"""Read the version from agent-memory-client/__init__.py"""
23+
init_file = Path("agent-memory-client/agent_memory_client/__init__.py")
24+
25+
if not init_file.exists():
26+
raise FileNotFoundError(f"Could not find {init_file}")
27+
28+
content = init_file.read_text()
29+
30+
# Look for __version__ = "x.y.z"
31+
version_match = re.search(r'__version__\s*=\s*["\']([^"\']+)["\']', content)
32+
33+
if not version_match:
34+
raise ValueError(f"Could not find __version__ in {init_file}")
35+
36+
return version_match.group(1)
37+
38+
39+
def run_command(cmd: list[str], dry_run: bool = False) -> subprocess.CompletedProcess:
40+
"""Run a command, optionally in dry-run mode."""
41+
print(f"Running: {' '.join(cmd)}")
42+
43+
if dry_run:
44+
print(" (dry-run mode - command not executed)")
45+
return subprocess.CompletedProcess(cmd, 0, "", "")
46+
47+
try:
48+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
49+
if result.stdout:
50+
print(f" Output: {result.stdout.strip()}")
51+
return result
52+
except subprocess.CalledProcessError as e:
53+
print(f" Error: {e.stderr.strip()}")
54+
raise
55+
56+
57+
def check_git_status():
58+
"""Check if git working directory is clean."""
59+
try:
60+
result = subprocess.run(
61+
["git", "status", "--porcelain"], capture_output=True, text=True, check=True
62+
)
63+
if result.stdout.strip():
64+
print("Warning: Git working directory is not clean:")
65+
print(result.stdout)
66+
response = input("Continue anyway? (y/N): ")
67+
if response.lower() != "y":
68+
sys.exit(1)
69+
except subprocess.CalledProcessError:
70+
print("Error: Could not check git status")
71+
sys.exit(1)
72+
73+
74+
def tag_exists(tag_name: str) -> bool:
75+
"""Check if a tag already exists."""
76+
try:
77+
subprocess.run(
78+
["git", "rev-parse", f"refs/tags/{tag_name}"],
79+
capture_output=True,
80+
check=True,
81+
)
82+
return True
83+
except subprocess.CalledProcessError:
84+
return False
85+
86+
87+
def main():
88+
parser = argparse.ArgumentParser(
89+
description="Tag and push agent-memory-client release"
90+
)
91+
parser.add_argument(
92+
"--dry-run",
93+
action="store_true",
94+
help="Show what would be done without actually doing it",
95+
)
96+
parser.add_argument(
97+
"--force",
98+
action="store_true",
99+
help="Force tag creation even if tag already exists",
100+
)
101+
parser.add_argument(
102+
"--test",
103+
action="store_true",
104+
help="Add '-test' suffix to tag for TestPyPI deployment",
105+
)
106+
107+
args = parser.parse_args()
108+
109+
# Change to project root directory
110+
script_dir = Path(__file__).parent
111+
project_root = script_dir.parent
112+
113+
try:
114+
original_cwd = Path.cwd()
115+
if project_root.resolve() != original_cwd.resolve():
116+
print(f"Changing to project root: {project_root}")
117+
import os
118+
119+
os.chdir(project_root)
120+
except Exception as e:
121+
print(f"Warning: Could not change to project root: {e}")
122+
123+
try:
124+
# Get the current version
125+
version = get_client_version()
126+
tag_suffix = "-test" if args.test else ""
127+
tag_name = f"client/v{version}{tag_suffix}"
128+
129+
print(f"Current client version: {version}")
130+
print(f"Tag to create: {tag_name}")
131+
print(f"Deployment target: {'TestPyPI' if args.test else 'PyPI (Production)'}")
132+
133+
if not args.dry_run:
134+
# Check git status
135+
check_git_status()
136+
137+
# Check if tag already exists
138+
if tag_exists(tag_name):
139+
if args.force:
140+
print(f"Tag {tag_name} already exists, but --force specified")
141+
run_command(["git", "tag", "-d", tag_name], args.dry_run)
142+
else:
143+
print(
144+
f"Error: Tag {tag_name} already exists. Use --force to overwrite."
145+
)
146+
sys.exit(1)
147+
148+
# Create the tag
149+
run_command(["git", "tag", tag_name], args.dry_run)
150+
151+
# Push the tag
152+
push_cmd = ["git", "push", "origin", tag_name]
153+
if args.force:
154+
push_cmd.insert(2, "--force")
155+
156+
run_command(push_cmd, args.dry_run)
157+
158+
print(f"\n✅ Successfully tagged and pushed {tag_name}")
159+
160+
if not args.dry_run:
161+
print("\nThis should trigger the GitHub Actions workflow for:")
162+
if args.test:
163+
print(" - TestPyPI publication (testing)")
164+
else:
165+
print(" - PyPI publication (production)")
166+
167+
except Exception as e:
168+
print(f"Error: {e}")
169+
sys.exit(1)
170+
171+
172+
if __name__ == "__main__":
173+
main()

0 commit comments

Comments
 (0)