another attempt at publishing packages via GA #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Python package | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
jobs: | ||
# test_package: | ||
# uses: ./.github/workflows/test_package.yml | ||
build: | ||
# needs: test_package | ||
permissions: | ||
id-token: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.x | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install poetry | ||
- name: Build the package | ||
run: poetry build | ||
- name: Mint 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 '.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 '.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 package | ||
env: | ||
PYPI_TOKEN: ${{ outputs.api-token }} | ||
run: | | ||
poetry config pypi-token.pypi $PYPI_TOKEN | ||
poetry publish |