@@ -2,39 +2,43 @@ name: Publish
22on :
33 push :
44 tags : ['*']
5+ # Org policy only allows actions from rivian-owned repos, so every step here is
6+ # a plain shell command instead of a `uses:` action.
57jobs :
6- build :
8+ publish :
79 runs-on : ubuntu-latest
10+ environment : pypi
11+ permissions :
12+ contents : read
13+ id-token : write
814 steps :
9- - uses : actions/checkout@v4
10- - uses : actions/setup-python@v5
11- with :
12- python-version : ' 3.x'
15+ - name : Checkout
16+ run : |
17+ git init .
18+ git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
19+ git fetch --depth 1 origin "$GITHUB_SHA"
20+ git checkout FETCH_HEAD
1321 - name : Check tag matches package version
1422 run : |
15- version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
23+ version=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
1624 if [ "$version" != "$GITHUB_REF_NAME" ]; then
1725 echo "Tag $GITHUB_REF_NAME does not match pyproject.toml version $version"
1826 exit 1
1927 fi
2028 - name : Build
2129 run : |
22- pip install build twine
23- python -m build
24- twine check dist/*
25- - uses : actions/upload-artifact@v4
26- with :
27- name : dist
28- path : dist/
29- publish :
30- needs : build
31- runs-on : ubuntu-latest
32- environment : pypi
33- permissions :
34- id-token : write
35- steps :
36- - uses : actions/download-artifact@v4
37- with :
38- name : dist
39- path : dist/
40- - uses : pypa/gh-action-pypi-publish@release/v1
30+ python3 -m venv .venv
31+ .venv/bin/pip install build twine
32+ .venv/bin/python -m build
33+ .venv/bin/twine check dist/*
34+ - name : Publish to PyPI
35+ # Trusted publishing: exchange the GitHub OIDC token for a short-lived
36+ # PyPI upload token (what pypa/gh-action-pypi-publish does internally).
37+ run : |
38+ set -euo pipefail
39+ oidc=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
40+ "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi" | jq -r .value)
41+ token=$(curl -sSf -X POST https://pypi.org/_/oidc/mint-token \
42+ -d "{\"token\": \"$oidc\"}" | jq -r .token)
43+ echo "::add-mask::$token"
44+ TWINE_USERNAME=__token__ TWINE_PASSWORD="$token" .venv/bin/twine upload dist/*
0 commit comments