Skip to content

Commit 0292590

Browse files
committed
Setup PyPI trusted publishing
1 parent d4b08f0 commit 0292590

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

.github/workflows/sdk_publish.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,34 @@ permissions:
1212
- RELEASES.md
1313
- '*/RELEASES.md'
1414
jobs:
15+
mint-token:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
id-token: write
20+
outputs:
21+
api-token: ${{ steps.mint-token.outputs.api-token }}
22+
steps:
23+
- name: Mint API token
24+
run: |
25+
# retrieve the ambient OIDC token
26+
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
27+
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
28+
oidc_token=$(jq -r '.value' <<< "${resp}")
29+
30+
# exchange the OIDC token for an API token
31+
resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
32+
api_token=$(jq -r '.token' <<< "${resp}")
33+
34+
# mask the newly minted API token, so that we don't accidentally leak it
35+
echo "::add-mask::${api_token}"
36+
37+
# see the next step in the workflow for an example of using this step output
38+
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
1539
publish:
40+
needs: mint-token
1641
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15
1742
secrets:
1843
github_access_token: ${{ secrets.GITHUB_TOKEN }}
19-
pypi_token: ${{ secrets.PYPI_TOKEN }}
44+
pypi_token: ${{ needs.mint-token.outputs.api-token }}
2045
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}

0 commit comments

Comments
 (0)