Skip to content

chore: Refactor GitHub Actions workflow for publishing to PyPI and Te… #36

chore: Refactor GitHub Actions workflow for publishing to PyPI and Te…

chore: Refactor GitHub Actions workflow for publishing to PyPI and Te… #36

Workflow file for this run

name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
# Trigger on push (the publish job to PyPI only runs for tag pushes)
on: push
jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: python3 -m pip install --upgrade build --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs: [build]
runs-on: ubuntu-latest
# NOTE: create a GitHub Environment named `pypi` in your repo settings and require manual approval
environment:
name: pypi
url: https://pypi.org/project/mapie/
permissions:
id-token: write # mandatory for Trusted Publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs: [build]
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/project/mapie/
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# Notes:
# - Make sure to update the pypi and testpypi Trusted Publishers in the settings of your PyPI and TestPyPI accounts.
# - Configure GitHub Environments named `pypi` and `testpypi` in your repository settings.
# - For `pypi` the environment should require manual approval (recommended by PyPI Trusted Publishing).
# - After switching to Trusted Publishing you should remove any long-lived PYPI API token secrets from the repo and
# revoke them on PyPI/TestPyPI as described in the PyPI guide.