|
| 1 | +name: Automated Release Process |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Install uv |
| 19 | + uses: astral-sh/setup-uv@v5 |
| 20 | + with: |
| 21 | + enable-cache: true |
| 22 | + python-version: "3.10" |
| 23 | + |
| 24 | + - name: Test |
| 25 | + run: | |
| 26 | + uv run pytest tests/ --ignore=tests/test_rendering.py |
| 27 | +
|
| 28 | + - name: Determine Version Change |
| 29 | + id: version_check |
| 30 | + run: | |
| 31 | + VERSION="v$(uv version --short)" |
| 32 | + echo "Current version: $VERSION" |
| 33 | +
|
| 34 | + LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 35 | + https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.tag_name') |
| 36 | + echo "Latest release version: $LATEST_RELEASE" |
| 37 | +
|
| 38 | + if [ "$VERSION" != "$LATEST_RELEASE" ]; then |
| 39 | + echo "version_changed=true" >> $GITHUB_OUTPUT |
| 40 | + echo "new_version=$VERSION" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "version_changed=false" >> $GITHUB_OUTPUT |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Create Release |
| 46 | + if: steps.version_check.outputs.version_changed == 'true' |
| 47 | + uses: softprops/action-gh-release@v2 |
| 48 | + with: |
| 49 | + tag_name: ${{ steps.version_check.outputs.new_version }} |
| 50 | + generate_release_notes: True |
| 51 | + |
| 52 | + - name: mint API token |
| 53 | + id: mint-token |
| 54 | + run: | |
| 55 | + # retrieve the ambient OIDC token |
| 56 | + resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ |
| 57 | + "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") |
| 58 | + oidc_token=$(jq -r '.value' <<< "${resp}") |
| 59 | +
|
| 60 | + # exchange the OIDC token for an API token |
| 61 | + resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}") |
| 62 | + api_token=$(jq -r '.token' <<< "${resp}") |
| 63 | +
|
| 64 | + # mask the newly minted API token, so that we don't accidentally leak it |
| 65 | + echo "::add-mask::${api_token}" |
| 66 | +
|
| 67 | + # see the next step in the workflow for an example of using this step output |
| 68 | + echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" |
| 69 | +
|
| 70 | + - name: Build and publish to PyPI |
| 71 | + if: steps.version_check.outputs.version_changed == 'true' |
| 72 | + run: | |
| 73 | + uv build |
| 74 | + uv publish --token ${{ steps.mint-token.outputs.api-token }} |
0 commit comments