Skip to content

Commit 7c43517

Browse files
Carreauclaude
andcommitted
Move PyPI publishing to its own tag-only workflow
PyPI trusted publishing trusts a workflow by file name. test.yml also runs on pull requests, branch pushes and manual dispatch, and is the file contributors and Dependabot edit most, so publishing now lives in publish.yml, which only runs for version tags. publish.yml calls test.yml as a reusable workflow (lint, tests, the tag/__version__ check, building and testing the wheel), then uploads that same build from its own top-level job in the "pypi" environment. The upload has to stay in the top-level workflow: PyPI does not accept trusted-publishing uploads from inside a called workflow. test.yml gains a workflow_call trigger and loses its tag trigger and publish job. PyPI action needed after merge: add a GitHub trusted publisher with workflow publish.yml and environment pypi, then remove the old test.yml publisher. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent aa751cd commit 7c43517

2 files changed

Lines changed: 43 additions & 22 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish
2+
3+
# Releases are published only from this workflow, and only for version tags
4+
# (e.g. 1.2.0, 1.2.0rc1). The PyPI trusted publisher is bound to this file
5+
# name and to the "pypi" environment: do not rename it.
6+
on:
7+
push:
8+
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ]
9+
10+
permissions: {}
11+
12+
jobs:
13+
# Lint, tests, the tag/__version__ check and the build, from test.yml.
14+
ci:
15+
# A job-level call resolves from this commit, not the runner's files, so
16+
# the newer "$/" self-repository syntax buys nothing here.
17+
uses: ./.github/workflows/test.yml # zizmor: ignore[self-repository]
18+
permissions:
19+
contents: read
20+
21+
publish:
22+
name: Publish to PyPI
23+
# Must stay a job of this workflow: PyPI trusted publishing does not
24+
# accept uploads from inside a reusable (called) workflow.
25+
needs: ci
26+
runs-on: ubuntu-latest
27+
environment:
28+
name: pypi
29+
url: https://pypi.org/project/ipython-pygments-lexers/
30+
permissions:
31+
id-token: write # OIDC for uploading to PyPI
32+
33+
steps:
34+
- name: Download packages
35+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
36+
with:
37+
name: dist
38+
path: dist/
39+
40+
- name: Publish package distributions to PyPI
41+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Tests
33
on:
44
push:
55
branches: [ main ]
6-
# Only version tags (e.g. 1.2.0, 1.2.0rc1) trigger a release.
7-
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ]
86
pull_request:
97
branches: [ main ]
108
workflow_dispatch:
9+
# Called by publish.yml so a release runs the same checks and build.
10+
workflow_call:
1111

1212
permissions:
1313
contents: read
@@ -120,23 +120,3 @@ jobs:
120120
name: dist
121121
path: dist/
122122
if-no-files-found: error
123-
124-
publish:
125-
runs-on: ubuntu-latest
126-
if: ${{ startsWith(github.ref, 'refs/tags/') }}
127-
needs: [lint, tests, build]
128-
environment:
129-
name: pypi
130-
url: https://pypi.org/project/ipython-pygments-lexers/
131-
permissions:
132-
id-token: write # OIDC for uploading to PyPI
133-
134-
steps:
135-
- name: Download packages
136-
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
137-
with:
138-
name: dist
139-
path: dist/
140-
141-
- name: Publish package distributions to PyPI
142-
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3

0 commit comments

Comments
 (0)