Skip to content

Commit 1abd70a

Browse files
committed
Convert build pipelines to use two jobs
This avoids exposing the GitHub token (`id-token: write`) used for trusted publishing to the build process (`build` and the underlying backend), improving security via isolation. Also, add `twine check` to the build+publish pipeline, per the recommendations of various publishing guides, to catch malformed metadata. Big thanks to @webknjaz for spotting this improvement and for providing tools, docs, and guidance for publishing!
1 parent 6bdc483 commit 1abd70a

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

.github/workflows/publish_to_pypi.yaml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,40 @@ on:
55
types: [published]
66

77
jobs:
8-
publish:
8+
build-dists:
99
runs-on: ubuntu-latest
10-
environment: publish
11-
permissions:
12-
id-token: write
1310

1411
steps:
1512
- uses: actions/checkout@v3
1613
- uses: actions/setup-python@v4
1714
with:
1815
python-version: "3.11"
1916

20-
- run: python -m pip install build
21-
- run: python -m build .
17+
- run: python -m pip install build twine
18+
19+
- name: Build Dists
20+
run: python -m build .
21+
22+
- name: Check Dists (twine)
23+
run: twine check dist/*
24+
25+
- uses: actions/upload-artifact@v3
26+
with:
27+
name: packages
28+
path: dist/*
29+
30+
publish:
31+
needs: [build-dists]
32+
runs-on: ubuntu-latest
33+
environment: publish-testpypi
34+
permissions:
35+
id-token: write
36+
37+
steps:
38+
- uses: actions/download-artifact@v3
39+
with:
40+
name: packages
41+
path: dist
2242

2343
- name: Publish to PyPI
2444
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/publish_to_test_pypi.yaml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ on:
1212
tags: ["*"]
1313

1414
jobs:
15-
publish:
15+
build-dists:
1616
runs-on: ubuntu-latest
17-
environment: publish-testpypi
18-
permissions:
19-
id-token: write
2017

2118
steps:
2219
- uses: actions/checkout@v3
2320
- uses: actions/setup-python@v4
2421
with:
2522
python-version: "3.11"
2623

27-
- run: python -m pip install build
24+
- run: python -m pip install build twine
2825

2926
- name: Set dev version prior to upload (auto)
3027
if: ${{ github.event.inputs.devNumber == '' }}
@@ -34,9 +31,32 @@ jobs:
3431
if: ${{ github.event.inputs.devNumber != '' }}
3532
run: python ./scripts/set-dev-version.py -n ${{ github.event.inputs.devNumber }}
3633

37-
- run: python -m build .
34+
- name: Build Dists
35+
run: python -m build .
36+
37+
- name: Check Dists (twine)
38+
run: twine check dist/*
39+
40+
- uses: actions/upload-artifact@v3
41+
with:
42+
name: packages
43+
path: dist/*
44+
45+
46+
publish:
47+
needs: [build-dists]
48+
runs-on: ubuntu-latest
49+
environment: publish-testpypi
50+
permissions:
51+
id-token: write
52+
53+
steps:
54+
- uses: actions/download-artifact@v3
55+
with:
56+
name: packages
57+
path: dist
3858

3959
- name: Publish to TestPyPI
4060
uses: pypa/gh-action-pypi-publish@release/v1
4161
with:
42-
repository_url: https://test.pypi.org/legacy/
62+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)