Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/pypi_mint_token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Mint PyPI Token
on:
workflow_call:
outputs:
pypi_token:
description: Minted PyPI API token via OIDC
value: ${{ jobs.mint.outputs.pypi_token }}
jobs:
mint:
name: Mint PyPI token
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Mint API token
id: mint-token
run: |
# retrieve the ambient OIDC token
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
oidc_token=$(jq -r '.value' <<< "${resp}")

# exchange the OIDC token for an API token
resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
api_token=$(jq -r '.token' <<< "${resp}")

# mask the newly minted API token, so that we don't accidentally leak it
echo "::add-mask::${api_token}"

# see the next step in the workflow for an example of using this step output
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
outputs:
pypi_token: ${{ steps.mint-token.outputs.pypi_token }}
8 changes: 6 additions & 2 deletions .github/workflows/sdk_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ permissions:
contents: write
pull-requests: write
statuses: write
"on":
id-token: write
on:
workflow_dispatch:
inputs:
force:
Expand All @@ -17,7 +18,10 @@ permissions:
schedule:
- cron: 0 0 * * *
jobs:
mint_pypi_token:
uses: ./.github/workflows/pypi_mint_token.yaml
generate:
needs: mint_pypi_token
uses: speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15
with:
force: ${{ github.event.inputs.force }}
Expand All @@ -26,5 +30,5 @@ jobs:
speakeasy_version: latest
secrets:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
pypi_token: ${{ needs.mint_pypi_token.outputs.pypi_token }}
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
8 changes: 6 additions & 2 deletions .github/workflows/sdk_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ permissions:
contents: write
pull-requests: write
statuses: write
"on":
id-token: write
on:
push:
branches:
- main
paths:
- RELEASES.md
- '*/RELEASES.md'
jobs:
mint_pypi_token:
uses: ./.github/workflows/pypi_mint_token.yaml
publish:
needs: mint_pypi_token
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15
secrets:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
pypi_token: ${{ needs.mint_pypi_token.outputs.pypi_token }}
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
Loading