You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add GitHub Actions to PyPI trusted publishing example (#15753)
Add a complete example for the most common publishing workflow, GitHub
Actions to PyPI, with screenshots for settings and a standalone
companion repo.
Closes#14398
The workflow uses [trusted publishing](https://docs.pypi.org/trusted-publishers/), so no credentials
352
+
need to be configured.
353
+
354
+
In the example workflow, we use a script to test that the source distribution and the wheel are both
355
+
functional and we didn't miss any files. This step is recommended, but optional.
356
+
357
+
First, add a release workflow to your project:
358
+
359
+
```yaml title=".github/workflows/publish.yml"
360
+
name: "Publish"
361
+
362
+
on:
363
+
push:
364
+
tags:
365
+
# Publish on any tag starting with a `v`, e.g., v0.1.0
366
+
- v*
367
+
368
+
jobs:
369
+
run:
370
+
runs-on: ubuntu-latest
371
+
environment:
372
+
name: pypi
373
+
permissions:
374
+
id-token: write
375
+
contents: read
376
+
steps:
377
+
- name: Checkout
378
+
uses: actions/checkout@v5
379
+
- name: Install uv
380
+
uses: astral-sh/setup-uv@v6
381
+
- name: Install Python 3.13
382
+
run: uv python install 3.13
383
+
- name: Build
384
+
run: uv build
385
+
# Check that basic features work and we didn't miss to include crucial files
386
+
- name: Smoke test (wheel)
387
+
run: uv run --isolated --no-project --with dist/*.whl tests/smoke_test.py
388
+
- name: Smoke test (source distribution)
389
+
run: uv run --isolated --no-project --with dist/*.tar.gz tests/smoke_test.py
390
+
- name: Publish
391
+
run: uv publish
392
+
```
393
+
394
+
Then, create the environment defined in the workflow in the GitHub repository under "Settings" ->
395
+
"Environments".
396
+
397
+

398
+
399
+
Add a [trusted publisher](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) to your PyPI
400
+
project in the project settings under "Publishing". Ensure that all fields match with your GitHub
401
+
configuration.
402
+
403
+

0 commit comments