Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cache:
image: python:3.8-buster
before_script:
# want to set up a virtualenv to cache
- apt-get install -y --no-install-recommends git
- apt-get install -y --no-install-recommends git jq
- python -V
- python -m venv .venv
- source .venv/bin/activate
Expand Down Expand Up @@ -152,23 +152,34 @@ make_wheels:
- make_wheels
{%- endif %}
script:
- pipx run twine upload --verbose dist/*whl dist/*gz
# Retrieve the OIDC token from GitLab CI/CD and exchange it for a PyPI API token
- oidc_token=$(pipx run id PYPI)
- response=$(curl -X POST "${OIDC_MINT_TOKEN_URL}" -d "{\"token\":\"${oidc_token}\"}")
- api_token=$(jq --raw-output '.token' <<< "${response}")

- pipx run twine upload --password "${api_token}" --verbose dist/*whl dist/*gz

deploy_staging:
extends: .deploy
rules:
- if:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"
id_tokens:
PYPI_ID_TOKEN:
aud: testpypi
variables:
TWINE_REPOSITORY: testpypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: $TESTPYPI_TOKEN
OIDC_MINT_TOKEN_URL: "https://test.pypi.org/_/oidc/mint-token"

deploy_production:
extends: .deploy
only:
- tags
id_tokens:
PYPI_ID_TOKEN:
aud: pypi
variables:
TWINE_REPOSITORY: pypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: $PYPI_TOKEN
OIDC_MINT_TOKEN_URL: "https://pypi.org/_/oidc/mint-token"
Loading