Skip to content

Commit efa0cbb

Browse files
ci(backport): Add GitHub artifact attestations to package distribution (#2496)
* Backport: - PR #2473 - PR #2478 --------- Co-authored-by: Matthew Feickert <[email protected]>
1 parent 1de3759 commit efa0cbb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

.github/workflows/publish-package.yml

+35
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ jobs:
2929
build:
3030
name: Build Python distribution
3131
runs-on: ubuntu-latest
32+
permissions:
33+
id-token: write
34+
attestations: write
35+
contents: read
36+
3237
steps:
3338
- uses: actions/checkout@v4
3439
with:
@@ -96,6 +101,16 @@ jobs:
96101
- name: List contents of wheel
97102
run: python -m zipfile --list dist/pyhf-*.whl
98103

104+
- name: Generate artifact attestation for sdist and wheel
105+
# If publishing to TestPyPI or PyPI
106+
if: >-
107+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository == 'scikit-hep/pyhf')
108+
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' && github.repository == 'scikit-hep/pyhf')
109+
|| (github.event_name == 'release' && github.event.action == 'published' && github.repository == 'scikit-hep/pyhf')
110+
uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2
111+
with:
112+
subject-path: "dist/pyhf-*"
113+
99114
- name: Upload distribution artifact
100115
uses: actions/upload-artifact@v4
101116
with:
@@ -125,6 +140,26 @@ jobs:
125140
- name: List all files
126141
run: ls -lh dist
127142

143+
- name: Verify sdist artifact attestation
144+
# If publishing to TestPyPI or PyPI
145+
if: >-
146+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository == 'scikit-hep/pyhf')
147+
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' && github.repository == 'scikit-hep/pyhf')
148+
|| (github.event_name == 'release' && github.event.action == 'published' && github.repository == 'scikit-hep/pyhf')
149+
env:
150+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
run: gh attestation verify dist/pyhf-*.tar.gz --repo ${{ github.repository }}
152+
153+
- name: Verify wheel artifact attestation
154+
# If publishing to TestPyPI or PyPI
155+
if: >-
156+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.repository == 'scikit-hep/pyhf')
157+
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' && github.repository == 'scikit-hep/pyhf')
158+
|| (github.event_name == 'release' && github.event.action == 'published' && github.repository == 'scikit-hep/pyhf')
159+
env:
160+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
161+
run: gh attestation verify dist/pyhf-*.whl --repo ${{ github.repository }}
162+
128163
- name: Publish distribution 📦 to Test PyPI
129164
# Publish to TestPyPI on tag events of if manually triggered
130165
# Compare to 'true' string as booleans get turned into strings in the console

0 commit comments

Comments
 (0)