Repository navigation
🐛 FIX: Build releases with python -m build, on every PR - #164
Merged
Merged
Conversation
Add a `build` job that runs `python -m build` and `twine check --strict`, checks on a tag push that the tag matches the built version, and uploads the distributions as the `dist` artifact. `allgood` now needs it, so a broken build is caught before a tag. The workflow also gets a read-only default `permissions:` block.
`pip install flit~=3.4` now resolves flit 3.12.0 with flit_core 4.2.0, and `flit build` then crashes with `TypeError: SdistBuilder.build() got an unexpected keyword argument 'gen_setup_py'`, so the next tag would fail before uploading anything. The `publish` job now downloads the `dist` artifact from the `build` job and uploads it with trusted publishing. It needs `pre-commit`, `tests` and `build`, runs only for `v*` tag pushes, and its only permission is `id-token: write`.
The tag check compared a set of versions, so a dist/ holding only a wheel or only an sdist would still pass.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #164 +/- ##
==========================================
+ Coverage 92.80% 92.90% +0.10%
==========================================
Files 31 40 +9
Lines 1835 2284 +449
==========================================
+ Hits 1703 2122 +419
- Misses 132 162 +30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The release build is broken: the next
v*tag would fail before anything reaches PyPI.The
publishjob runspip install flit~=3.4and thenflit build.That now resolves flit 3.12.0 with flit_core 4.2.0 (flit 3.12 requires
flit_core>=3.12.0with no upper bound),and
flit buildcrashes:This PR changes
.github/workflows/tests.yml, keeping its file name, which the PyPI trusted publisher names:buildjob, run on every push and PR.It runs
python -m build, which builds with the project's own[build-system]pin (flit_core >=3.4,<4),so the release build can no longer drift from it.
Then
twine check --strict dist/*.On a tag push it also checks that
dist/holds exactly one wheel and one sdist, and that the tag matches their version.It uploads
dist/as an artifact, andallgoodnow needs it, so a broken build shows up on PRs instead of at release time.publishpublishes that artifact.It downloads it and uploads it with
pypa/gh-action-pypi-publish(trusted publishing; attestations are on by default).It needs
pre-commit,testsandbuild, runs only forv*tag pushes, uses thepypienvironment,and its only permission is
id-token: write.(Its job-level
ifused to match any tag, but the trigger already limited tag runs tov*, so that does not change.)permissions: contents: read.How it was tested
pip install "flit~=3.4"installed flit 3.12.0 + flit_core 4.2.0, andflit buildexited 1 with theTypeErrorabove.python -m buildexited 0 and builtmdit_py_plugins-0.7.0.tar.gzandmdit_py_plugins-0.7.0-py3-none-any.whl.twine check --strict dist/*passed for both.v0.7.0: exit 0;v0.7.1andv0.7: exit 1, withtag v0.7.1 != built version(s) ['0.7.0'];dist/with only the wheel, only the sdist, or nothing: exit 1, withexpected one wheel and one sdist, got 1 and 0(and so on).actionlintreports nothing new.It still reports one finding on master, which this PR does not touch: SC2102 on
pip install -e .[testing]intests.pre-commit run --all-filespasses.pytest: 511 passed (Python 3.13). No package code changed.Distribution contents compared with PyPI 0.6.1
mdit_py_plugins/section_ref/(✨ NEW: Add section reference plugin (section_ref) #144).METADATAis identical apart fromVersion, andWHEELnames the same generator, currently flit 3.12.0(the release build gets whichever
flit_corethe>=3.4,<4range resolves to when the tag is pushed).section_refmodules..coveragerc,.github/dependabot.yml,.github/workflows/copilot-setup-steps.yml,.github/workflows/tests.yml,.gitignore,.pre-commit-config.yaml,.readthedocs.yml,AGENTS.md,CHANGELOG.md,codecov.ymlandtox.ini.The flit CLI added these from version control; the PEP 517 backend does not.
LICENSE,README.md,pyproject.tomlandPKG-INFO.tests/anddocs/were already excluded by[tool.flit.sdist]and still are.LICENSE(license_file).Notes for the reviewer
pushtriggers only onmasterand tags, so thebuildjob first runs when this PR is opened.publishjob itself first runs on thev0.7.0tag.That tag push is also the first upload through trusted publishing (0.6.1 was uploaded with the token).
checkout@v7,setup-python@v7,upload-artifact@v7,download-artifact@v8).The existing jobs still use
checkout@v4/setup-python@v5; they are bumped separately.pypienvironment;build/twineand SHA-pinning the actions (the repo pins neither today);tests/andtox.iniin the sdist, which needs apyproject.tomlchange.