Skip to content

Commit 7ccee68

Browse files
committed
chore(ci): use OIDC trusted publishing for pypi.org
1 parent a2b8c8c commit 7ccee68

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/workflows/release.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ jobs:
99
release:
1010
if: github.repository == 'python-gitlab/python-gitlab'
1111
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write
14+
environment: pypi.org
1215
steps:
1316
- uses: actions/checkout@v3.5.0
1417
with:
1518
fetch-depth: 0
1619
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
20+
- name: mint API token
21+
id: mint-token
22+
run: |
23+
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
24+
oidc_token=$(jq '.value' <<< "${resp}")
25+
26+
resp=$(curl -X POST https://pypi.org/_/oidc/github/mint-token -d "{\"token\":${oidc_token}}")
27+
api_token=$(jq '.token' <<< "${resp}" | tr -d '"')
28+
29+
echo "::add-mask::${api_token}"
30+
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
1731
- name: Python Semantic Release
1832
uses: relekang/python-semantic-release@v7.33.2
1933
with:
2034
github_token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
21-
pypi_token: ${{ secrets.PYPI_TOKEN }}
35+
pypi_token: ${{ steps.mint-token.outputs.api-token }}

0 commit comments

Comments
 (0)