|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + test: |
| 7 | + strategy: |
| 8 | + matrix: |
| 9 | + os: [windows-latest, ubuntu-latest, macos-latest] |
| 10 | + runs-on: ${{ matrix.os }} |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + - name: Install dependencies |
| 14 | + run: pipx install hatch |
| 15 | + - name: Lint and typecheck |
| 16 | + run: | |
| 17 | + hatch run lint-check |
| 18 | + - name: Test |
| 19 | + run: | |
| 20 | + hatch test --all |
| 21 | +
|
| 22 | + - uses: codecov/codecov-action@v5 |
| 23 | + with: |
| 24 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 25 | + fail_ci_if_error: true |
| 26 | + verbose: true |
| 27 | + |
| 28 | + release: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + environment: release |
| 31 | + needs: test |
| 32 | + if: startsWith(github.ref, 'refs/tags/') |
| 33 | + permissions: |
| 34 | + contents: write |
| 35 | + id-token: write |
| 36 | + |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + - name: Install dependencies |
| 40 | + shell: bash |
| 41 | + run: pipx install hatch |
| 42 | + - name: mint API token |
| 43 | + id: mint-token |
| 44 | + run: | |
| 45 | + # retrieve the ambient OIDC token |
| 46 | + resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ |
| 47 | + "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") |
| 48 | + oidc_token=$(jq -r '.value' <<< "${resp}") |
| 49 | +
|
| 50 | + # exchange the OIDC token for an API token |
| 51 | + resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}") |
| 52 | + api_token=$(jq -r '.token' <<< "${resp}") |
| 53 | +
|
| 54 | + # mask the newly minted API token, so that we don't accidentally leak it |
| 55 | + echo "::add-mask::${api_token}" |
| 56 | +
|
| 57 | + # see the next step in the workflow for an example of using this step output |
| 58 | + echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" |
| 59 | + - name: Build and publish on PyPI |
| 60 | + env: |
| 61 | + HATCH_INDEX_USER: __token__ |
| 62 | + HATCH_INDEX_AUTH: ${{ steps.mint-token.outputs.api-token }} |
| 63 | + run: | |
| 64 | + hatch build |
| 65 | + hatch publish |
| 66 | + - name: Create release |
| 67 | + uses: ncipollo/release-action@v1 |
| 68 | + with: |
| 69 | + draft: true |
| 70 | + body: ${{ github.event.head_commit.message }} |
| 71 | + allowUpdates: true |
| 72 | + omitBodyDuringUpdate: true |
| 73 | + updateOnlyUnreleased: true |
| 74 | + artifacts: dist/*.whl,dist/*.tar.gz |
| 75 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments