Skip to content

Commit f8b7d75

Browse files
authored
Enable trusted publishing (#6)
1 parent cf3c166 commit f8b7d75

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,39 @@ on:
1010
- v*
1111

1212
jobs:
13+
build-package:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
# write attestations and id-token are necessary for attest-build-provenance-github
17+
attestations: write
18+
id-token: write
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
persist-credentials: false
24+
- uses: hynek/build-and-inspect-python-package@v2
25+
with:
26+
# Prove that the packages were built in the context of this workflow.
27+
attest-build-provenance-github: true
1328
publish:
1429
runs-on: ubuntu-latest
30+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
31+
# Use the `release` GitHub environment to protect the Trusted Publishing (OIDC)
32+
# workflow by requiring signoff from a maintainer.
33+
environment: release
34+
needs: build-package
35+
permissions:
36+
# write id-token is necessary for trusted publishing (OIDC)
37+
id-token: write
1538
steps:
16-
- uses: actions/checkout@v2
17-
- name: Set up Python
18-
uses: actions/setup-python@v4
39+
- name: Download Distribution Artifacts
40+
uses: actions/download-artifact@v4
1941
with:
20-
python-version: "3.10"
21-
- name: Install build dependencies
22-
run: python -m pip install build
23-
- name: Build package
24-
run: python -m build
25-
- name: Publish to PyPI
42+
# The build-and-inspect-python-package action invokes upload-artifact.
43+
# These are the correct arguments from that action.
44+
name: Packages
45+
path: dist
46+
- name: Publish Package to PyPI
2647
uses: pypa/gh-action-pypi-publish@release/v1
27-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
28-
with:
29-
user: __token__
30-
password: ${{ secrets.PYPI_API_TOKEN }}
48+
# Implicitly attests that the packages were uploaded in the context of this workflow.

0 commit comments

Comments
 (0)