@@ -17,11 +17,11 @@ cache:
17
17
image: python:3.8-buster
18
18
before_script:
19
19
# want to set up a virtualenv to cache
20
- - apt-get install -y --no-install-recommends git
20
+ - apt-get install -y --no-install-recommends git jq
21
21
- python -V
22
22
- python -m venv .venv
23
23
- source .venv/bin/activate
24
- - python -m pip install -U pip pipx
24
+ - python -m pip install -U pip pipx id
25
25
- python -m pipx ensurepath
26
26
- python -m pip freeze
27
27
@@ -152,7 +152,12 @@ make_wheels:
152
152
- make_wheels
153
153
{%- endif %}
154
154
script:
155
- - pipx run twine upload --verbose dist/*whl dist/*gz
155
+ # Retrieve the OIDC token from GitLab CI/CD and exchange it for a PyPI API token
156
+ - oidc_token=$(python -m id PYPI)
157
+ - response=$(curl -X POST "${OIDC_MINT_TOKEN_URL}" -d "{\"token\":\"${oidc_token}\"}")
158
+ - api_token=$(jq --raw-output '.token' <<< "${response}")
159
+
160
+ - pipx run twine upload --password "${api_token}" --verbose dist/*whl dist/*gz
156
161
157
162
deploy_staging:
158
163
extends: .deploy
@@ -162,7 +167,7 @@ deploy_staging:
162
167
variables:
163
168
TWINE_REPOSITORY: testpypi
164
169
TWINE_USERNAME: __token__
165
- TWINE_PASSWORD: $TESTPYPI_TOKEN
170
+ OIDC_MINT_TOKEN_URL: "https://test.pypi.org/_/oidc/mint-token"
166
171
167
172
deploy_production:
168
173
extends: .deploy
@@ -171,4 +176,4 @@ deploy_production:
171
176
variables:
172
177
TWINE_REPOSITORY: pypi
173
178
TWINE_USERNAME: __token__
174
- TWINE_PASSWORD: $PYPI_TOKEN
179
+ OIDC_MINT_TOKEN_URL: "https://pypi.org/_/oidc/mint-token"
0 commit comments