Skip to content

Commit 8d2c4e2

Browse files
Tahtaclaude
andcommitted
Publish workflow: PyPI trusted publishing, started by hand and gated by PYPI_PUBLISH_ENABLED
Tests and builds the package, then uploads it from the pypi environment with an OIDC token. The header lists the pending-publisher values to enter on pypi.org. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e77ed2b commit 8d2c4e2

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Publishes cleanedweb to PyPI with trusted publishing (no API token).
2+
#
3+
# Runs only when started by hand from the Actions tab, with "publish" typed in, and only while the
4+
# repository variable PYPI_PUBLISH_ENABLED is "true".
5+
#
6+
# One-time setup on pypi.org (Account settings > Publishing > Add a new pending publisher):
7+
# PyPI project name: cleanedweb
8+
# Owner: cleanedweb Repository name: cleanedweb-python
9+
# Workflow name: publish.yml Environment name: pypi
10+
#
11+
# Bump the version and its CHANGELOG entry on main before starting a run: PyPI refuses to
12+
# replace a version it already has.
13+
14+
name: Publish to PyPI
15+
16+
on:
17+
workflow_dispatch:
18+
inputs:
19+
confirm:
20+
description: 'Type "publish" to publish to PyPI'
21+
required: true
22+
type: string
23+
24+
permissions:
25+
contents: read
26+
27+
jobs:
28+
build:
29+
name: Test and build
30+
if: ${{ vars.PYPI_PUBLISH_ENABLED == 'true' && inputs.confirm == 'publish' }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-python@v5
35+
with:
36+
python-version: "3.13"
37+
- name: Test
38+
run: |
39+
python -m pip install -e ".[dev]"
40+
pytest -q
41+
- name: Build
42+
run: |
43+
python -m pip install build twine
44+
python -m build
45+
twine check dist/*
46+
- uses: actions/upload-artifact@v4
47+
with:
48+
name: dist
49+
path: dist/
50+
if-no-files-found: error
51+
52+
publish:
53+
name: Publish
54+
needs: build
55+
runs-on: ubuntu-latest
56+
environment:
57+
name: pypi
58+
url: https://pypi.org/project/cleanedweb/
59+
permissions:
60+
id-token: write
61+
steps:
62+
- uses: actions/download-artifact@v4
63+
with:
64+
name: dist
65+
path: dist/
66+
- uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)