|
| 1 | +name: Release |
| 2 | + |
1 | 3 | on:
|
2 | 4 | release:
|
3 | 5 | types:
|
4 | 6 | - published
|
5 | 7 |
|
6 |
| -name: release |
7 |
| - |
8 |
| -permissions: |
9 |
| - # Needed to access the workflow's OIDC identity. |
10 |
| - id-token: write |
11 |
| - |
12 |
| - # Needed to upload release assets. |
13 |
| - contents: write |
14 |
| - |
15 | 8 | jobs:
|
16 |
| - pypi: |
17 |
| - name: Build, sign and publish release to PyPI |
| 9 | + build: |
| 10 | + name: Build and sign artifacts |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + id-token: write |
| 14 | + outputs: |
| 15 | + hashes: ${{ steps.hash.outputs.hashes }} |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@d171c3b028d844f2bf14e9fdec0c58114451e4bf |
| 18 | + |
| 19 | + - uses: actions/setup-python@7f80679172b057fc5e90d70d197929d454754a5a |
| 20 | + |
| 21 | + - name: deps |
| 22 | + run: python -m pip install -U build |
| 23 | + |
| 24 | + - name: build |
| 25 | + run: python -m build |
| 26 | + |
| 27 | + - name: sign |
| 28 | + run: | |
| 29 | + mkdir -p smoketest-artifacts |
| 30 | +
|
| 31 | + # we smoke-test sigstore by installing each of the distributions |
| 32 | + # we've built in a fresh environment and using each to sign and |
| 33 | + # verify for itself, using the ambient OIDC identity |
| 34 | + for dist in dist/*; do |
| 35 | + dist_base="$(basename "${dist}")" |
| 36 | +
|
| 37 | + python -m venv smoketest-env |
| 38 | +
|
| 39 | + ./smoketest-env/bin/python -m pip install "${dist}" |
| 40 | +
|
| 41 | + # NOTE: signing artifacts currently go in a separate directory, |
| 42 | + # to avoid confusing the package uploader (which otherwise tries |
| 43 | + # to upload them to PyPI and fails). Future versions of twine |
| 44 | + # and the gh-action-pypi-publish action should support these artifacts. |
| 45 | + ./smoketest-env/bin/python -m \ |
| 46 | + sigstore sign "${dist}" \ |
| 47 | + --output-signature smoketest-artifacts/"${dist_base}.sig" \ |
| 48 | + --output-certificate smoketest-artifacts/"${dist_base}.crt" |
| 49 | +
|
| 50 | + ./smoketest-env/bin/python -m \ |
| 51 | + sigstore verify "${dist}" \ |
| 52 | + --cert "smoketest-artifacts/${dist_base}.crt" \ |
| 53 | + --signature "smoketest-artifacts/${dist_base}.sig" \ |
| 54 | + --cert-oidc-issuer https://token.actions.githubusercontent.com |
| 55 | +
|
| 56 | + rm -rf smoketest-env |
| 57 | + done |
| 58 | +
|
| 59 | + - name: Generate hashes for provenance |
| 60 | + shell: bash |
| 61 | + id: hash |
| 62 | + run: | |
| 63 | + # sha256sum generates sha256 hash for all artifacts. |
| 64 | + # base64 -w0 encodes to base64 and outputs on a single line. |
| 65 | + # sha256sum artifact1 artifact2 ... | base64 -w0 |
| 66 | + echo "::set-output name=hashes::$(sha256sum ./dist/* | base64 -w0)" |
| 67 | +
|
| 68 | + - name: Upload built packages |
| 69 | + uses: actions/upload-artifact@v3 |
| 70 | + with: |
| 71 | + name: built-packages |
| 72 | + path: ./dist/ |
| 73 | + if-no-files-found: warn |
| 74 | + |
| 75 | + - name: Upload smoketest-artifacts |
| 76 | + uses: actions/upload-artifact@v3 |
| 77 | + with: |
| 78 | + name: smoketest-artifacts |
| 79 | + path: smoketest-artifacts/ |
| 80 | + if-no-files-found: warn |
| 81 | + |
| 82 | + generate-provenance: |
| 83 | + needs: [build] |
| 84 | + name: Generate build provenance |
| 85 | + permissions: |
| 86 | + actions: read # To read the workflow path. |
| 87 | + id-token: write # To sign the provenance. |
| 88 | + contents: write # To add assets to a release. |
| 89 | + # Currently this action needs to be referred by tag. More details at: |
| 90 | + # https://github.com/slsa-framework/slsa-github-generator#verification-of-provenance |
| 91 | + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.1 |
| 92 | + with: |
| 93 | + attestation-name: provenance-sigstore-${{ github.event.release.tag_name }}.intoto.jsonl |
| 94 | + base64-subjects: "${{ needs.build.outputs.hashes }}" |
| 95 | + upload-assets: true |
| 96 | + |
| 97 | + release-pypi: |
| 98 | + needs: [build, generate-provenance] |
| 99 | + runs-on: ubuntu-latest |
| 100 | + permissions: {} |
| 101 | + steps: |
| 102 | + - name: Download artifacts diretories # goes to current working directory |
| 103 | + uses: actions/download-artifact@v3 |
| 104 | + |
| 105 | + - name: publish |
| 106 | + uses: pypa/gh-action-pypi-publish@717ba43cfbb0387f6ce311b169a825772f54d295 |
| 107 | + with: |
| 108 | + user: __token__ |
| 109 | + password: ${{ secrets.PYPI_TOKEN }} |
| 110 | + packages_dir: built-packages/ |
| 111 | + |
| 112 | + release-github: |
| 113 | + needs: [build, generate-provenance] |
18 | 114 | runs-on: ubuntu-latest
|
| 115 | + permissions: |
| 116 | + # Needed to upload release assets. |
| 117 | + contents: write |
19 | 118 | steps:
|
20 |
| - - uses: actions/checkout@d171c3b028d844f2bf14e9fdec0c58114451e4bf |
21 |
| - |
22 |
| - - uses: actions/setup-python@7f80679172b057fc5e90d70d197929d454754a5a |
23 |
| - |
24 |
| - - name: deps |
25 |
| - run: python -m pip install -U build |
26 |
| - |
27 |
| - - name: build |
28 |
| - run: python -m build |
29 |
| - |
30 |
| - - name: sign |
31 |
| - run: | |
32 |
| - mkdir -p smoketest-artifacts |
33 |
| -
|
34 |
| - # we smoke-test sigstore by installing each of the distributions |
35 |
| - # we've built in a fresh environment and using each to sign and |
36 |
| - # verify for itself, using the ambient OIDC identity |
37 |
| - for dist in dist/*; do |
38 |
| - dist_base="$(basename "${dist}")" |
39 |
| -
|
40 |
| - python -m venv smoketest-env |
41 |
| -
|
42 |
| - ./smoketest-env/bin/python -m pip install "${dist}" |
43 |
| -
|
44 |
| - # NOTE: signing artifacts currently go in a separate directory, |
45 |
| - # to avoid confusing the package uploader (which otherwise tries |
46 |
| - # to upload them to PyPI and fails). Future versions of twine |
47 |
| - # and the gh-action-pypi-publish action should support these artifacts. |
48 |
| - ./smoketest-env/bin/python -m \ |
49 |
| - sigstore sign "${dist}" \ |
50 |
| - --output-signature smoketest-artifacts/"${dist_base}.sig" \ |
51 |
| - --output-certificate smoketest-artifacts/"${dist_base}.crt" |
52 |
| -
|
53 |
| - ./smoketest-env/bin/python -m \ |
54 |
| - sigstore verify "${dist}" \ |
55 |
| - --cert "smoketest-artifacts/${dist_base}.crt" \ |
56 |
| - --signature "smoketest-artifacts/${dist_base}.sig" \ |
57 |
| - --cert-oidc-issuer https://token.actions.githubusercontent.com \ |
58 |
| -
|
59 |
| - rm -rf smoketest-env |
60 |
| - done |
61 |
| -
|
62 |
| - - name: publish |
63 |
| - uses: pypa/gh-action-pypi-publish@717ba43cfbb0387f6ce311b169a825772f54d295 |
64 |
| - with: |
65 |
| - user: __token__ |
66 |
| - password: ${{ secrets.PYPI_TOKEN }} |
67 |
| - |
68 |
| - - name: upload artifacts to github |
69 |
| - # Confusingly, this action also supports updating releases, not |
70 |
| - # just creating them. This is what we want here, since we've manually |
71 |
| - # created the release that triggered the action. |
72 |
| - uses: softprops/action-gh-release@v1 |
73 |
| - with: |
74 |
| - # dist/ contains the built packages, which smoketest-artifacts/ |
75 |
| - # contains the signatures and certificates. |
76 |
| - files: | |
77 |
| - dist/* |
78 |
| - smoketest-artifacts/* |
| 119 | + - name: Download artifacts diretories # goes to current working directory |
| 120 | + uses: actions/download-artifact@v3 |
| 121 | + |
| 122 | + - name: Upload artifacts to github |
| 123 | + # Confusingly, this action also supports updating releases, not |
| 124 | + # just creating them. This is what we want here, since we've manually |
| 125 | + # created the release that triggered the action. |
| 126 | + uses: softprops/action-gh-release@v1 |
| 127 | + with: |
| 128 | + # smoketest-artifacts/ contains the signatures and certificates. |
| 129 | + files: | |
| 130 | + built-packages/* |
| 131 | + smoketest-artifacts/* |
0 commit comments