|
7 | 7 | jobs: |
8 | 8 | build: |
9 | 9 | runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
10 | 12 | strategy: |
11 | 13 | matrix: |
12 | 14 | python-version: [ "3.11", "3.12" ] |
@@ -55,61 +57,57 @@ jobs: |
55 | 57 |
|
56 | 58 | - name: Create release |
57 | 59 | if: steps.version.outputs.released == 'true' |
58 | | - uses: ncipollo/release-action@v1 |
59 | | - with: |
60 | | - tag: v${{ steps.version.outputs.version }} |
61 | | - generateReleaseNotes: true |
| 60 | + env: |
| 61 | + GH_TOKEN: ${{ github.token }} |
| 62 | + VERSION: ${{ steps.version.outputs.version }} |
| 63 | + run: gh release create "v$VERSION" --target "$GITHUB_SHA" --generate-notes |
62 | 64 |
|
63 | | - publish: |
| 65 | + package: |
64 | 66 | runs-on: ubuntu-latest |
65 | 67 | needs: [release] |
66 | 68 | if: needs.release.outputs.released == 'true' |
67 | 69 | permissions: |
68 | | - id-token: write |
| 70 | + contents: read |
69 | 71 | steps: |
70 | | - - uses: actions/checkout@v3 |
| 72 | + - uses: actions/checkout@v4 |
71 | 73 |
|
72 | 74 | - uses: actions/setup-python@v4 |
73 | 75 | with: |
74 | 76 | python-version: "3.x" |
75 | 77 |
|
76 | | - - name: deps |
77 | | - run: python -m pip install -U build |
78 | | - |
79 | 78 | - name: build |
80 | | - run: python -m build |
81 | | - |
82 | | - - name: mint API token |
83 | | - id: mint-token |
84 | 79 | run: | |
85 | | - # retrieve the ambient OIDC token |
86 | | - resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ |
87 | | - "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") |
88 | | - oidc_token=$(jq -r '.value' <<< "${resp}") |
89 | | -
|
90 | | - # exchange the OIDC token for an API token |
91 | | - resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}") |
92 | | - api_token=$(jq -r '.token' <<< "${resp}") |
| 80 | + python -m pip install -U build |
| 81 | + python -m build |
93 | 82 |
|
94 | | - # mask the newly minted API token, so that we don't accidentally leak it |
95 | | - echo "::add-mask::${api_token}" |
| 83 | + - uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: dist |
| 86 | + path: dist/ |
96 | 87 |
|
97 | | - # see the next step in the workflow for an example of using this step output |
98 | | - echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" |
| 88 | + # PyPI trusted publishing trusts this whole workflow file, so only this job holds id-token: write, and it |
| 89 | + # installs and runs nothing but the pinned publish action on the distributions the package job built. |
| 90 | + publish: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: [package] |
| 93 | + permissions: |
| 94 | + id-token: write |
| 95 | + steps: |
| 96 | + - uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + name: dist |
| 99 | + path: dist/ |
99 | 100 |
|
100 | 101 | - name: publish |
101 | | - # gh-action-pypi-publish uses TWINE_PASSWORD automatically |
102 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
103 | | - with: |
104 | | - password: ${{ steps.mint-token.outputs.api-token }} |
| 102 | + uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 |
105 | 103 |
|
106 | 104 | notify-failure: |
107 | | - needs: [build, release, publish] |
| 105 | + needs: [build, release, package, publish] |
108 | 106 | if: failure() |
109 | 107 | runs-on: ubuntu-latest |
110 | 108 | steps: |
111 | 109 | - name: Notify Slack on release failure |
112 | | - uses: slackapi/slack-github-action@v4.0.0 |
| 110 | + uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 |
113 | 111 | with: |
114 | 112 | errors: true |
115 | 113 | webhook: ${{ secrets.PLATFORM_INCIDENT_SLACK_CHANNEL_WEBHOOK }} |
|
0 commit comments