Repository navigation
Version fractional-indexing from git tags instead of committing a bump - #4
Conversation
The org ruleset now rejects unsigned commits on `main`, so the release workflow can no longer push its `chore: bump version` commit. The version now comes from the `v*` tags through hatch-vcs, matched strictly so the legacy `0.1.x` tags and the upstream fork's tags never count. The release works out the next version from the latest tag, builds with it, and tags the released commit, so nothing is committed. `__version__` reads the installed metadata, which also fixes it still saying 1.0.0.
`ubuntu-latest` now resolves to Ubuntu 26.04, and `actions/setup-python` has no Python 3.8 or 3.9 builds for it, so those two jobs fail before any test runs. The package still supports 3.8, so the tests stay on 24.04 until the 3.8 and 3.9 support is dropped on purpose.
doistbot
left a comment
There was a problem hiding this comment.
This PR moves fractional-indexing's versioning from a committed bump to deriving it from vX.Y.Z git tags via hatch-vcs, reworks the release workflow with tag-based guards and build-time version checks, and switches __version__ to package metadata with a 0.0.0 fallback.
Few things worth tightening:
- CI never exercises the installed
__version__path —test.ymlonly runs pytest uninstalled, so every run tests the0.0.0fallback. Adding apip install .step in one matrix job and asserting__version__ != '0.0.0'would catch any drift between the hardcoded package name infractional_indexing.pyand the published name, which the release workflow's wheelVersion:grep wouldn't catch.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (3)
.github/workflows/release.yml:89: This remote check only verifies the computed
v$NEXT_VERSION; it doesn't ensure the localLATEST_TAGused to compute that version is still the newest release tag on the remote. If a newer tag (sayv1.2.0) is pushed after checkout,LATEST_TAGstaysv1.1.0, this run computesv1.1.1, andls-remoteforv1.1.1passes even though the run would publish an older version than the remote's latest. DeriveLATEST_TAGfromgit ls-remote --tags origin(filtered andsort -V) instead of the local clone, or additionally check that no remotevX.Y.Ztag is newer than$LATEST_TAG..github/workflows/release.yml:56: The
RELEASE_TAGregex re-declares the "only vX.Y.Z tags are releases" rule that[tool.hatch.version]already owns in pyproject.toml (tag-patternanddescribe_command). The two copies already disagree: this regex rejects leading zeros, while pyproject's\d+pattern acceptsv01.2.3. Keep one source of truth, or at least make both patterns identical, so a future tag can't be treated as a release by one and ignored by the other..github/workflows/release.yml:89:
git ls-remote --exit-codeexits 2 when the tag is absent, but any other non-zero exit (network failure, auth error) lands on the sameifand is treated as "tag doesn't exist", silently skipping the guard and publishing anyway. Only exit code 2 means "safe to proceed":bash if git ls-remote --exit-code --tags origin "refs/tags/v$NEXT_VERSION" > /dev/null; then echo "::error::Tag v$NEXT_VERSION already exists." exit 1 elif [ $? -ne 2 ]; then echo "::error::Could not check remote tags." exit 1 fiOtherwise a transient failure re-publishes the same version to CodeArtifact before the later tag-creation step fails.
doistbot
left a comment
There was a problem hiding this comment.
This PR moves fractional-indexing's versioning from a committed bump to deriving it from vX.Y.Z git tags via hatch-vcs, reworks the release workflow with tag-based guards and build-time version checks, and switches __version__ to package metadata with a 0.0.0 fallback.
Few things worth tightening:
- CI never exercises the installed
__version__path —test.ymlonly runs pytest uninstalled, so every run tests the0.0.0fallback. Adding apip install .step in one matrix job and asserting__version__ != '0.0.0'would catch any drift between the hardcoded package name infractional_indexing.pyand the published name, which the release workflow's wheelVersion:grep wouldn't catch.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (3)
.github/workflows/release.yml:89: This remote check only verifies the computed
v$NEXT_VERSION; it doesn't ensure the localLATEST_TAGused to compute that version is still the newest release tag on the remote. If a newer tag (sayv1.2.0) is pushed after checkout,LATEST_TAGstaysv1.1.0, this run computesv1.1.1, andls-remoteforv1.1.1passes even though the run would publish an older version than the remote's latest. DeriveLATEST_TAGfromgit ls-remote --tags origin(filtered andsort -V) instead of the local clone, or additionally check that no remotevX.Y.Ztag is newer than$LATEST_TAG..github/workflows/release.yml:56: The
RELEASE_TAGregex re-declares the "only vX.Y.Z tags are releases" rule that[tool.hatch.version]already owns in pyproject.toml (tag-patternanddescribe_command). The two copies already disagree: this regex rejects leading zeros, while pyproject's\d+pattern acceptsv01.2.3. Keep one source of truth, or at least make both patterns identical, so a future tag can't be treated as a release by one and ignored by the other..github/workflows/release.yml:89:
git ls-remote --exit-codeexits 2 when the tag is absent, but any other non-zero exit (network failure, auth error) lands on the sameifand is treated as "tag doesn't exist", silently skipping the guard and publishing anyway. Only exit code 2 means "safe to proceed":bash if git ls-remote --exit-code --tags origin "refs/tags/v$NEXT_VERSION" > /dev/null; then echo "::error::Tag v$NEXT_VERSION already exists." exit 1 elif [ $? -ne 2 ]; then echo "::error::Could not check remote tags." exit 1 fiOtherwise a transient failure re-publishes the same version to CodeArtifact before the later tag-creation step fails.
The release job asks the remote whether the next tag already exists, but `git ls-remote --exit-code` exits 2 for a missing tag and 128 when the lookup itself fails, and both counted as "missing". A network or auth failure skipped the check silently. Only exit 2 lets the release continue now. The tests run without the package installed, so `__version__` always took the 0.0.0 fallback, and a mismatch between the name it looks up and the published name would reach users unnoticed. CI installs the package and fails if the version still falls back. The hatch-vcs `tag-pattern` uses release.yml's pattern, so both agree on which tags are releases.
|
ec136b0 also applies the |
amleczko
left a comment
There was a problem hiding this comment.
LGTM. The two rulesets on this repo target branches only, so tag creation after the publish is not blocked.
Overview
The next release of fractional-indexing will fail whenever someone bumps the version. The release workflow pushes a version-bump commit, and the org ruleset has rejected unsigned commits on
mainsince 23 Oct. Both releases so far, v1.0.0 and v1.1.0, ran before the ruleset.The version now lives only in the
vX.Y.Zgit tags, read by hatch-vcs, so nothing commits tomain. This is path A from the signed-commits rollout, as in Doist/todoist-id-python#79.Changes
bumpinput is nowpatch,minorormajor, and the workflow works out the next version from the latest tag.noneoption is gone. "Release the version in pyproject.toml" no longer means anything.main, to create a tag that already exists, to release a commit that already has a release tag, or to release code older than the latest tag.Version:before it publishes.github.sha). It still runs after the publish, so a failed publish leaves no tag behind.vX.Y.Ztags count. The legacy0.1.xtags and the httpie upstream's tags (such as4.0.0) never set the version.__version__now reads the installed package metadata, which also fixes it saying 1.0.0. It falls back to0.0.0when the package isn't installed, as intest.yml.uv.lockdrops the package's own version line. A newer uv also moved itsrevisionfrom 3 to 5.ubuntu-24.04.ubuntu-latestis now 26.04, which has nosetup-pythonbuilds for 3.8 or 3.9 (failed run).Note
mainis still atv1.1.0. The first release after merge should be 1.1.1, containing only this PR.Testing
v1.1.0commit, a run on the olderv1.0.0commit, and a tag that already exists on the remote.4.0.0and0.1.9tags on HEAD, the build version still comes fromv1.1.0.SETUPTOOLS_SCM_PRETEND_VERSION=1.1.1 uv buildgives a wheel withVersion: 1.1.1, and__version__is1.1.1once installed.test.ymlsetup, without it.actionlintpasses. The first real run is the next manual release.References