Skip to content

Commit 7be09e5

Browse files
authored
chore(ci): use OIDC trusted publishing for pypi.org (#2559)
* chore(ci): use OIDC trusted publishing for pypi.org * chore(ci): explicitly install setuptools in tests
1 parent a2b8c8c commit 7be09e5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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 }}

requirements-test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ pytest-github-actions-annotate-failures==0.1.8
77
pytest==7.2.2
88
PyYaml==5.4.1
99
responses==0.23.1
10+
setuptools==67.7.2
11+
wheel==0.40.0

0 commit comments

Comments
 (0)