Repository navigation
149 lines (133 loc) · 5.28 KB
/
Copy pathrelease.yml
File metadata and controls
149 lines (133 loc) · 5.28 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
name: Release to PyPI
on:
push:
branches:
- main
paths-ignore:
- "agentx/version.py" # Prevent infinite loops
workflow_dispatch: # Allow manual triggering
permissions:
contents: write
packages: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine wheel packaging
- name: Bump version (only on main branch pushes)
id: bump
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
python -c "
import re
with open('agentx/version.py', 'r') as f:
content = f.read()
current_version = re.search(r'VERSION = \"([^\"]+)\"', content).group(1)
from packaging import version
v = version.parse(current_version)
new_version = f'{v.major}.{v.minor}.{v.micro + 1}'
new_content = content.replace(f'VERSION = \"{current_version}\"', f'VERSION = \"{new_version}\"')
with open('agentx/version.py', 'w') as f:
f.write(new_content)
print(f'Bumped version from {current_version} to {new_version}')
"
- name: Refresh engine pin (ENGINE_VERSION)
id: engine
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Every SDK release re-pins agentx.version.ENGINE_VERSION to AgentX-trace-eval's
# newest release, so the tested-pair contract (agentx/cli.py installs and converges to
# this tag) never goes stale - both repos release per merge, a manual pin would lag
# within days. Fail-open on a transient API error: publishing with the previous pin
# beats not publishing.
set -euo pipefail
tag="$(gh release view --repo AgentX-ai/AgentX-trace-eval --json tagName -q .tagName || true)"
if ! echo "$tag" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Could not resolve a v<x>.<y>.<z> engine release (got: '$tag'); keeping the existing pin."
grep ENGINE_VERSION agentx/version.py
exit 0
fi
python - "$tag" <<'EOF'
import re, sys
tag = sys.argv[1]
with open('agentx/version.py') as f:
content = f.read()
new_content = re.sub(r'ENGINE_VERSION = "[^"]+"', f'ENGINE_VERSION = "{tag}"', content)
with open('agentx/version.py', 'w') as f:
f.write(new_content)
print(f'Pinned ENGINE_VERSION = {tag}')
EOF
- name: Get new version
id: version
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
python -c "
import re
with open('agentx/version.py', 'r') as f:
content = f.read()
new_version = re.search(r'VERSION = \"([^\"]+)\"', content).group(1)
print(f'new_version={new_version}')
" >> $GITHUB_OUTPUT
- name: Commit version bump
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add agentx/version.py
git commit -m "Bump version to ${{ steps.version.outputs.new_version }} (engine pin refreshed) [skip ci]"
git push
- name: Wait for version bump commit and fetch latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
sleep 15 # Wait for the version bump commit to be processed
git fetch origin main
git checkout main
git pull origin main
- name: Verify version for PyPI
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
python -c "
import re
with open('agentx/version.py', 'r') as f:
content = f.read()
version = re.search(r'VERSION = \"([^\"]+)\"', content).group(1)
print(f'Version to be published to PyPI: {version}')
"
- name: Build package
run: |
python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m twine upload dist/*
- name: Create GitHub Release
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.new_version }}
release_name: Release v${{ steps.version.outputs.new_version }}
body: |
Automated release for version ${{ steps.version.outputs.new_version }}
Changes in this release:
- Automated version bump
- PyPI package update
draft: false
prerelease: false