Skip to content

Merge pull request #48 from AgentX-ai/fix/double-billing-timeout #79

Merge pull request #48 from AgentX-ai/fix/double-billing-timeout

Merge pull request #48 from AgentX-ai/fix/double-billing-timeout #79

Workflow file for this run

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