@@ -40,19 +40,45 @@ jobs:
4040 runs-on : ubuntu-latest
4141 steps :
4242 - name : Install Python (if missing)
43- run : apt-get update && apt-get install -y python3 python3-pip
43+ run : |
44+ sudo apt-get update
45+ sudo apt-get install -y python3 python3-pip
4446
4547 - name : Update python dependencies
46- run : python3 -m pip install -U packaging --break-system-packages
48+ run : |
49+ python3 -m venv venv
50+ source venv/bin/activate
51+ pip install -U packaging
4752
4853 - uses : actions/download-artifact@v4
4954 with :
5055 name : artifact
5156 path : dist
5257
58+ - name : mint API token
59+ id : mint-token
60+ run : |
61+ # retrieve the ambient OIDC token
62+ resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
63+ "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
64+ oidc_token=$(jq -r '.value' <<< "${resp}")
65+
66+ # exchange the OIDC token for an API token
67+ resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
68+ api_token=$(jq -r '.token' <<< "${resp}")
69+
70+ # mask the newly minted API token, so that we don't accidentally leak it
71+ echo "::add-mask::${api_token}"
72+
73+ # see the next step in the workflow for an example of using this step output
74+ echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
75+
5376 - name : Publish package to TestPyPI
77+ env :
78+ PATH : ${{ github.workspace }}/venv/bin:$PATH
5479 uses : pypa/gh-action-pypi-publish@release/v1
5580 with :
81+ password : ${{ steps.mint-token.outputs.api-token }}
5682 repository-url : https://test.pypi.org/legacy/
5783
5884 upload_pypi :
@@ -61,27 +87,35 @@ jobs:
6187 if : startsWith(github.ref, 'refs/tags/v') && github.repository == 'linux-nvme/libnvme'
6288 steps :
6389 - name : Install Python (if missing)
64- run : apt-get update && apt-get install -y python3 python3-pip
90+ run : |
91+ sudo apt-get update
92+ sudo apt-get install -y python3 python3-pip
6593
6694 - name : Update python dependencies
67- run : python3 -m pip install -U packaging --break-system-packages
95+ run : |
96+ python3 -m venv venv
97+ source venv/bin/activate
98+ pip install -U packaging
6899
69100 - name : Check if it is a release tag
70101 id : check-tag
71102 run : |
72103 if [[ ${{ github.event.ref }} =~ ^refs/tags/v([0-9]+\.[0-9]+)(\.[0-9]+)?(-rc[0-9]+)?$ ]]; then
73104 echo ::set-output name=match::true
74105 fi
106+
75107 - name : Download artifiact
76108 uses : actions/download-artifact@v4
77109 if : steps.check-tag.outputs.match == 'true'
78110 with :
79111 name : artifact
80112 path : dist
113+
81114 - name : Publish package to PyPI
115+ env :
116+ PATH : ${{ github.workspace }}/venv/bin:$PATH
82117 uses : pypa/gh-action-pypi-publish@release/v1
83118 if : steps.check-tag.outputs.match == 'true'
84119 with :
85120 user : __token__
86121 password : ${{ secrets.PYPI_API_TOKEN }}
87- verify-metadata : false
0 commit comments