Skip to content

Commit 52d605f

Browse files
authored
Merge pull request #160 from AFM-SPM/ns-rse/159-improve-pypi-workflow
ci(pypi): Improves PyPI publishing workflow
2 parents ac06413 + 8057c4a commit 52d605f

1 file changed

Lines changed: 54 additions & 11 deletions

File tree

.github/workflows/pypi.yaml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ name: Publish package to PyPi
22
# See https://docs.pypi.org/trusted-publishers/adding-a-publisher/
33

44
on:
5-
push:
6-
tags:
7-
- v*
5+
pull_request:
6+
branches:
7+
- main
88
workflow_dispatch: # Uncomment line if you also want to trigger action manually
99

10-
permissions:
11-
id-token: write
12-
1310
jobs:
14-
build-release:
11+
build:
12+
name: Build Package
1513
runs-on: ubuntu-latest
16-
environment: pypi-publish
17-
name: Publish package to PyPi
1814
steps:
1915
- uses: actions/checkout@v4
2016
with:
@@ -25,15 +21,62 @@ jobs:
2521
python-version: 3.11
2622
- name: Installing the package
2723
run: |
28-
pip3 install .
2924
pip3 install .[pypi]
3025
- name: Build package
3126
run: |
3227
pip3 install --upgrade setuptools
3328
export DEB_PYTHON_INSTALL_LAYOUT=deb_system
3429
python -m build --no-isolation
35-
- name: Publish package to PyPI
30+
- name: Store the distribution packages
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: python-package-distributions
34+
path: dist/
35+
36+
publish-to-pypi:
37+
name: Publish Python 🐍 distribution 📦 to PyPI
38+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
39+
needs:
40+
- build
41+
runs-on: ubuntu-latest
42+
permissions:
43+
id-token: write
44+
environment:
45+
name: pypi-publish
46+
url: https://pypi.org/p/topostats
47+
steps:
48+
- name: Download all the dists
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
54+
- name: Publish distribution 📦 to PyPI
3655
uses: pypa/gh-action-pypi-publish@release/v1
3756
with:
3857
user: __token__
3958
password: ${{ secrets.PYPI_API_TOKEN }}
59+
60+
# publish-to-testpypi:
61+
# name: Publish Python 🐍 distribution 📦 to TestPyPI
62+
# needs:
63+
# - build
64+
# runs-on: ubuntu-latest
65+
66+
# environment:
67+
# name: testpypi
68+
# url: https://test.pypi.org/p/topostats
69+
70+
# permissions:
71+
# id-token: write # IMPORTANT: mandatory for trusted publishing
72+
73+
# steps:
74+
# - name: Download all the dists
75+
# uses: actions/download-artifact@v4
76+
# with:
77+
# name: python-package-distributions
78+
# path: dist/
79+
# - name: Publish distribution 📦 to TestPyPI
80+
# uses: pypa/gh-action-pypi-publish@release/v1
81+
# with:
82+
# repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)