auto run on tags #5
Workflow file for this run
This file contains hidden or 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: Test and Publish to PyPI | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # triggers only when pushing tags starting with 'v' | |
| jobs: | |
| test: | |
| 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: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| poetry install | |
| - name: Run tests | |
| run: poetry run pytest | |
| publish: | |
| needs: test | |
| 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: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| poetry install | |
| - name: Extract version from pyproject.toml | |
| id: get_version | |
| run: | | |
| echo "VERSION=$(poetry version --short)" >> $GITHUB_ENV | |
| - name: Show extracted version | |
| run: echo "Publishing version $VERSION" | |
| - name: Clean old builds | |
| run: rm -rf dist/ | |
| - name: Build the package | |
| run: poetry build | |
| - name: Publish to PyPI | |
| env: | |
| POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} | |
| run: | | |
| poetry config pypi-token.pypi $POETRY_PYPI_TOKEN_PYPI | |
| poetry publish --no-interaction |