|
1 | | -name: Publish to PyPi |
| 1 | +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI |
2 | 2 |
|
3 | | -on: |
4 | | - release: |
5 | | - types: [published] |
| 3 | +# Trigger on push (the publish job to PyPI only runs for tag pushes) |
| 4 | +on: push |
6 | 5 |
|
7 | 6 | jobs: |
8 | | - deploy: |
| 7 | + build: |
| 8 | + name: Build distribution 📦 |
9 | 9 | runs-on: ubuntu-latest |
| 10 | + |
10 | 11 | steps: |
11 | | - |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + persist-credentials: false |
12 | 15 | - name: Set up Python |
13 | | - |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: "3.x" |
| 19 | + - name: Install pypa/build |
| 20 | + run: python3 -m pip install --upgrade build --user |
| 21 | + - name: Build a binary wheel and a source tarball |
| 22 | + run: python3 -m build |
| 23 | + - name: Store the distribution packages |
| 24 | + uses: actions/upload-artifact@v4 |
| 25 | + with: |
| 26 | + name: python-package-distributions |
| 27 | + path: dist/ |
| 28 | + |
| 29 | + publish-to-pypi: |
| 30 | + name: Publish Python 🐍 distribution 📦 to PyPI |
| 31 | + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes |
| 32 | + needs: [build] |
| 33 | + runs-on: ubuntu-latest |
| 34 | + # NOTE: create a GitHub Environment named `pypi` in your repo settings and require manual approval |
| 35 | + environment: |
| 36 | + name: pypi |
| 37 | + url: https://pypi.org/project/mapie/ |
| 38 | + permissions: |
| 39 | + id-token: write # mandatory for Trusted Publishing |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Download all the dists |
| 43 | + uses: actions/download-artifact@v4 |
14 | 44 | with: |
15 | | - python-version: "3.13" |
16 | | - - name: Install build dependencies |
17 | | - run: | |
18 | | - python -m pip install -e '.[dev]' |
19 | | - - name: Build package |
20 | | - run: python -m build |
21 | | - - name: Publish package |
22 | | - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 |
| 45 | + name: python-package-distributions |
| 46 | + path: dist/ |
| 47 | + - name: Publish distribution 📦 to PyPI |
| 48 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 49 | + |
| 50 | + publish-to-testpypi: |
| 51 | + name: Publish Python 🐍 distribution 📦 to TestPyPI |
| 52 | + needs: [build] |
| 53 | + runs-on: ubuntu-latest |
| 54 | + environment: |
| 55 | + name: testpypi |
| 56 | + url: https://test.pypi.org/project/mapie/ |
| 57 | + permissions: |
| 58 | + id-token: write |
| 59 | + |
| 60 | + steps: |
| 61 | + - name: Download all the dists |
| 62 | + uses: actions/download-artifact@v4 |
| 63 | + with: |
| 64 | + name: python-package-distributions |
| 65 | + path: dist/ |
| 66 | + - name: Publish distribution 📦 to TestPyPI |
| 67 | + uses: pypa/gh-action-pypi-publish@release/v1 |
23 | 68 | with: |
24 | | - user: __token__ |
25 | | - password: ${{ secrets.PYPI_API_TOKEN_VBL }} |
| 69 | + repository-url: https://test.pypi.org/legacy/ |
| 70 | + |
| 71 | +# Notes: |
| 72 | +# - Make sure to update the pypi and testpypi Trusted Publishers in the settings of your PyPI and TestPyPI accounts. |
| 73 | +# - Configure GitHub Environments named `pypi` and `testpypi` in your repository settings. |
| 74 | +# - For `pypi` the environment should require manual approval (recommended by PyPI Trusted Publishing). |
| 75 | +# - After switching to Trusted Publishing you should remove any long-lived PYPI API token secrets from the repo and |
| 76 | +# revoke them on PyPI/TestPyPI as described in the PyPI guide. |
0 commit comments