Skip to content

Commit c9d1906

Browse files
committed
Add automated PyPI release workflow
1 parent 58d0df2 commit c9d1906

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

.github/workflows/release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Release to PyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- "agentx/version.py" # Prevent infinite loops
9+
workflow_dispatch: # Allow manual triggering
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: "3.9"
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install build twine wheel packaging
30+
31+
- name: Bump version (only on main branch pushes)
32+
id: bump
33+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
34+
run: |
35+
python -c "
36+
import re
37+
with open('agentx/version.py', 'r') as f:
38+
content = f.read()
39+
current_version = re.search(r'VERSION = \"([^\"]+)\"', content).group(1)
40+
from packaging import version
41+
v = version.parse(current_version)
42+
new_version = f'{v.major}.{v.minor}.{v.micro + 1}'
43+
new_content = content.replace(f'VERSION = \"{current_version}\"', f'VERSION = \"{new_version}\"')
44+
with open('agentx/version.py', 'w') as f:
45+
f.write(new_content)
46+
print(f'new_version={new_version}')
47+
print(f'Bumped version from {current_version} to {new_version}')
48+
"
49+
50+
- name: Commit version bump
51+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
52+
run: |
53+
git config --local user.email "[email protected]"
54+
git config --local user.name "GitHub Action"
55+
git add agentx/version.py
56+
git commit -m "Bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
57+
git push
58+
59+
- name: Wait for version bump commit
60+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
61+
run: |
62+
sleep 10 # Wait for the version bump commit to be processed
63+
64+
- name: Checkout latest code (to get version bump)
65+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
66+
uses: actions/checkout@v4
67+
with:
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Build package
71+
run: |
72+
python -m build
73+
74+
- name: Publish to PyPI
75+
env:
76+
TWINE_USERNAME: __token__
77+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
78+
run: |
79+
python -m twine upload dist/*
80+
81+
- name: Create GitHub Release
82+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
83+
uses: actions/create-release@v1
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
with:
87+
tag_name: v${{ steps.bump.outputs.new_version }}
88+
release_name: Release v${{ steps.bump.outputs.new_version }}
89+
body: |
90+
Automated release for version ${{ steps.bump.outputs.new_version }}
91+
92+
Changes in this release:
93+
- Automated version bump
94+
- PyPI package update
95+
draft: false
96+
prerelease: false

0 commit comments

Comments
 (0)