Skip to content
Merged
60 changes: 42 additions & 18 deletions .github/scripts/syncVersions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
# with push access to App main.
# - GITHUB_OUTPUT: written by `check` and `sync` (defaults to /dev/null outside GitHub Actions).
# - TARGET_VERSION (sync, optional): version to sync to. Must equal the Mobile-Expensify version,
# since only the App side is rewritten and the final verification compares the two. Empty means
# "use the Mobile-Expensify version".
# since only the App side is rewritten and the final verification compares the two. Anything else
# is rejected before the sync writes or pushes. Empty means "use the Mobile-Expensify version".
# - NEED_FULL_VERSION_SYNC (sync): 'true' to rewrite versions, anything else to only bump the
# submodule pointer. Threaded from `check` so exactly one decision exists across both steps.
# - EXPECTED_SUBMODULE_SHA (sync): Mobile-Expensify SHA `check` updated to. The submodule-only
# path asserts against it so a checkout that moved in between is caught.
# path asserts against it so a checkout that moved in between is caught, and verification uses
# it to tell "this sync went wrong" apart from "Mobile-Expensify moved on again".
#
# Outputs (via GITHUB_OUTPUT):
# - check: IN_SYNC, NEED_FULL_VERSION_SYNC, ACTUAL_SHA
# - sync: POST_SYNC_APP_VERSION
# - sync: POST_SYNC_APP_VERSION, SUBMODULE_MATCHES_REMOTE
#
# Side effects:
# - `check` is not read-only: it runs `git submodule update --remote`.
Expand Down Expand Up @@ -96,17 +97,25 @@ function update_ios_versions {
}

function resolve_target_version {
if [[ -n "$TARGET_VERSION" ]]; then
echo "Using provided target version: $TARGET_VERSION" >&2
echo "$TARGET_VERSION"
return
fi

# Use Mobile-Expensify version as source of truth since it was pushed first
local me_version
me_version="$(get_mobile_expensify_version)"
echo "Using Mobile-Expensify version as target: $me_version" >&2
echo "$me_version"

if [[ -z "$TARGET_VERSION" ]]; then
echo "Using Mobile-Expensify version as target: $me_version" >&2
echo "$me_version"
return
fi

# Only the App side is rewritten, so any other target fails verification -- after the commits
# have already been pushed to main. Reject it before anything is written.
if [[ "$TARGET_VERSION" != "$me_version" ]]; then
echo "::error::TARGET_VERSION ($TARGET_VERSION) must match the Mobile-Expensify version ($me_version)" >&2
exit 1
fi

echo "Using provided target version: $TARGET_VERSION" >&2
echo "$TARGET_VERSION"
}

function cmd_check {
Expand Down Expand Up @@ -168,10 +177,12 @@ function sync_full_version {
git add package.json package-lock.json android/app/build.gradle ios/*/Info.plist
git commit -m "Update version to $target (sync recovery)"

# Stages the submodule's checked-out HEAD, which is the commit `check` moved it to with
# --remote, not whatever main currently records.
# Stages the submodule's checked-out HEAD, the commit `check` moved it to with --remote. That can
# already be what main records, when a previous sync got this far and then died, hence the guard.
git add Mobile-Expensify
git commit -m "Update Mobile-Expensify submodule version to $target (sync recovery)"
if ! git diff --staged --quiet; then
git commit -m "Update Mobile-Expensify submodule version to $target (sync recovery)"
fi

# main is busy enough that another merge can land between `check` and here, which makes this
# push non fast-forward.
Expand Down Expand Up @@ -233,12 +244,25 @@ function verify_sync {
recorded=$(git rev-parse HEAD:Mobile-Expensify)
remote_sha=$(git -C Mobile-Expensify rev-parse origin/main)
if [[ "$recorded" != "$remote_sha" ]]; then
echo "::error::Submodule on App main ($recorded) still differs from Mobile-Expensify origin/main ($remote_sha)"
exit 1
# Mobile-Expensify main can advance mid-run, which is likely because a deployer triggers this
# during a deploy. Recording what `check` pinned is still a successful sync, so report it and
# let the next run collect the newer commit.
if [[ "$recorded" == "$EXPECTED_SUBMODULE_SHA" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not claim the stale gitlink matches current main

When Mobile-Expensify advances after check, this branch deliberately returns success while recorded is still the older SHA. The workflow then runs its existing “Announce sync in Slack” step, whose success message says that the submodule matches Mobile-Expensify main, even though this branch just established that it does not. Deployer notifications will therefore report a completed, fully synchronized version when a rerun is still required; expose this stale-but-accepted state to the workflow or change the success announcement accordingly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Vit's agent)

Good catch, and correct — fixed in 7a6f54c8d62. verify_sync now sets a SUBMODULE_MATCHES_REMOTE output, and the announce step's text branches on it, so the stale-but-accepted case says "Mobile-Expensify main has advanced since, so run this again to record it" instead of claiming a match. Both directions are asserted in the suite.

echo "::warning::Mobile-Expensify main advanced to $remote_sha while syncing. App main records $recorded, which is what this run set out to record. Re-run to pick up the newer commit."
set_output SUBMODULE_MATCHES_REMOTE false
else
echo "::error::Submodule on App main ($recorded) still differs from Mobile-Expensify origin/main ($remote_sha)"
exit 1
fi
fi

set_output POST_SYNC_APP_VERSION "$app_version"
echo "::notice::✅ Verified versions ($app_version) and submodule match Mobile-Expensify main ($recorded)"
if [[ "$recorded" == "$remote_sha" ]]; then
set_output SUBMODULE_MATCHES_REMOTE true
echo "::notice::✅ Verified versions ($app_version) and submodule match Mobile-Expensify main ($recorded)"
else
echo "::notice::✅ Verified versions ($app_version); submodule records $recorded, one behind Mobile-Expensify main"
fi
}

function cmd_sync {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/syncVersions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
"channel": "#deployer",
"attachments": [{
"color": "good",
"text": "✅ Version sync completed. E/App and Mobile-Expensify are at ${{ steps.performSync.outputs.POST_SYNC_APP_VERSION }}; submodule matches Mobile-Expensify main."
"text": "✅ Version sync completed. E/App and Mobile-Expensify are at ${{ steps.performSync.outputs.POST_SYNC_APP_VERSION }}; ${{ steps.performSync.outputs.SUBMODULE_MATCHES_REMOTE == 'true' && 'submodule matches Mobile-Expensify main.' || 'Mobile-Expensify main has advanced since, so run this again to record it.' }}"
}]
}

Expand Down
47 changes: 45 additions & 2 deletions tests/tooling/SyncVersions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,27 @@ describe('syncVersions.sh sync (submodule only)', () => {

expect(result.status).toBe(0);
expect(result.outputs.POST_SYNC_APP_VERSION).toBe('9.3.11-48');
expect(result.outputs.SUBMODULE_MATCHES_REMOTE).toBe('true');
expect(git(appDir, 'ls-tree', 'origin/main', 'Mobile-Expensify')).toContain(newSubmoduleSha);
expect(git(appDir, 'log', '-1', '--format=%s', 'origin/main')).toBe(`Bump Mobile-Expensify submodule to latest main (${newSubmoduleSha})`);
});

it('warns instead of failing when Mobile-Expensify main advances mid-sync', () => {
setUpFixture('9.3.11-48', '9.3.11-48');
const shaAtCheck = advanceMobileExpensify();
runScript('check');
// Mobile-Expensify main moves again while Node is being set up and the sync runs
const laterSha = advanceMobileExpensify();

const result = runScript('sync', {env: {NEED_FULL_VERSION_SYNC: 'false', EXPECTED_SUBMODULE_SHA: shaAtCheck}});

expect(result.status).toBe(0);
expect(result.stdout).toContain(`::warning::Mobile-Expensify main advanced to ${laterSha} while syncing`);
expect(result.outputs.POST_SYNC_APP_VERSION).toBe('9.3.11-48');
expect(result.outputs.SUBMODULE_MATCHES_REMOTE).toBe('false');
expect(git(appDir, 'ls-tree', 'origin/main', 'Mobile-Expensify')).toContain(shaAtCheck);
});

it('rebases and retries when App main moved since the check step', () => {
setUpFixture('9.3.11-48', '9.3.11-48');
const newSubmoduleSha = advanceMobileExpensify();
Expand Down Expand Up @@ -374,7 +391,7 @@ describeMacOS('syncVersions.sh sync (full version)', () => {
expect(result.outputs.POST_SYNC_APP_VERSION).toBe('9.3.11-48');
});

it('fails verification when the target version does not match Mobile-Expensify', () => {
it('rejects a target version that does not match Mobile-Expensify, without touching App main', () => {
setUpFixture('9.3.10-1', '9.3.11-48', true);
// A real version drift always comes with the submodule pointer being behind, since Mobile-Expensify is bumped first
advanceMobileExpensify();
Expand All @@ -383,7 +400,33 @@ describeMacOS('syncVersions.sh sync (full version)', () => {
const result = runScript('sync', {env: {NEED_FULL_VERSION_SYNC: 'true', TARGET_VERSION: '9.9.9-9'}});

expect(result.status).toBe(1);
expect(result.stdout).toContain("::error::Sync failed! Versions still don't match");
expect(result.stderr).toContain('::error::TARGET_VERSION (9.9.9-9) must match the Mobile-Expensify version (9.3.11-48)');
expect(readVersion(path.join(appDir, 'package.json'))).toBe('9.3.10-1');
expect(git(appDir, 'log', '-1', '--format=%s', 'origin/main')).toBe('Add Mobile-Expensify submodule');
});

it('fails verification when App main records a submodule commit this run never pinned', () => {
setUpFixture('9.3.10-1', '9.3.11-48', true);
runScript('check');
advanceMobileExpensify();

const result = runScript('sync', {env: {NEED_FULL_VERSION_SYNC: 'true', EXPECTED_SUBMODULE_SHA: 'f'.repeat(40)}});

expect(result.status).toBe(1);
expect(result.stdout).toContain('::error::Submodule on App main');
});

it('still syncs when the submodule pointer is already current', () => {
// Reachable after a previous sync got as far as bumping the submodule pointer but not the versions
setUpFixture('9.3.10-1', '9.3.11-48', true);
runScript('check');

const result = runScript('sync', {env: {NEED_FULL_VERSION_SYNC: 'true'}});

expect(result.status).toBe(0);
expect(result.outputs.POST_SYNC_APP_VERSION).toBe('9.3.11-48');
expect(readVersion(path.join(appDir, 'package.json'))).toBe('9.3.11-48');
expect(git(appDir, 'log', '-1', '--format=%s', 'origin/main')).toBe('Update version to 9.3.11-48 (sync recovery)');
});
});

Expand Down
Loading