|
| 1 | +name: Create release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + publish-pypi: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + name: PyPI Release |
| 16 | + environment: release |
| 17 | + permissions: |
| 18 | + id-token: write # for PyPI trusted publishing |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v4 |
| 23 | + with: |
| 24 | + python-version: 3 |
| 25 | + cache: pip |
| 26 | + cache-dependency-path: pyproject.toml |
| 27 | + |
| 28 | + - name: Install build dependencies (pypa/build, twine) |
| 29 | + run: | |
| 30 | + pip install -U pip |
| 31 | + pip install build twine |
| 32 | +
|
| 33 | + - name: Build distribution |
| 34 | + run: python -m build |
| 35 | + |
| 36 | + - name: Mint PyPI API token |
| 37 | + id: mint-token |
| 38 | + uses: actions/github-script@v6 |
| 39 | + with: |
| 40 | + # language=JavaScript |
| 41 | + script: | |
| 42 | + // retrieve the ambient OIDC token |
| 43 | + const oidc_request_token = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN; |
| 44 | + const oidc_request_url = process.env.ACTIONS_ID_TOKEN_REQUEST_URL; |
| 45 | + const oidc_resp = await fetch(`${oidc_request_url}&audience=pypi`, { |
| 46 | + headers: {Authorization: `bearer ${oidc_request_token}`}, |
| 47 | + }); |
| 48 | + const oidc_token = (await oidc_resp.json()).value; |
| 49 | + |
| 50 | + // exchange the OIDC token for an API token |
| 51 | + const mint_resp = await fetch('https://pypi.org/_/oidc/github/mint-token', { |
| 52 | + method: 'post', |
| 53 | + body: `{"token": "${oidc_token}"}` , |
| 54 | + headers: {'Content-Type': 'application/json'}, |
| 55 | + }); |
| 56 | + const api_token = (await mint_resp.json()).token; |
| 57 | + |
| 58 | + // mask the newly minted API token, so that we don't accidentally leak it |
| 59 | + core.setSecret(api_token) |
| 60 | + core.setOutput('api-token', api_token) |
| 61 | + |
| 62 | + - name: Upload to PyPI |
| 63 | + env: |
| 64 | + TWINE_NON_INTERACTIVE: "true" |
| 65 | + TWINE_USERNAME: "__token__" |
| 66 | + TWINE_PASSWORD: "${{ steps.mint-token.outputs.api-token }}" |
| 67 | + run: | |
| 68 | + twine check dist/* |
| 69 | + twine upload dist/* |
| 70 | +
|
| 71 | + github-release: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + name: GitHub release |
| 74 | + environment: release |
| 75 | + permissions: |
| 76 | + contents: write # for softprops/action-gh-release to create GitHub release |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v3 |
| 79 | + - name: Get release version |
| 80 | + id: get_version |
| 81 | + uses: actions/github-script@v6 |
| 82 | + with: |
| 83 | + script: core.setOutput('version', context.ref.replace("refs/tags/v", "")) |
| 84 | + |
| 85 | + - name: Create GitHub release |
| 86 | + uses: softprops/action-gh-release@v1 |
| 87 | + if: startsWith(github.ref, 'refs/tags/') |
| 88 | + with: |
| 89 | + name: "sphinxcontrib-devhelp ${{ steps.get_version.outputs.version }}" |
| 90 | + body: "Changelog: https://www.sphinx-doc.org/en/master/changes.html" |
0 commit comments