Skip to content

Commit

Permalink
Target PyPI in create-release.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 24, 2023
1 parent 21fbee5 commit 0882914
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,41 @@ jobs:
id: mint-token
uses: actions/github-script@v6
with:
# language=JavaScript
script: |
// retrieve the ambient OIDC token
const oidc_request_token = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
const oidc_request_url = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
const oidc_resp = await fetch(`${oidc_request_url}&audience=testpypi`, {
headers: {Authorization: `bearer ${oidc_request_token}`},
}
);
const oidc_resp = await fetch(`${oidc_request_url}&audience=pypi`, {
headers: {Authorization: `bearer ${oidc_request_token}`},
});
const oidc_token = (await oidc_resp.json()).value;
github.log.warn(`len(oidc_token): ${oidc_token.length}`);
// exchange the OIDC token for an API token
const mint_resp = await fetch('https://test.pypi.org/_/oidc/github/mint-token', {
method: 'post',
body: `{"token": "${oidc_token}"}` ,
headers: {'Content-Type': 'application/json'},
}
);
const mint_resp = await fetch('https://pypi.org/_/oidc/github/mint-token', {
method: 'post',
body: `{"token": "${oidc_token}"}` ,
headers: {'Content-Type': 'application/json'},
});
const api_token = (await mint_resp.json()).token;
github.log.warn(`len(api_token): ${api_token.length}`);

// mask the newly minted API token, so that we don't accidentally leak it
core.setSecret(api_token)
core.setOutput('api-token', api_token)

- name: Upload to Test PyPI
- name: Upload to PyPI
env:
TWINE_NON_INTERACTIVE: "true"
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: "${{ steps.mint-token.outputs.api-token }}"
TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
run: |
twine check dist/*
twine upload dist/*
github-release:
runs-on: ubuntu-latest
name: GitHub release
environment: release
permissions:
contents: write # for softprops/action-gh-release to create GitHub release
steps:
Expand Down

0 comments on commit 0882914

Please sign in to comment.