Update publish.yml #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to PyPI | |
on: | |
push: | |
tags: | |
- "v*" # Trigger on tags starting with 'v' (e.g., v1.0.0, v1.2.3) | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.12 | |
- name: Install Poetry and dependencies | |
run: | | |
pip install poetry | |
poetry install | |
- name: Extract version from Git tag | |
id: version | |
run: | | |
VERSION=$(echo ${GITHUB_REF} | sed 's/refs\/tags\/v//') # Strip 'v' prefix | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Bump version in pyproject.toml | |
run: | | |
poetry version $VERSION | |
poetry lock | |
- name: Push version bump to main | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "actions@github.com" | |
git add pyproject.toml poetry.lock | |
git commit -m "Bump version to $VERSION" | |
git push origin HEAD:main # Push from detached HEAD directly to main | |
- name: Build the package and publish to PyPI | |
env: | |
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} | |
run: poetry publish --build |