| 1 |
name: Publish to PyPI |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
tags: |
| 6 |
- "*" |
| 7 |
|
| 8 |
permissions: |
| 9 |
contents: read |
| 10 |
|
| 11 |
jobs: |
| 12 |
build: |
| 13 |
name: "Build dists" |
| 14 |
runs-on: "ubuntu-latest" |
| 15 |
environment: |
| 16 |
name: "publish" |
| 17 |
outputs: |
| 18 |
hashes: ${{ steps.hash.outputs.hashes }} |
| 19 |
|
| 20 |
steps: |
| 21 |
- name: Harden the runner (Audit all outbound calls) |
| 22 |
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 |
| 23 |
with: |
| 24 |
egress-policy: audit |
| 25 |
|
| 26 |
- name: "Checkout repository" |
| 27 |
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" |
| 28 |
|
| 29 |
- name: "Setup Python" |
| 30 |
uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065" |
| 31 |
with: |
| 32 |
python-version: "3.x" |
| 33 |
|
| 34 |
- name: "Install dependencies" |
| 35 |
run: python -m pip install build==0.8.0 |
| 36 |
|
| 37 |
- name: "Build dists" |
| 38 |
run: | |
| 39 |
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) \ |
| 40 |
python -m build |
| 41 |
|
| 42 |
- name: "Generate hashes" |
| 43 |
id: hash |
| 44 |
run: | |
| 45 |
cd dist && echo "::set-output name=hashes::$(sha256sum * | base64 -w0)" |
| 46 |
|
| 47 |
- name: "Upload dists" |
| 48 |
uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02" |
| 49 |
with: |
| 50 |
name: "dist" |
| 51 |
path: "dist/" |
| 52 |
if-no-files-found: error |
| 53 |
retention-days: 5 |
| 54 |
|
| 55 |
provenance: |
| 56 |
needs: [build] |
| 57 |
permissions: |
| 58 |
actions: read |
| 59 |
contents: write |
| 60 |
id-token: write # Needed to access the workflow's OIDC identity. |
| 61 |
uses: "slsa-framework/slsa-github-generator/.github/workflows/[email protected]" |
| 62 |
with: |
| 63 |
base64-subjects: "${{ needs.build.outputs.hashes }}" |
| 64 |
upload-assets: true |
| 65 |
compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163 |
| 66 |
|
| 67 |
publish: |
| 68 |
name: "Publish" |
| 69 |
if: startsWith(github.ref, 'refs/tags/') |
| 70 |
needs: ["build", "provenance"] |
| 71 |
permissions: |
| 72 |
contents: write |
| 73 |
id-token: write |
| 74 |
runs-on: "ubuntu-latest" |
| 75 |
|
| 76 |
steps: |
| 77 |
- name: Harden the runner (Audit all outbound calls) |
| 78 |
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 |
| 79 |
with: |
| 80 |
egress-policy: audit |
| 81 |
|
| 82 |
- name: "Download dists" |
| 83 |
uses: "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093" |
| 84 |
with: |
| 85 |
name: "dist" |
| 86 |
path: "dist/" |
| 87 |
|
| 88 |
- name: "Publish dists to PyPI" |
| 89 |
uses: "pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc" |