Skip to content

Make pre-release versions sort after the release they follow - #6

Merged
dwd merged 3 commits into
dwd:mainfrom
Fishbowler:prerelease-semver-ordering
Nov 20, 2026
Merged

dwd merged 3 commits into
dwd:mainfrom
Fishbowler:prerelease-semver-ordering

Conversation

@Fishbowler

Copy link
Copy Markdown
Contributor

Builds on #5 (which builds on #4). Until those merge, this PR also shows their commits. Only the last commit (44cd987) is new here.

This changes the version scheme, so I've kept it separate from the bug fixes in #5. It can be accepted or declined on its own.

Problem

After #5, a build made after v0.0.6 is labelled 0.0.6-pre-<sha>. Under semver a pre-release sorts before its release, so:

  • Release order is backwards. Sentry's release ordering, pub, and any "is there an update?" check treat a build made after 0.0.6 as older than 0.0.6.
  • Two pre-releases sort by commit hash, which is effectively random. 0.0.6-pre-f00d123 ranks above a later 0.0.6-pre-0abc456.
  • The .deb has the same problem under dpkg's rules, because it uses the same string.

Change

Pre-releases are labelled as a pre-release of the next version:

Last release tag Pre-release version
v0.0.6 (final) 0.0.7-pre.<build>.g<sha>
v2.0.0-rc.1 (unreleased rc) 2.0.0-rc.1.pre.<build>.g<sha>
  • The patch bump puts a build after 0.0.6 between 0.0.6 and 0.0.7.
  • Extending an unreleased rc keeps the build between that rc and the next rc or the final release, rather than skipping past them.
  • The build number is a numeric part of the version, so pre-releases of the same version sort by build rather than by hash. The g prefix stops an all-digit hash from becoming an invalid number with a leading zero.

build_version.sh also outputs WIMSY_DEB_VERSION. That's the version with its pre-release separator (only the first -) as ~, which dpkg sorts before the release: 0.0.7~pre.412.g… < 0.0.7. The .deb uses it for its Version field. Its file name keeps the plain version, since ~ in release asset names is best avoided.

Unchanged from #5:

  • Apple builds show 0.0.7 (<build>). The build number only ever increases, so it orders them before the final 0.0.7.
  • MSIX keeps <last final release>.<build> (e.g. 0.0.6.412). MSIX has no separate build field, so it can't use the next version without outranking the coming release.

Testing

  • tool/test_build_version.sh now has 103 checks. It has updated expectations wherever a pre-release is produced, plus new checks: .deb versions (including a hyphenated rc, 1.2.3-rc-2 → 1.2.3~rc-2), and the patch bump carrying past 9 (1.4.9 → 1.4.10).

  • Ordering is checked, not just asserted. A small semver comparator in the test file is itself tested against the semver spec's precedence example. It's then used on real script output, whatever the hashes:

    • 0.0.6 < build 12 < build 13 < 0.0.7
    • all-digit hashes
    • rc1 < post-rc build < rc2 < final
    • dotted rc.9 < post-rc.9 build < rc.10 < final

    The same .deb sequences are also checked with dpkg --compare-versions on the Linux runner.

  • Mutation checks: removing the patch bump, or replacing every - with ~, makes the corresponding tests fail.

  • CI on my fork, run 44504221328: all green, including maestro-e2e. The Android build hit a Gradle Plugin Portal outage once and passed on re-run. Stamped values from that run:

    • WIMSY_VERSION=0.0.7-pre.8.g44cd987
    • WIMSY_DEB_VERSION=0.0.7~pre.8.g44cd987
    • WIMSY_MSIX_VERSION=0.0.6.8
    • From a previous fork run of this branch: macOS DMG check ok: bundle version 0.0.7 and ok: bundle build number 7, and the .deb built as wimsy_0.0.7-pre.7.g00b2534_amd64.deb.
  • flutter analyze, flutter test and vendor/xmpp_stone dart test all pass. The app code is unchanged.

🤖 Generated with Claude Code

Fishbowler and others added 3 commits November 19, 2026 17:03
… versions

Seven jobs carried identical copies of a "Set Build Version" step that
wrote `version: <tag>` or `version: <last tag>-pre-<sha>` into
pubspec.yaml with no build number. That caused several problems:

- Pre-release builds were all labelled 0.0.0-pre-<sha>. CI checkouts
  are depth-1 clones. `git fetch --tags` downloads the full history
  behind every tag, but HEAD's own history stays cut off at depth 1,
  so `git describe` never reached a tag and fell back to 0.0.0.
- iOS/macOS: Flutter strips every non-digit/non-dot from the build
  name on Apple platforms, so 0.0.6-pre-d217e1d became
  CFBundleShortVersionString 0.0.62171 (0.0.02171 as actually built).
  With no build number, CFBundleVersion fell back to the same value.
- Android: versionCode was always 1.
- Windows MSIX: msix_config.msix_version was never updated, so every
  MSIX claimed to be 0.0.2.0.
- Sentry derives its release from the package version, so Apple
  pre-release builds reported nonsense releases.
- deploy-web, the build served on GitHub Pages, never had a version
  step at all, so it reported the committed placeholder 0.0.2.
- `sed -i -E` on the macOS (BSD sed) runners treats -E as a backup
  suffix, leaving a stray pubspec.yaml-E behind.

Replace them with two CI-provider-neutral scripts, following the
pattern of tool/build_web.sh (inputs as arguments, provider specifics
kept out), wired up once in a local composite action. They share
tool/release_tags.sh, so they agree on what a release tag is (v plus
a full semver 2.0.0 version; final means no -pre-release part, even
if build metadata contains a hyphen) and on when HEAD's history is
cut off.

tool/fetch_release_history.sh fetches what the version needs and no
more. It lists the remote's release tags and their commits with
ls-remote (annotated tags peeled); while HEAD's history is cut off,
deepens HEAD by commit id in steps until it contains a final
release's commit (so a detached PR merge commit works); then fetches
just the tags whose commits are in that history, including in a full
clone made without tags. Completeness is judged by whether any commit
in HEAD's history is a shallow boundary, not whether the repository
is shallow (another ref's shallow tip would otherwise keep it
looping), and a deepen that makes no progress is an error. On this
repo it fetches 21 of 776 commits and one tag, where the old
`fetch --tags` pulled the full history for nothing.

tool/build_version.sh works out the version and prints KEY=VALUE
lines (WIMSY_VERSION, WIMSY_VERSION_CORE, WIMSY_BUILD_NUMBER,
WIMSY_MSIX_VERSION). It takes --tag and --build-number, modifies
nothing by default (safe to run locally to see what version a build
would get), and only with --write-pubspec rewrites the pubspec's
version and msix_version lines, so every tool that reads the pubspec
picks the version up without extra flags. It keeps the existing
scheme (release X.Y.Z, pre-release <base>-pre-<sha>) and adds:

- `version: <display>+<build number>`, giving every platform a
  build number that increases with each CI run;
- a pre-release base that is the nearest release tag unless the
  highest final release in HEAD's history is at least as high (an
  older release merged back in, or an rc whose final release exists),
  so the base never names an older version than HEAD contains;
- msix_version X.Y.Z.0 for final releases and
  <highest final release>.<build> for pre-release *and* -rc tag
  builds, so rc -> later builds -> final release are all upgrades
  (errors past the 16-bit MSIX limit);
- full semver validation of tags (malformed ones such as v1.2.3- or
  v1.08.3 fail up front instead of in pub), rejection of release tags
  carrying +build metadata, and dropping of build metadata from base
  tags;
- a clear failure when HEAD's history is shallow and no final
  release is reachable, rather than silently guessing 0.0.0;
- awk-based rewriting that behaves the same on all runners,
  preserves msix_version's indentation, keeps a CRLF file CRLF, and
  leaves the file untouched on any error. The line ending is detected
  from the raw bytes with od: Git for Windows' awk drops the CR of a
  CRLF line as it reads it, so it cannot tell the two apart itself,
  and on the Windows runner it turned the whole file into LF.

.github/actions/build-version runs both scripts, passing the tag
(only for v* tag refs) and github.run_number through env vars (so a
tag name cannot inject shell) and teeing the output into $GITHUB_ENV.
All eight jobs that build use it in one step, now including
deploy-web. The macOS and iOS builds pass --build-name
"$WIMSY_VERSION_CORE", so the bundle gets e.g. 0.0.6 (412) in place of
0.0.62171; the build number still comes from the pubspec. The .deb
reads $WIMSY_VERSION, so its version is exactly as before (no
+build). A new test-ci-scripts job runs the script tests on Linux,
macOS and Windows in parallel with the builds, and publish-release
waits for it.

The macOS DMG verification now checks the version on every build,
not just tags. tool/verify_macos_dmg.sh gains an optional expected
CFBundleVersion argument, which CI passes, and reports a missing
Info.plist key as a failed check instead of aborting under set -e.

Known limitations, documented in build_version.sh: Apple platforms
only take numeric versions, so a pre-release or -rc build shares its
release's short version there (the build number differs). The run
counter is shared by all branches, so it orders builds by when they
ran, and restarts if the workflow file is renamed. Undotted rc
numbers (rc10 vs rc9) sort lexically; tags should use rc.N. Ordering
of pre-release display versions is unchanged here (see the
follow-up).

Testing:
- New tool/test_build_version.sh (76 checks, run under LC_ALL=C) in
  the new test-ci-scripts job on all three runner types. It uses
  throwaway git repos and covers: no tags; nothing written (and a
  clean tree) without --write-pubspec; a pre-release after tags;
  release, v-less and -rc tags (rc MSIX after the last final release,
  and its 65535 limit); MSIX values for releases (including build
  70000) and pre-releases after an rc; an older release merged back
  in nearer to HEAD (with dated commits so git describe really picks
  it); an rc superseded by its final release on the same commit
  (dated so describe picks the rc); a repo whose only tag is an rc; a
  non-semver v tag being ignored; build metadata on a base tag;
  indentation, CRLF (compared as raw bytes via od, since text tools
  on Windows can translate CRLF as they read) and --pubspec; and, on
  clones of a tagged origin
  with an annotated tag: build_version failing with guidance before
  history is fetched, a release build needing no history, the fetch
  reaching the last tag with only that history (31 of 86 commits), a
  detached HEAD, a remote with no tags, an orphan branch on a tagged
  remote (terminates with HEAD's full history, fetches no tags), and
  a full clone without tags (tags fetched). Failure cases (build
  number 0 or non-numeric, non-numeric tag, leading zeros, empty
  pre-release, a space, +build tag, pre-release build number over
  65535, unknown argument, missing option value, missing msix_version
  line) each exit non-zero with the pubspec unchanged.
- Mutation checks: removing the higher-base rule, the rc MSIX rule,
  the tag fetch for complete histories, the HEAD-history termination
  test, or the od line-ending detection (which reproduces the Windows
  awk behaviour on macOS) each makes the corresponding tests fail.
- CI on a fork: the byte-level CRLF check failed on the Windows
  runner before the od detection was added (every 0d0a written as
  0a), and passed on Linux and macOS.
- Simulated the CI steps on a depth-1 clone of this repo: version
  0.0.6-pre-<sha>, MSIX 0.0.6.412, 21 of 776 commits fetched.
- Confirmed in flutter_tools (ios/xcode_build_settings.dart) that
  --build-name alone still takes the build number from the pubspec.
- verify_macos_dmg.sh: passes with the v0.0.6 DMG's real build
  number; fails with a wrong one; with CFBundleVersion deleted it
  reports the failure and still runs the other checks.
- Reviewed three times with /code-review; findings fixed or
  documented as limitations above.
- shellcheck clean on all tool/*.sh; workflow and action YAML parse.
- flutter analyze: no issues. flutter test: all 1044 passed.
  vendor/xmpp_stone dart test: all 190 passed.
- Maestro flows not run locally (they need Openfire in Docker and an
  emulator, and would not exercise CI version stamping); the CI
  maestro-e2e job runs them against a CI-stamped build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pull request run on dwd/Wimsy (PR dwd#5) failed in every job with
"deepening HEAD fetched no new commits; giving up". The run was created
at 12:08 but only started at 16:10, after main had moved. By then GitHub
had replaced the PR's merge commit (102d7d3 became f2558fd), so no ref
pointed to the commit the run checked out. GitHub still serves such a
commit by id, which is why actions/checkout's --depth=1 fetch worked,
but `git fetch --deepen=N` on it returns nothing.

GitHub does serve it at an absolute depth, so fetch_release_history.sh
now asks for --depth=<current + step> each time round the loop. The
starting depth is HEAD's commit count, which is at least the clone's
depth; asking for less than a clone already has would cut its history
back rather than extend it. The no-progress error now names the commit
and remote.

Testing:
- Reproduced against GitHub with a depth-1 checkout of 102d7d3, as the
  run made: the old script fails with the same error; the new one
  fetches 24 commits, finds v0.0.6 and stamps 0.0.6-pre-102d7d3.
  Fetching the merge commit's parents instead was tried and rejected:
  the commit stays marked shallow, so git does not follow them.
- tool/test_build_version.sh: 80 checks pass (76 before). New cases:
  - a merge commit that no ref points to, fetched by id from a remote
    with uploadpack.allowAnySHA1InWant. Local git still deepens such a
    commit, so this passes on the old code too and cannot catch the
    GitHub behaviour; it checks the fetch works on that kind of commit.
  - a depth-15 clone, checking a deeper starting clone still works.
- shellcheck -x clean on both scripts.
- flutter analyze, flutter test, vendored dart tests and Maestro not run
  locally: no Dart code changed; CI covers them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pre-release builds were labelled <base>-pre-<sha>, e.g.
0.0.6-pre-d217e1d for a build made after v0.0.6. Under semver a
pre-release sorts *before* its release, so every semver consumer
(Sentry's release ordering, pub, update checks) ranked these builds
below the release they were built on top of. Between two pre-releases
the order was decided by comparing commit hashes, i.e. at random. The
.deb, using the same string, had the same problem under dpkg's rules.

Label pre-releases as a pre-release of the *next* version instead:

  after a final vX.Y.Z:        X.Y.(Z+1)-pre.<build number>.g<short sha>
  after an unreleased rc:      X.Y.Z-rc.1.pre.<build number>.g<short sha>

- The patch bump makes a build after v0.0.6 (0.0.7-pre...) sort after
  0.0.6 and before 0.0.7.
- After an unreleased rc tag, extending the rc keeps the build between
  that rc and the next rc or the final release, rather than skipping
  past them. (Which tag counts as the base is unchanged: the previous
  commit already prefers the highest final release over an older or
  superseded nearest tag.)
- The numeric build-number identifier orders pre-releases of the same
  version by build, not by hash. The "g" prefix stops an all-digit
  hash becoming an invalid numeric identifier with a leading zero.

build_version.sh now also outputs WIMSY_DEB_VERSION: the display
version with its pre-release separator (only the first -, so hyphens
inside identifiers such as rc-2 are kept) as ~, which dpkg sorts
before the release (0.0.7~pre.412.g... < 0.0.7). The .deb uses it for
its Version field; its file name keeps the plain display version,
since ~ in release asset names is best avoided. The composite action's
description and a stale workflow comment are updated.

Unchanged: WIMSY_VERSION_CORE follows the display version (0.0.7 for
the example), so Apple builds show 0.0.7 (<build>), and the build
number, which only increases, orders them before the final 0.0.7.
MSIX has no separate build field, so it keeps
<last final release>.<build> from the previous commit, which already
orders correctly.

This is a behaviour change to the version scheme, kept separate from
the build-number and packaging fixes so it can be accepted or dropped
on its own.

Testing:
- tool/test_build_version.sh grows to 107 checks. Updated
  expectations wherever a pre-release is produced (no tags, after
  tags, after an rc, merge-back, superseded rc, only an rc tag,
  non-semver tag, base tag with build metadata, shallow, depth-15,
  detached, unreferenced merge commit,
  orphan and tagless full clones), plus new checks: deb versions for
  pre-release and rc tags, including a hyphenated rc (1.2.3-rc-2 ->
  1.2.3~rc-2); the patch bump carrying past 9 (1.4.9 -> 1.4.10).
- Ordering is checked, not just asserted: a small semver 2.0.0
  precedence comparator in the test file is itself tested against
  the spec's precedence example, then used to check 0.0.6 < build 12
  < build 13 < 0.0.7 on real script output (whatever the hashes),
  all-digit hashes, rc1 < post-rc build < rc2 < final, and dotted
  rc.9 < post-rc.9 build < rc.10 < final. The deb sequences are also
  checked with `dpkg --compare-versions` where dpkg is installed (the
  Linux CI runner; skipped on macOS).
- Mutation checks: removing the patch bump fails the ordering and
  expectation checks; replacing every - with ~ fails the hyphenated
  rc check.
- Reviewed with /code-review; findings fixed here or in the previous
  commit, or documented.
- shellcheck clean; workflow and action YAML parse.
- flutter analyze: no issues. flutter test: all 1044 passed.
  vendor/xmpp_stone dart test: all 190 passed.
- Maestro flows not run locally; the CI maestro-e2e job runs them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Fishbowler
Fishbowler force-pushed the prerelease-semver-ordering branch from 44cd987 to 2b29c29 Compare November 19, 2026 17:04
@dwd
dwd merged commit 62e333f into dwd:main Nov 20, 2026
21 checks passed
dwd pushed a commit that referenced this pull request Nov 20, 2026
build-android had no Gradle cache (the Flutter action caches the
Flutter SDK, not ~/.gradle), so every run downloaded all of Gradle's
dependencies, including the plugins for Flutter's own Gradle plugin
loader. That is slow, and makes the job fail whenever those
repositories hiccup: a fork run failed with the Gradle Plugin Portal
answering "Could not find org.jetbrains.kotlin:kotlin-stdlib:2.2.21"
for an artifact that exists, and passed on re-run. Gradle's own
download retries don't help there, as a not-found response is treated
as definite.

Add gradle/actions/setup-gradle@v6 to build-android, before the first
Gradle build. Its init scripts apply to every Gradle run in the job,
including those started by `flutter build apk`, and it caches the
Gradle User Home (dependencies, wrapper distributions, generated jars)
between runs. Only default-branch runs write the cache; branch and
pull-request runs restore it. build-android is the only job that runs
Gradle; maestro-e2e uses the APK it uploads.

It uses the default (enhanced) cache provider: proprietary, under the
Gradle Technologies Terms of Use, free for public repositories, with
restore-key matching and cleanup. `cache-provider: basic` is the
MIT-licensed alternative.

No retry around the build step: with a warm cache the repositories are
rarely contacted, and a retry would mostly delay genuine failures.

Testing:
- Workflow YAML parses; the step is in build-android immediately
  before "Build Android (release)".
- Merges cleanly with the version-fixes and prerelease ordering
  branches (#5, #6).
- flutter analyze: no issues. flutter test: all 1044 passed.
  vendor/xmpp_stone dart test: all 190 passed.
- Maestro flows not run locally: CI-only change; the CI maestro-e2e
  job covers them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants