Skip to content

Commit d93acff

Browse files
authored
chore: Refactor GitHub Actions workflow for publishing to PyPI and TestPyPI (#795)
* Refactor GitHub Actions workflow for publishing to PyPI and TestPyPI * Update release checklist to include optional monitoring steps for TestPyPI and PyPI publish jobs
1 parent f6a7be0 commit d93acff

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

.github/workflows/publish.yml

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,76 @@
1-
name: Publish to PyPi
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
22

3-
on:
4-
release:
5-
types: [published]
3+
# Trigger on push (the publish job to PyPI only runs for tag pushes)
4+
on: push
65

76
jobs:
8-
deploy:
7+
build:
8+
name: Build distribution 📦
99
runs-on: ubuntu-latest
10+
1011
steps:
11-
- uses: actions/[email protected]
12+
- uses: actions/checkout@v4
13+
with:
14+
persist-credentials: false
1215
- name: Set up Python
13-
uses: actions/[email protected]
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
1444
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
2368
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.

RELEASE_CHECKLIST.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
* `make doc`
1010
- [ ] Commit every change from the steps above
1111
- [ ] Update the version number with `bump2version major|minor|patch` (a commit is automatically made)
12-
- [ ] Build source distribution:
13-
* `make clean-build`
14-
* `make build`
15-
- [ ] Check that your package is ready for publication: `twine check dist/*`
16-
- [ ] Upload it to TestPyPi:
17-
* you need to create an account on test.pypi.org first if you don't have one, then an API key, and ask one the existing MAPIE maintainer to add you as a maintainer
18-
* `twine upload --repository-url https://test.pypi.org/legacy/ dist/*` (use `__token__` as username and your api token as password)
19-
- [ ] Test upload on TestPyPi:
20-
* create a new empty virtual environment
21-
* `pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mapie` (mapie should install from test.pypi.org, may not work if using uv)
2212
- [ ] Push the commit created by bump2version: `git push origin master`
13+
- [ ] (Optional) Monitor the TestPyPI publish job on GitHub Actions:
14+
* The workflow automatically publishes to TestPyPI on every push to master
15+
* Check the Actions tab to verify the build and TestPyPI publish succeeded
16+
* Test installation from TestPyPI if desired:
17+
- create a new empty virtual environment
18+
- `pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mapie`
2319
- [ ] Push the tag created by bump2version: `git push --tags`
20+
- [ ] Monitor the PyPI publish job on GitHub Actions:
21+
* The workflow automatically triggers on tag pushes
22+
* The `pypi` environment requires manual approval (configured in repo settings)
23+
* Approve the deployment in the GitHub Actions UI when prompted
24+
* Verify the package appears on PyPI after approval
2425
- [ ] Create new release on GitHub for this tag.
2526
- [ ] Merge the automatically created pull request on https://github.com/conda-forge/mapie-feedstock. You need to be added as a maintainer on this repo first. To create the pull request
2627
manually to avoid waiting for automation, create an issue with the name `@conda-forge-admin, please update version`

0 commit comments

Comments
 (0)