Skip to content

Fix CI build versioning: real pre-release versions, build numbers, Apple and MSIX versions - #5

Merged
dwd merged 2 commits into
dwd:mainfrom
Fishbowler:version-fixes
Nov 20, 2026
Merged

dwd merged 2 commits into
dwd:mainfrom
Fishbowler:version-fixes

Conversation

@Fishbowler

Copy link
Copy Markdown
Contributor

Builds on #4. Until #4 merges, this PR also shows its two DMG commits. Only the last commit (fff062a) is new here.

Problem

The workflow had seven identical copies of a "Set Build Version" step. Between them they produced the following wrong or missing versions:

  • Every pre-release build was labelled 0.0.0-pre-<sha>. CI uses 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 reaches a tag and falls back to 0.0.0.
  • iOS/macOS versions were mangled. On Apple platforms Flutter strips everything except digits and dots, so 0.0.6-pre-d217e1d became CFBundleShortVersionString 0.0.62171. There was no build number, so CFBundleVersion repeated the same value.
  • Android versionCode was always 1.
  • Every Windows MSIX claimed to be 0.0.2.0. msix_version in the pubspec was never updated.
  • Sentry reported nonsense release names for Apple builds, because it takes the release from the package version.
  • deploy-web had no version step at all, so the live GitHub Pages site reported the committed placeholder 0.0.2.
  • sed -i -E left a stray pubspec.yaml-E on the macOS runners. BSD sed reads -E as a backup-file suffix.

Changes

The fix keeps the existing version scheme: releases are X.Y.Z from the tag, pre-releases <base>-pre-<sha>. It fixes how the version is worked out and applied.

tool/fetch_release_history.sh fetches only the history needed to find the last release:

  1. Lists the remote's release tags and their commits with ls-remote, which downloads no history.
  2. If HEAD's history is cut off, deepens it in steps until it contains a final release's commit.
  3. Fetches just the tags whose commits are in that history.

On this repo that's 21 of 776 commits and one tag. It handles a detached HEAD (pull-request merge commits), orphan branches, remotes with no tags, and full clones made without tags.

tool/build_version.sh works out the version, prints KEY=VALUE lines and changes nothing unless asked. It takes --tag and --build-number, so nothing in it is specific to GitHub; it follows the same pattern as tool/build_web.sh. Running it locally shows what version a build would get. --write-pubspec writes the result into pubspec.yaml, so every tool that reads the pubspec picks it up: flutter build, msix:create and package_info_plus (and through it, Sentry).

  • version: <display>+<build number>. The build number is github.run_number.
  • MSIX version: X.Y.Z.0 for final releases. Pre-release and rc-tag builds get <last final release>.<build>, so rc → later builds → final release are all upgrades.
  • The pre-release base 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).
  • Tags are validated against the full semver grammar. A shallow clone with no reachable release fails with a clear message rather than guessing 0.0.0.

.github/actions/build-version is a small local action that maps GitHub's tag and run number onto the scripts and exports the results to later steps. The tag is passed through an environment variable rather than pasted into the script, so a tag name can't inject shell commands. All eight jobs that build use it in one step, including deploy-web.

Workflow

  • macOS and iOS builds pass --build-name "$WIMSY_VERSION_CORE", so bundles get e.g. 0.0.6 (412).
  • The DMG check from Ship the macOS release as a verified DMG containing only wimsy.app #4 now verifies the version and build number on every build, not just tags.
  • A new test-ci-scripts job runs the scripts' tests on Linux, macOS and Windows alongside the builds. publish-release waits for it.

Testing

  • tool/test_build_version.sh: 76 checks in throwaway git repos. They cover:
    • CI-shaped clones: shallow, tagless, detached HEAD, orphan branches and annotated tags.
    • Merge-backs and superseded rc tags. These use dated commits so git describe really picks the tricky tag.
    • The MSIX limits.
    • Pubspec rewriting, including CRLF files compared as raw bytes.
    • A set of malformed inputs, each of which must fail without touching the pubspec.
  • Mutation checks: removing each key rule makes its tests fail.
  • CI on my fork, run 44504221234: all green. That includes test-ci-scripts on all three operating systems and maestro-e2e. Stamped values from real runs:
    • WIMSY_VERSION=0.0.6-pre-<sha>, WIMSY_MSIX_VERSION=0.0.6.<run>
    • macOS DMG check: ok: bundle version 0.0.6, ok: bundle build number <run>
  • Bugs that only showed up on CI runners, now fixed:
    • On Windows, the pubspec rewrite turned the whole file into LF-only. Git for Windows' awk drops the CR as it reads each line. The line ending is now detected from the raw bytes.
    • A loop condition that could spin forever on orphan branches.
  • flutter analyze, flutter test and vendor/xmpp_stone dart test all pass. The Maestro flows weren't run locally, since the app code is unchanged; CI's maestro-e2e passed.

Known limitations

These are documented in tool/build_version.sh:

  • Apple short versions: Apple platforms only accept numeric versions, so a pre-release shares its release's short version there; the build number tells them apart.
  • Run counter: github.run_number is shared by all branches and restarts if the workflow file is renamed.
  • rc numbering: undotted rc numbers sort as text (rc10 < rc9), so use rc.N tags.
  • MSIX limit: pre-release MSIX versions need a build number of at most 65535.

Not in this PR

  • Pre-release ordering: a pre-release labelled 0.0.6-pre-<sha> still sorts before 0.0.6 under semver. That scheme change is a separate follow-up PR, so it can be accepted or declined on its own.
  • Gradle download caching for the Android job: this would harden it against Gradle Plugin Portal outages, which made one of my fork runs fail once. Possibly a separate PR.

🤖 Generated with Claude Code

Fishbowler and others added 2 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>
@dwd
dwd merged commit a6866da 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