Skip to content

Commit a6c47af

Browse files
Document GitHub artifact attestations in PyPI workflow
1 parent ecf32d9 commit a6c47af

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎source/guides/github-actions-ci-cd-sample/publish-to-pypi.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,35 @@ jobs:
2929
name: python-package-distributions
3030
path: dist/
3131

32+
attest-distributions:
33+
name: Generate artifact attestations
34+
needs:
35+
- build
36+
runs-on: ubuntu-latest
37+
38+
permissions:
39+
id-token: write
40+
contents: read
41+
attestations: write
42+
43+
steps:
44+
- name: Download all the dists
45+
uses: actions/download-artifact@v6
46+
with:
47+
name: python-package-distributions
48+
path: dist/
49+
- name: Generate artifact attestations
50+
uses: actions/attest-build-provenance@v4
51+
with:
52+
subject-path: dist/*
53+
3254
publish-to-pypi:
3355
name: >-
3456
Publish Python 🐍 distribution 📦 to PyPI
3557
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
3658
needs:
3759
- build
60+
- attest-distributions
3861
runs-on: ubuntu-latest
3962
environment:
4063
name: pypi
@@ -55,6 +78,7 @@ jobs:
5578
name: Publish Python 🐍 distribution 📦 to TestPyPI
5679
needs:
5780
- build
81+
- attest-distributions
5882
runs-on: ubuntu-latest
5983

6084
environment:

‎source/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows.rst‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ This guide shows you how to publish a Python distribution
1212
whenever a tagged commit is pushed.
1313
It will use the `pypa/gh-action-pypi-publish GitHub Action`_ for
1414
publishing. It also uses GitHub's `upload-artifact`_ and `download-artifact`_ actions
15-
for temporarily storing and downloading the source packages.
15+
for temporarily storing and downloading the source packages, and `actions/attest-build-provenance`_
16+
to generate `GitHub artifact attestations`_ for the built distributions.
1617

1718
.. attention::
1819

@@ -101,8 +102,9 @@ Checking out the project and building distributions
101102
===================================================
102103

103104
We will have to define two jobs to publish to PyPI
104-
and TestPyPI respectively, and an additional job to
105-
build the distribution packages.
105+
and TestPyPI respectively, an additional job to
106+
build the distribution packages, and a job to generate
107+
GitHub artifact attestations for those packages.
106108

107109
First, we'll define the job for building the dist packages of
108110
your project and storing them for later use:
@@ -129,6 +131,19 @@ So add this to the steps list:
129131
.. literalinclude:: github-actions-ci-cd-sample/publish-to-pypi.yml
130132
:language: yaml
131133
:start-at: Install pypa/build
134+
:end-before: attest-distributions
135+
136+
Generating GitHub artifact attestations
137+
=======================================
138+
139+
After building the distributions, generate a build provenance attestation
140+
for each file in the ``dist/`` folder. This is separate from uploading
141+
the files to a package index, so the attestation job downloads the stored
142+
artifact and runs before the publishing jobs.
143+
144+
.. literalinclude:: github-actions-ci-cd-sample/publish-to-pypi.yml
145+
:language: yaml
146+
:start-at: attest-distributions
132147
:end-before: publish-to-pypi
133148

134149
Defining a workflow job environment
@@ -171,8 +186,9 @@ the contents of the ``dist/`` folder into PyPI unconditionally.
171186
Starting with version
172187
`v1.11.0 <https://github.com/pypa/gh-action-pypi-publish/releases/tag/v1.11.0>`_,
173188
`pypa/gh-action-pypi-publish`_ generates and uploads :pep:`740`-compatible
174-
attestations for each distribution by default. No additional manual
175-
signing steps are required.
189+
attestations for each distribution by default. This complements the GitHub
190+
artifact attestation job above, which records build provenance in GitHub.
191+
No additional manual signing steps are required.
176192

177193

178194
Separate workflow for publishing to TestPyPI
@@ -235,6 +251,10 @@ sure that your release pipeline remains healthy!
235251
https://github.com/actions/download-artifact
236252
.. _`upload-artifact`:
237253
https://github.com/actions/upload-artifact
254+
.. _`actions/attest-build-provenance`:
255+
https://github.com/actions/attest-build-provenance
256+
.. _`GitHub artifact attestations`:
257+
https://docs.github.com/en/actions/how-tos/secure-your-work/use-artifact-attestations/use-artifact-attestations
238258
.. _Secrets:
239259
https://docs.github.com/en/actions/reference/encrypted-secrets
240260
.. _Trusted Publishing: https://docs.pypi.org/trusted-publishers/

0 commit comments

Comments
 (0)