Skip to content

Commit 858a9de

Browse files
takluyverdi
andauthored
Simplify Gitlab examples - trusted publishing is now integrated in twine (#17682)
* Simplify Gitlab examples - trusted publishing is now integrated in twine * Apply suggestions from code review --------- Co-authored-by: Dustin Ingram <[email protected]>
1 parent 187b0df commit 858a9de

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

docs/user/attestations/producing-attestations.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,11 @@ Before uploading attestations to the index, please:
187187
aud: pypi
188188
script:
189189
# Install dependencies
190-
- apt update && apt install -y jq
191-
- python -m pip install -U twine id
190+
- python -m pip install -U twine
192191

193-
# Retrieve the OIDC token from GitLab CI/CD, and exchange it for a PyPI API token
194-
- oidc_token=$(python -m id pypi)
195-
# Replace "https://pypi.org/*" with "https://test.pypi.org/*" if uploading to TestPyPI
196-
- resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\":\"${oidc_token}\"}")
197-
- api_token=$(jq --raw-output '.token' <<< "${resp}")
198-
199-
# Upload to PyPI authenticating via the newly-minted token, including the generated attestations
192+
# Upload to PyPI using Trusted Publishing, including the generated attestations
200193
# Add "--repository testpypi" if uploading to TestPyPI
201-
- twine upload --verbose --attestations -u __token__ -p "${api_token}" python_pkg/dist/*
194+
- twine upload --attestations python_pkg/dist/*
202195
```
203196

204197
Note how, compared with the [Trusted Publishing workflow][GitLab Trusted Publishing], it has the

docs/user/trusted-publishers/using-a-publisher.md

+7-15
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,8 @@ below describe the setup process for each supported Trusted Publisher.
384384
[`id_tokens`](https://docs.gitlab.com/ee/ci/yaml/index.html#id_tokens) is used
385385
to request an OIDC token from GitLab with name `PYPI_ID_TOKEN` and audience
386386
`pypi`.
387-
- This OIDC token is extracted from the CI/CD environment using the
388-
[`id`](https://pypi.org/project/id/) package.
389-
- The OIDC token is then sent to PyPI in exchange for a PyPI API token, which
387+
- Twine is called to upload the package with no token specified.
388+
It sends the OIDC token to PyPI in exchange for a PyPI API token, which
390389
is then used to publish the package using `twine`.
391390

392391
```yaml
@@ -411,16 +410,9 @@ below describe the setup process for each supported Trusted Publisher.
411410
aud: pypi
412411
script:
413412
# Install dependencies
414-
- apt update && apt install -y jq
415-
- python -m pip install -U twine id
416-
417-
# Retrieve the OIDC token from GitLab CI/CD, and exchange it for a PyPI API token
418-
- oidc_token=$(python -m id PYPI)
419-
# Replace "https://pypi.org/*" with "https://test.pypi.org/*" if uploading to TestPyPI
420-
- resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\":\"${oidc_token}\"}")
421-
- api_token=$(jq --raw-output '.token' <<< "${resp}")
422-
423-
# Upload to PyPI authenticating via the newly-minted token
424-
# Add "--repository testpypi" if uploading to TestPyPI
425-
- twine upload -u __token__ -p "${api_token}" python_pkg/dist/*
413+
- python -m pip install -U twine
414+
415+
# Upload to PyPI, add "--repository testpypi" if uploading to TestPyPI
416+
# With no token specified, twine will use Trusted Publishing
417+
- twine upload python_pkg/dist/*
426418
```

0 commit comments

Comments
 (0)