Skip to content

Instantly share code, notes, and snippets.

@scivision
Created May 25, 2025 06:31
Show Gist options
  • Save scivision/b89d4c27829ded2fe16825a47b5e2466 to your computer and use it in GitHub Desktop.
Save scivision/b89d4c27829ded2fe16825a47b5e2466 to your computer and use it in GitHub Desktop.
PyPI upload from GitHub Actions without API token

For each package, go into PyPI projects and add a publisher.

This uses separate jobs for build and publish as recommended to avoid a poisoned package from hijacking the publish to put hostile code in a package.

# https://docs.pypi.org/trusted-publishers/using-a-publisher/
name: publish
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install builder
run: pip install build
- name: Build package
run: python -m build
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/
pypi-publish:
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist/
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment