From 8e11a56e99d13e0f950f4ca26d0d836054aecc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 13 Mar 2024 23:14:52 +0100 Subject: [PATCH] Create release.yml --- .github/workflows/release.yml | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6aff77e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +on: + release: + types: + - published + +name: release + +jobs: + pypi: + name: upload release to PyPI + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: deps + run: python -m pip install -U build + + - name: build + run: python -m build + + - 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}" + + - name: publish + # gh-action-pypi-publish uses TWINE_PASSWORD automatically + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ steps.mint-token.outputs.api-token }}