Skip to content

Create python-publish.yml #1

Create python-publish.yml

Create python-publish.yml #1

Workflow file for this run

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/