Skip to content

Commit 9e4afda

Browse files
authored
Add PyPI token fallback for releases
Use PYPI_API_TOKEN when present and otherwise use trusted publishing.
1 parent 021cdcb commit 9e4afda

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ jobs:
6565
uses: astral-sh/setup-uv@v8.1.0
6666

6767
- name: Publish distributions
68-
run: uv publish --trusted-publishing always dist/*
68+
env:
69+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
70+
run: |
71+
if [ -n "${PYPI_API_TOKEN}" ]; then
72+
uv publish --token "${PYPI_API_TOKEN}" dist/*
73+
else
74+
uv publish --trusted-publishing always dist/*
75+
fi
6976
7077
- name: Create GitHub release
7178
env:

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ uv run twine check dist/*
3232
Releases are automatic after a version change lands on `main`. If
3333
`pyproject.toml` contains a version without a matching `vX.Y.Z` tag, GitHub
3434
Actions creates the tag and dispatches `release.yml`. The release workflow
35-
builds, validates, publishes to PyPI, and creates a GitHub Release.
35+
builds, validates, publishes to PyPI through trusted publishing or the
36+
`PYPI_API_TOKEN` fallback secret, and creates a GitHub Release.
3637

3738
## Dependency Policy
3839

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,13 @@ Releases are automatic:
178178
2. Merge to `main`.
179179
3. GitHub Actions creates the missing `vX.Y.Z` tag.
180180
4. GitHub Actions dispatches `release.yml` for that tag.
181-
5. The release workflow builds, validates, publishes to PyPI with trusted
182-
publishing, and creates a GitHub Release.
181+
5. The release workflow builds, validates, publishes to PyPI, and creates a
182+
GitHub Release.
183183

184184
PyPI trusted publishing must be configured for the `release.yml` workflow and
185-
the `pypi` environment before the publish step can succeed. Manual tag pushes
186-
with the `vX.Y.Z` format still run the same release workflow.
185+
the `pypi` environment for credential-free publishing. If the repository still
186+
uses a `PYPI_API_TOKEN` secret, the release workflow can use that as a fallback.
187+
Manual tag pushes with the `vX.Y.Z` format still run the same release workflow.
187188

188189
## License
189190

0 commit comments

Comments
 (0)