Skip to content

Commit b25dbeb

Browse files
weiji14seisman
authored andcommitted
CI: Separate jobs for publishing to TestPyPI and PyPI (#3742)
1 parent 2a84b5e commit b25dbeb

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

.github/workflows/publish-to-pypi.yml

+49-9
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,17 @@ on:
3535
# - main
3636

3737
jobs:
38-
publish-pypi:
39-
name: Publish to PyPI
38+
build:
39+
name: Build distribution 📦
4040
runs-on: ubuntu-latest
41-
permissions:
42-
# This permission is mandatory for OIDC publishing
43-
id-token: write
44-
if: github.repository == 'GenericMappingTools/pygmt'
4541

4642
steps:
4743
- name: Checkout
4844
uses: actions/[email protected]
4945
with:
5046
# fetch all history so that setuptools-scm works
5147
fetch-depth: 0
48+
persist-credentials: false
5249

5350
- name: Set up Python
5451
uses: actions/[email protected]
@@ -74,11 +71,54 @@ jobs:
7471
echo "Generated files:"
7572
ls -lh dist/
7673
77-
- name: Publish to Test PyPI
74+
- name: Store the distribution packages
75+
uses: actions/[email protected]
76+
with:
77+
name: python-package-distributions
78+
path: dist/
79+
80+
publish-to-testpypi:
81+
name: Publish Python 🐍 distribution 📦 to TestPyPI
82+
if: github.repository == 'GenericMappingTools/pygmt'
83+
needs:
84+
- build
85+
runs-on: ubuntu-latest
86+
environment:
87+
name: testpypi
88+
url: https://test.pypi.org/project/pygmt
89+
permissions:
90+
id-token: write # IMPORTANT: mandatory for trusted OIDC publishing
91+
92+
steps:
93+
- name: Download all the dists
94+
uses: actions/[email protected]
95+
with:
96+
name: python-package-distributions
97+
path: dist/
98+
99+
- name: Publish distribution 📦 to TestPyPI
78100
uses: pypa/[email protected]
79101
with:
80102
repository-url: https://test.pypi.org/legacy/
81103

82-
- name: Publish to PyPI
83-
if: startsWith(github.ref, 'refs/tags')
104+
publish-pypi:
105+
name: Publish Python 🐍 distribution 📦 to PyPI
106+
if: github.repository == 'GenericMappingTools/pygmt' && startsWith(github.ref, 'refs/tags/')
107+
needs:
108+
- build
109+
runs-on: ubuntu-latest
110+
environment:
111+
name: pypi
112+
url: https://pypi.org/project/pygmt/
113+
permissions:
114+
id-token: write # IMPORTANT: mandatory for trusted OIDC publishing
115+
116+
steps:
117+
- name: Download all the dists
118+
uses: actions/[email protected]
119+
with:
120+
name: python-package-distributions
121+
path: dist/
122+
123+
- name: Publish distribution 📦 to PyPI
84124
uses: pypa/[email protected]

0 commit comments

Comments
 (0)