Skip to content

Commit 93e5603

Browse files
build: add pipeline
1 parent 9817678 commit 93e5603

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/main.yml

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

0 commit comments

Comments
 (0)