Repository navigation
feat(app): bake git SHA and build number into analytics and crash reports - #14336
Merged
Merged
Conversation
Codemagic and the local harness pass --dart-define OMI_GIT_SHA / OMI_BUILD_NUMBER (plus a dirty-tree marker). A single accessor defaults to unknown, then PostHog super-properties and Crashlytics keys carry them so a production signal resolves to a commit. Shorebird patches also report the runtime patch number when the updater is present. Co-authored-by: Cursor <[email protected]>
Porcelain counted Codemagic's untracked env and Firebase files as dirty, so a release SHA would not resolve. Validate dart-define values so unquoted command substitution cannot word-split. Failure-Class: none Co-authored-by: Cursor <[email protected]>
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 changed and why
Today nothing in
app/libknows its git commit.pubspec.yamlis1.0.543+992; Codemagic computes a differentBUILD_NUMBERfrom TestFlight / App Store / Play. Production PostHog events and Crashlytics issues cannot be resolved to a commit with one query.This bakes
OMI_GIT_SHA+OMI_BUILD_NUMBER(+OMI_GIT_DIRTY=trueonly when a tracked file differs from HEAD) via--dart-defineon every Codemagic app build (ios-internal-auto,android-internal-auto,ios-prod-testflight,android-prod-internal,ios-prod-patch,android-prod-patch) and on local/dev harnesssetup.shbuilds. A single Dart accessor (BuildProvenance) defaults to'unknown'when a define is omitted.Those properties are registered as PostHog super-properties through the existing analytics adapter (PostHog stays a no-op without a key) and as Crashlytics custom keys inside
CrashlyticsManager.init(), which already runs afterFirebase.initializeApp.app/lib/main.dartis not touched.Dirty flag:
git status --porcelainwould have marked Codemagic releases-dirtybecause those workflows write untracked files into the checkout (.env,firebase_key.json, FlutterFire output). Ignored paths cover env files,lib/firebase_options_*.dart,google-services.json,GoogleService-Info.plist, andkey.properties; untracked-but-not-ignored files (e.g.firebase_key.json) still show in porcelain. Dirty now meansgit diff --quiet HEAD --failed: a tracked file differs in the worktree or the index. Untracked and gitignored files do not count. WhenCM_BUILD_IDis set and the tree is dirty, the script printsbuild provenance: tracked files differ from HEAD:plusgit diff --name-only HEAD --so the Codemagic log names the files. SHA and build number are validated (^(unknown|[0-9a-f]{40})$/^(local|[0-9]+)$) before print, so unquoted$(scripts/build_provenance_dart_defines.sh)cannot word-split.Codemagic cwd: all six workflows set
working_directory: app.pod installcd iosis a prior step; the Flutter / Shorebird build step starts again inapp/, soscripts/build_provenance_dart_defines.shresolves.Shorebird
--dart-define: docs.shorebird.dev/code-push/patch/ —shorebird patchwrapsflutter build; args after--are flutter build args; exampleshorebird patch android -- --dart-define="foo=bar". FAQ: "Dart defines are compiled into your app's Dart code, they can be updated via patches." A patch that changes onlyOMI_GIT_SHA(a DartString.fromEnvironmentconstant) is a valid Dart-snapshot patch; native / flavor / obfuscate must still match the store release. Both patch workflows pass the defines after--.Shorebird patch number (cut, follow-up):
shorebird_code_pushwas added to readShorebirdUpdater.readCurrentPatch()for one string. That package is Dart + FFI into the updater already present in Shorebird-built engines; onflutter run/ the dev flavor (non-Shorebird engine) it is unavailable and prints a banner. It would register a plugin in every binary, including store builds, and the previous init awaited the read before first events. Patch number is a nice-to-have; this package's value is lead time through store review. SHA + build number ship now. Follow-up if wanted: async read, never throw into startup,registerSuperPropertieslate so the first events are not delayed.This is useless for production until a build carrying it has passed store review.
Product invariants affected
Path-based:
codemagic.yamlis on these globs. This PR only appends--dart-defineprovenance flags to existing mobile app build/patch steps. It does not change OAuth, Firebase project, API routing, or desktop Beta identity.How it was verified
bash app/scripts/build_provenance_dart_defines_test.sh(clean / tracked-dirty / untracked-only / non-git / BUILD_NUMBER / OMI_BUILD_NUMBER / CM_TAG ±+N/ none / whitespace fail / Codemagic dirty file list)bash app/scripts/mobile_build_wrapper_test.shflutter test test/unit/build_provenance_test.dart test/unit/build_provenance_registration_test.dartTZ=UTC bash app/test.shuv run --python 3.11.15 --with pytest pytest --noconftest backend/tests/unit/test_workflow_contracts.pymake preflight.github/scripts/fixtures/codemagic_workflow_contract/v1.jsonCould not verify: a store-signed binary in PostHog/Crashlytics (needs store review). Host tests have no Firebase app; Crashlytics registration is asserted as a no-op before
Firebase.initializeAppplus matching key names.Query: event → commit
PostHog (super properties
git_shaandbuild_numberon every event once the adapter has inited):git_shaequals the full 40-char git SHA (dirty local builds end in-dirty; strip that suffix beforegit show).Then
git show <full-git-sha>.build_numberis the store / Codemagic integer (BUILD_NUMBER), notpubspec.yaml's+992.Crashlytics: Firebase console → Crashlytics → Issues → filter by custom key
git_shaequals<full-git-sha>→ open the issue → Keys tab showsgit_shaandbuild_number. Same mapping as PostHog.Tests
app/test/unit/build_provenance_test.dartapp/test/unit/build_provenance_registration_test.dartapp/scripts/mobile_build_wrapper_test.shapp/scripts/build_provenance_dart_defines_test.sh(run fromapp/test.shandapp/scripts/test.sh)scripts/build_provenance_dart_defines.sh; script uses tracked-only dirty detectionFailure class (fixes)
Failure-Class: none
Part of the mobile self-driving program (CI and release lane, package V10). Implemented by Cursor
cursor-grok-4.6-high. This goes early because it is useless until a build carrying it has passed store review. Coordinator verification on the head commit: the script's shell tests pass (clean, tracked-dirty, untracked-only, non-git, every build-number source); the two Dart unit test files pass (7); on a clean tree the script emits a 40-hex SHA withOMI_GIT_DIRTY=false. The first review round rejected a dirty flag that counted untracked files (it would have labelled Codemagic release builds-dirty) and a newshorebird_code_pushruntime dependency added for one string; both are gone. Not verifiable before merge: that each of the six Codemagic workflows resolves the script and passes the defines — the first internal build after merge is that check, and the query in this body is how to confirm it.🤖 Generated with Claude Code