Skip to content

Commit 5b12a32

Browse files
committed
pypi release workflow
1 parent 662fb15 commit 5b12a32

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build-release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Bump version and push tag
13+
id: bump
14+
uses: hennejg/[email protected]
15+
with:
16+
github_token: ${{ secrets.GITHUB_TOKEN }}
17+
release_branches: main
18+
19+
- uses: ncipollo/release-action@v1
20+
with:
21+
tag: ${{ steps.bump.outputs.new_tag }}
22+
generateReleaseNotes: true
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
on:
2+
release:
3+
types:
4+
- published
5+
6+
name: release
7+
8+
jobs:
9+
pypi:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.x"
19+
20+
- name: deps
21+
run: python -m pip install -U build
22+
23+
- name: build
24+
run: python -m build
25+
26+
- name: mint API token
27+
id: mint-token
28+
run: |
29+
# retrieve the ambient OIDC token
30+
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
31+
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
32+
oidc_token=$(jq -r '.value' <<< "${resp}")
33+
34+
# exchange the OIDC token for an API token
35+
resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
36+
api_token=$(jq -r '.token' <<< "${resp}")
37+
38+
# mask the newly minted API token, so that we don't accidentally leak it
39+
echo "::add-mask::${api_token}"
40+
41+
# see the next step in the workflow for an example of using this step output
42+
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
43+
44+
- name: publish
45+
# gh-action-pypi-publish uses TWINE_PASSWORD automatically
46+
uses: pypa/gh-action-pypi-publish@release/v1
47+
with:
48+
password: ${{ steps.mint-token.outputs.api-token }}

.github/workflows/release.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)