Create python-publish.yml #1
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: Build, Stage, Approve, Publish | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| jobs: | |
| build-test-stage: | |
| name: Build + Test + Stage to TestPyPI | |
| 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.11" | |
| - name: Install build & test deps | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build pytest | |
| - name: Build distribution | |
| run: python -m build | |
| - name: Run tests | |
| run: pytest -q | |
| - name: Upload artifacts for later | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| # π₯ STAGING PUBLISH β TestPyPI | |
| - name: Publish to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| user: __token__ | |
| password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| approve-publish-prod: | |
| name: Approve β Publish to PyPI β Trigger Docs | |
| needs: build-test-stage | |
| runs-on: ubuntu-latest | |
| # π₯ MANUAL APPROVAL REQUIRED HERE | |
| environment: | |
| name: production | |
| url: https://pypi.org/project/YOUR-PACKAGE-NAME/ # <<< CHANGE THIS | |
| steps: | |
| - name: Download artifacts from staging job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| # π₯ PRODUCTION PUBLISH β PyPI | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| user: __token__ | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| # π₯ READTHEDOCS REBUILD | |
| - name: Trigger ReadTheDocs Build | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: Token ${{ secrets.RTD_TOKEN }}" \ | |
| https://readthedocs.org/api/v3/projects/YOUR-RTD-PROJECT-SLUG/versions/latest/builds/ |