Skip to content

Commit aa751cd

Browse files
Carreauclaude
andcommitted
Harden the release workflow
- Only version-like tags (e.g. 1.2.0, 1.2.0rc1) trigger the workflow on tag push, so a stray tag no longer publishes to PyPI. - New build job: fails on a tag that does not match __version__, builds the sdist and wheel, runs the test suite against the installed wheel (not the source tree), and uploads dist/ as an artifact. It runs on every push and PR, so packaging breakage shows up before a release. - The publish job now only downloads the artifact and uploads it, so the build no longer runs with id-token: write. - Publish runs in a "pypi" GitHub environment, so it can be gated by required reviewers or tag rules. PyPI's trusted publisher for this project has no environment configured, so it accepts this as is. The workflow file name (test.yml) is unchanged on purpose: the trusted publisher is bound to it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 7fbfe50 commit aa751cd

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: Tests
33
on:
44
push:
55
branches: [ main ]
6-
tags: [ '*' ]
6+
# Only version tags (e.g. 1.2.0, 1.2.0rc1) trigger a release.
7+
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ]
78
pull_request:
89
branches: [ main ]
910
workflow_dispatch:
@@ -79,13 +80,8 @@ jobs:
7980
run: |
8081
python3 -m pytest -v
8182
82-
publish:
83+
build:
8384
runs-on: ubuntu-latest
84-
if: ${{ startsWith(github.ref, 'refs/tags/') }}
85-
needs: [lint, tests]
86-
permissions:
87-
id-token: write # OIDC for uploading to PyPI
88-
8985
steps:
9086
- name: Checkout
9187
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -95,12 +91,52 @@ jobs:
9591
- name: Set up Python
9692
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
9793
with:
98-
python-version: "3.11"
94+
python-version: "3.x"
95+
96+
- name: Check tag matches __version__
97+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
98+
run: |
99+
version=$(python3 -c 'import re, pathlib; print(re.search(r"^__version__ = \"(.+)\"", pathlib.Path("ipython_pygments_lexers/__init__.py").read_text(), re.M).group(1))')
100+
if [ "${GITHUB_REF_NAME}" != "${version}" ]; then
101+
echo "::error::Tag ${GITHUB_REF_NAME} does not match __version__ ${version}"
102+
exit 1
103+
fi
99104
100105
- name: Build packages
101106
run: |
107+
python3 -m pip install --upgrade pip
102108
python3 -m pip install build
103109
python3 -m build
104110
111+
- name: Test the built wheel
112+
run: |
113+
python3 -m pip install dist/*.whl --group test
114+
cd "${RUNNER_TEMP}"
115+
python3 -m pytest --import-mode=importlib "${GITHUB_WORKSPACE}/test_ipython_pygments_lexers.py"
116+
117+
- name: Upload packages
118+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
119+
with:
120+
name: dist
121+
path: dist/
122+
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+
105141
- name: Publish package distributions to PyPI
106142
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3

0 commit comments

Comments
 (0)