diff --git a/.agents/skills/release-update/SKILL.md b/.agents/skills/release-update/SKILL.md index 013ca6f..a131e31 100644 --- a/.agents/skills/release-update/SKILL.md +++ b/.agents/skills/release-update/SKILL.md @@ -1,6 +1,6 @@ --- name: release-update -description: Build, verify, submit, and publish BooKoo releases through EAS Build, Expo Updates, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. +description: Build, verify, submit, and publish BooKoo releases through local EAS Build, Codemagic Patch OTA, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. --- # Release Update @@ -44,18 +44,19 @@ Require new iOS and Android binaries when any of these changed: permissions, targets, manifests, Info.plist, Pod/Gradle inputs, or native assets — including anything under `plugins/` and the social-login SDKs; - app version/build numbers or store compliance requirements; -- behavior that cannot run safely on the installed runtime version. +- behavior that cannot run safely on the installed binary version. -For the explicit native runtime, follow `$update-version`: native-contract -changes must advance `app.config.ts`'s shared runtimeVersion and ship new -iOS and Android binaries before OTA delivery. A proven metadata-only store patch -may retain the existing -compatible runtime and build only the platform that requires a new store version -(iOS1.1.1 retains runtime1.1.0; Android32 stays public). Record the exception and -verify the installed native version separately from the OTA manifest version. +Over-the-air updates come from Codemagic Patch (`@codemagic/react-native-patch`, +team OpenIAP on `https://ota.codemagicpatch.dev`, apps `BooKoo-iOS` and +`BooKoo-Android`). A release targets the binary's marketing version and Patch +also checks the native fingerprint, so an OTA never lands on an incompatible +binary. Native-contract changes need new iOS and Android binaries before any +OTA that relies on them; follow `$update-version`. The first Patch binary is +1.5.0; store binaries up to 1.4.0 still run expo-updates and receive nothing +from Patch. -Use Expo Updates only when the change is JavaScript/assets compatible with the -existing production runtime and no store binary or compliance update is needed. +Use a Codemagic Patch OTA only when the change is JavaScript/assets compatible with the +existing production binary and no store binary or compliance update is needed. ## Verify Before Shipping @@ -99,15 +100,19 @@ existing production runtime and no store binary or compliance update is needed. 2. Publish an OTA only for a JavaScript/assets-compatible change from a clean checkout whose `HEAD` exactly matches `origin/main`. Record that decision and a useful message explicitly: - - `EAS_UPDATE_CONFIRM_COMPATIBLE=1 EAS_UPDATE_MESSAGE="" bun eas:prod:updates` + - `OTA_CONFIRM_COMPATIBLE=1 OTA_MESSAGE="" bun ota:release` - append `:ios` or `:android` to target one platform. - The guard publishes to the `production` channel with the `production` EAS - environment. Never publish automatically on every merge: native modules, - config plugins, permissions, entitlements, and native assets require new - locally built binaries even when the semantic app version is unchanged. - - add `EAS_UPDATE_DRY_RUN=1` to verify the exact-main and successful-CI gates + The guard publishes to the Patch `Production` deployment, bundling with + the `production` EAS environment through `eas env:exec`. Never publish + automatically on every merge: native modules, config plugins, permissions, + entitlements, and native assets require new locally built binaries even + when the semantic app version is unchanged. + - Sign in once with `bunx @codemagic/patch-cli@0.10.0 login --server-url + https://ota.codemagicpatch.dev`. QA builds read the `Staging` deployment; + test there first with `cmpatch release-react --deployment Staging`. + - add `OTA_DRY_RUN=1` to verify the exact-main and successful-CI gates without bundling or publishing. - - when GitHub Actions cannot run, add `EAS_UPDATE_VERIFY=local`: the script + - when GitHub Actions cannot run, add `OTA_VERIFY=local`: the script runs CI's `check` commands (`bun lint:all`, `bun typecheck`, `bun run test`) on that exact clean commit instead of looking up the CI run. Never use it for a change under `convex/`. @@ -145,7 +150,7 @@ Include: - Convex deploy result and the deployment targeted; - AAB/IPA inspection results; - `$perf-audit` and `$e2e-test` summaries; -- Expo update IDs, branch, and runtime version when OTA was used; +- Patch release labels, deployment, and target binary version when OTA was used; - per-store upload, review, approval, and release states; - release-note text and any remaining manual action. diff --git a/.agents/skills/update-version/SKILL.md b/.agents/skills/update-version/SKILL.md index ac3f9a8..dbe8bb9 100644 --- a/.agents/skills/update-version/SKILL.md +++ b/.agents/skills/update-version/SKILL.md @@ -12,11 +12,11 @@ Use `references/workflow.md` as the detailed version and force-update checklist. 1. Parse the requested semantic version and whether `--force` was requested. 2. Update the marketing/store `version` in `package.json`; `app.config.ts` reads it. Never duplicate that marketing version in a screen. -3. Inspect native compatibility before building or publishing: `app.config.ts` - owns an explicit `runtimeVersion`. Advance it to the new release version - whenever native dependencies, plugins, permissions or the native contract - change. A shared top-level runtime bump requires both new iOS and Android - binaries before compatible OTA delivery. +3. Inspect native compatibility before building or publishing. Codemagic Patch + targets OTA releases by this marketing version and checks the native + fingerprint. Whenever native dependencies, plugins, permissions or the + native contract change, ship new iOS and Android binaries before any OTA + that depends on them. A metadata-only version change may retain the existing runtime only after confirming the native contract is unchanged and recording that decision. Historical iOS1.1.1 deliberately retained runtime1.1.0 for live Android32/iOS41. diff --git a/.agents/skills/update-version/references/workflow.md b/.agents/skills/update-version/references/workflow.md index 10fc0b3..594b20f 100644 --- a/.agents/skills/update-version/references/workflow.md +++ b/.agents/skills/update-version/references/workflow.md @@ -48,11 +48,11 @@ installed native version; the update manifest is only a web/Expo Go fallback. ### Step 1b — Review native runtime compatibility -`app.config.ts` owns the independent explicit `runtimeVersion`. If the release -changes native dependencies, plugins, permissions, entitlements or the native -contract, advance this value to the new release version. A shared top-level -runtime bump requires both new iOS and Android binaries before OTA delivery. -An OTA requiring those native APIs must never target older binaries. +Codemagic Patch targets each OTA release at the marketing version in +`package.json` and also compares the native fingerprint. If the release changes +native dependencies, plugins, permissions, entitlements or the native contract, +ship both new iOS and Android binaries before OTA delivery. An OTA requiring +those native APIs must never target older binaries. For a metadata-only patch with an unchanged native contract, explicitly retain the compatible runtime and record the decision in release evidence. Historical diff --git a/.claude/skills/release-update/SKILL.md b/.claude/skills/release-update/SKILL.md index e169f18..46e70e9 100644 --- a/.claude/skills/release-update/SKILL.md +++ b/.claude/skills/release-update/SKILL.md @@ -1,6 +1,6 @@ --- name: release-update -description: Build, verify, submit, and publish BooKoo releases through EAS Build, Expo Updates, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. +description: Build, verify, submit, and publish BooKoo releases through local EAS Build, Codemagic Patch OTA, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. --- # Release Update (Claude Code) diff --git a/.codex/skills/release-update/SKILL.md b/.codex/skills/release-update/SKILL.md index d8c6bbb..6aa8ae0 100644 --- a/.codex/skills/release-update/SKILL.md +++ b/.codex/skills/release-update/SKILL.md @@ -1,6 +1,6 @@ --- name: release-update -description: Build, verify, submit, and publish BooKoo releases through EAS Build, Expo Updates, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. +description: Build, verify, submit, and publish BooKoo releases through local EAS Build, Codemagic Patch OTA, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. --- # Release Update (Codex) diff --git a/.cursor/rules/release-update.mdc b/.cursor/rules/release-update.mdc index b6eb28b..09e1b5f 100644 --- a/.cursor/rules/release-update.mdc +++ b/.cursor/rules/release-update.mdc @@ -1,5 +1,5 @@ --- -description: Build, verify, submit, and publish BooKoo releases through EAS Build, Expo Updates, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. +description: Build, verify, submit, and publish BooKoo releases through local EAS Build, Codemagic Patch OTA, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. globs: alwaysApply: false --- diff --git a/.grok/skills/release-update/SKILL.md b/.grok/skills/release-update/SKILL.md index 8046114..9e40856 100644 --- a/.grok/skills/release-update/SKILL.md +++ b/.grok/skills/release-update/SKILL.md @@ -1,6 +1,6 @@ --- name: release-update -description: Build, verify, submit, and publish BooKoo releases through EAS Build, Expo Updates, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. +description: Build, verify, submit, and publish BooKoo releases through local EAS Build, Codemagic Patch OTA, Google Play, and App Store Connect. Use when the user runs `/release-update` or `$release-update`, asks to release or deploy BooKoo, upload IPA/AAB artifacts, submit store builds for review, add release notes, choose between a native build and an OTA update, or finish a version rollout after review and E2E. --- # Release Update (Grok) diff --git a/.notes/design/release-and-store.md b/.notes/design/release-and-store.md index 7cdc835..dfc0b21 100644 --- a/.notes/design/release-and-store.md +++ b/.notes/design/release-and-store.md @@ -37,11 +37,11 @@ from a verified release branch, with remote EAS build numbers, store record ids, and the exact Convex production deployment recorded in a private release manifest. No secret, service account JSON, `.p8`, keystore, OTP, or reviewer credential is committed. -EAS Update is a manual production tool, not a per-merge deployment. A compatible JavaScript/assets-only +Codemagic Patch (`bun ota:release`) is a manual production tool, not a per-merge deployment. A compatible JavaScript/assets-only change may be published only from a clean checkout whose `HEAD` exactly matches `origin/main`, after an exact successful push CI run plus an explicit compatibility acknowledgement and release message. The guarded -`eas:prod:updates*` scripts target the `production` channel and EAS environment; -`runtimeVersion.policy = appVersion` keeps updates scoped to matching installed binaries. Native dependency/ +`ota:release*` scripts publish to the Patch `Production` deployment with the `production` EAS environment; +the target binary version plus Patch's native fingerprint keep updates scoped to matching installed binaries. Native dependency/ config/permission/entitlement/manifest/asset changes require new local-only IPA/AAB builds. The EAS `preview` profile is retained only for explicit local internal-device testing and is unrelated to Convex cloud preview deployments. diff --git a/app.config.ts b/app.config.ts index bf3eaab..31aeef3 100644 --- a/app.config.ts +++ b/app.config.ts @@ -21,10 +21,23 @@ const {applicationId: APPLICATION_ID, qaApplicationId: QA_APPLICATION_ID} = JSON.parse( fs.readFileSync(path.join(projectRoot, 'shared/application.json'), 'utf8'), ) as {applicationId: string; qaApplicationId: string}; +// Codemagic Patch delivers over-the-air updates. The deployment keys only let a +// build ask for updates, so they ship inside every binary and live in the repo. +interface OtaDeployments { + apiUrl: string; + downloadBaseUrl: string; + deploymentKeys: Record< + 'ios' | 'android', + {staging: string; production: string} + >; +} +const OTA = JSON.parse( + fs.readFileSync(path.join(projectRoot, 'shared/otaDeployments.json'), 'utf8'), +) as OtaDeployments; // `EXPO_NO_DOTENV=1` means "the environment is already correct, do not read -// local env files". `scripts/eas-update-production.zsh` sets it alongside -// `--environment production` so a production OTA is built from the EAS +// local env files". `scripts/ota-release.zsh` sets it inside +// `eas env:exec production`, so a production OTA is built from the EAS // Environment and nothing else. // // Expo honours the flag for its own dotenv loading, but this config does its @@ -165,6 +178,27 @@ export default ({config}: ConfigContext): ExpoConfig => ({ typedRoutes: true, }, plugins: [ + [ + '@codemagic/react-native-patch', + { + ios: { + apiUrl: OTA.apiUrl, + downloadBaseUrl: OTA.downloadBaseUrl, + // QA builds read Staging so local testing never takes or replaces a + // production update. + deploymentKey: qa + ? OTA.deploymentKeys.ios.staging + : OTA.deploymentKeys.ios.production, + }, + android: { + apiUrl: OTA.apiUrl, + downloadBaseUrl: OTA.downloadBaseUrl, + deploymentKey: qa + ? OTA.deploymentKeys.android.staging + : OTA.deploymentKeys.android.production, + }, + }, + ], 'expo-iap', 'expo-router', 'expo-asset', @@ -428,11 +462,4 @@ export default ({config}: ConfigContext): ExpoConfig => ({ eas: {projectId: EAS_PROJECT_ID}, stage: qa ? 'preview' : (process.env.STAGE ?? 'development'), }, - // Vietnamese native declarations belong to the1.4.0 runtime; QA remains - // isolated so local testing cannot receive or replace production updates. - runtimeVersion: qa ? `qa-${version}` : '1.4.0', - updates: { - fallbackToCacheTimeout: 0, - url: `https://u.expo.dev/${EAS_PROJECT_ID}`, - }, }); diff --git a/app/_layout.tsx b/app/_layout.tsx index c0b7ede..31d217f 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -9,7 +9,7 @@ import {styled, css} from 'kstyled'; import {useMMKVString} from 'react-native-mmkv'; import {Stack, usePathname} from 'expo-router'; import * as SplashScreen from 'expo-splash-screen'; -import * as Updates from 'expo-updates'; +import * as Patch from '@codemagic/react-native-patch'; import {wrapWithObserveRoot} from '../src/features/runtime/observeRoot'; import {CustomPressable, Icon, useCPK} from 'cpk-ui'; import StatusBarBrightness from 'cpk-ui/components/uis/StatusbarBrightness/StatusBarBrightness'; @@ -120,7 +120,7 @@ function Navigator(): ReactElement | null { icon="WifiSlash" primaryAction={{ label: t('common.tryAgain'), - onPress: () => void Updates.reloadAsync().catch(() => undefined), + onPress: () => void Patch.restartApp().catch(() => undefined), }} secondaryAction={{ label: t('permission.openSettings'), diff --git a/bun.lock b/bun.lock index 85215c3..d610d53 100644 --- a/bun.lock +++ b/bun.lock @@ -5,6 +5,7 @@ "": { "name": "bookoo", "dependencies": { + "@codemagic/react-native-patch": "0.7.0", "@convex-dev/auth": "0.0.95", "@convex-dev/rate-limiter": "0.3.2", "@convex-dev/workpool": "0.4.10", @@ -58,7 +59,6 @@ "expo-splash-screen": "~57.0.10", "expo-status-bar": "~57.0.1", "expo-system-ui": "~57.0.3", - "expo-updates": "~57.0.26", "expo-web-browser": "~57.0.2", "i18n-js": "4.5.3", "jose": "6.2.10", @@ -293,6 +293,8 @@ "@bcoe/v8-coverage": ["@bcoe/v8-coverage@0.2.3", "", {}, "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw=="], + "@codemagic/react-native-patch": ["@codemagic/react-native-patch@0.7.0", "", { "peerDependencies": { "react": ">=18", "react-native": ">=0.73" } }, "sha512-SJrrasxn9ahMB92yO2xxXL6+S1eOr+3qeGqNx5kuqzu3GRu6Vo92IsFpSJ5MQBAZCVbDUCn3OUfMKmvmpxN99Q=="], + "@commitlint/cli": ["@commitlint/cli@21.2.2", "", { "dependencies": { "@commitlint/config-conventional": "^21.2.2", "@commitlint/format": "^21.2.2", "@commitlint/lint": "^21.2.2", "@commitlint/load": "^21.2.2", "@commitlint/read": "^21.2.1", "@commitlint/types": "^21.2.0", "tinyexec": "^1.0.0", "yargs": "^18.0.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-a+6hQxIxnpdvSvS2apvttPNbEliYsVC3PqFYDiiB2kjbwIsQsj1urvQ4Tkf70pKYozPalKAuRQmm/GHwndduqA=="], "@commitlint/config-conventional": ["@commitlint/config-conventional@21.2.2", "", { "dependencies": { "@commitlint/types": "^21.2.0", "conventional-changelog-conventionalcommits": "^10.0.0" } }, "sha512-NxA37SZviusFUEYOQZ5hNnZ1h7O/KiemPkxjOlpzKJNnWxThiwc6/SaZhaPa8fyLvfRBAywhQhJJk8XESHWlpQ=="], @@ -1375,8 +1377,6 @@ "expo-image-picker": ["expo-image-picker@57.0.20", "", { "dependencies": { "expo-image-loader": "~57.0.1" }, "peerDependencies": { "expo": "*" } }, "sha512-plgcGuMZMWqDchjXQW6S/WepYLB5KqfbZOzwC6xe0+j5IhY4ipvVuRZcXeP/0NgKgU0Jiu/XoTK4Bi8crtZ+sQ=="], - "expo-json-utils": ["expo-json-utils@57.0.2", "", {}, "sha512-9kYZECLKE3pYZQs+kt3+ggY83Lfryog9/UEo3HJKGcHUZeKKtlFBIPFjI4LzREubsvjP7AsvG0FdEX9EquIoAQ=="], - "expo-keep-awake": ["expo-keep-awake@57.0.2", "", { "peerDependencies": { "expo": "*", "react": "*" } }, "sha512-GqgH746wtJImmsbyHmCQoi7cOslKuWQBbJHXr53S35Bpf5UvxCAztvnitUEd7D0QvFN2rvkOhylbZpgZZfBLlQ=="], "expo-linear-gradient": ["expo-linear-gradient@57.0.2", "", { "peerDependencies": { "expo": "*", "react": "*", "react-native": "*" } }, "sha512-eGNSfcbdXYvw0B/TQ3nmXKQgj0jLUi3EgsXGlvI79rlXg5RR5dQTkY2yqkf7BQDM3PMd3tqBMZdsLhvBqSUaMg=="], @@ -1389,8 +1389,6 @@ "expo-location": ["expo-location@57.0.22", "", { "dependencies": { "@expo/image-utils": "^0.11.6" }, "peerDependencies": { "expo": "*" } }, "sha512-BcSWD4SLBXotfeSeITju/eLuuTl4bMIQv+ekBAn/a7SBH5uEjEAYy6NzRYzDg4TE+1gl/CxJ8EN2iXM+cS0EUA=="], - "expo-manifests": ["expo-manifests@57.0.2", "", { "dependencies": { "expo-json-utils": "~57.0.2" }, "peerDependencies": { "expo": "*" } }, "sha512-pPIIcKR73OShwlWMg8H90WRzKUd2krDdKlKAwuQV1FtUwE7H3hQEFw0ePFQY9yFoGMF/77ryYwNKfI5umMcCog=="], - "expo-maps": ["expo-maps@57.0.4", "", { "peerDependencies": { "expo": "*", "react": "*", "react-native": "*" } }, "sha512-ZpE/CpTNCvINXgBo/5OZ33QJSgrgUNSCBMJAu1Aqbcy6v2uWhz+gJHsIBJDGdBVdy6bGwaB87djaMOLJVcpqlA=="], "expo-media-library": ["expo-media-library@57.0.5", "", { "peerDependencies": { "expo": "*", "react-native": "*" } }, "sha512-amSLrLsS7Gl4nCqbc2PlVbHj5jK9kQLsSOQgJ2QasHCSHzYXw6Ui7aolxX5APg9P4TgYPE0yWn46ndifh52bRw=="], @@ -1419,14 +1417,10 @@ "expo-status-bar": ["expo-status-bar@57.0.1", "", { "peerDependencies": { "expo": "*", "react": "*", "react-native": "*" } }, "sha512-Xwaq1gAoVRWx5dPG5VhT5RSbnI9OilhZnO5qoPBnUaBAa5VzRzfdS8q0/bsPt0jR2DKLtGuP0bQ6efMJ4RIMDg=="], - "expo-structured-headers": ["expo-structured-headers@57.0.1", "", {}, "sha512-5VwmitVr2J716pOuHXWmEnHbZhZg63DBOZKH5tj0SR8Sps/3jSAf9wf9+UGTKcKgAxGf1PPwQ0lAQ2bG3RwjAg=="], - "expo-symbols": ["expo-symbols@57.0.3", "", { "dependencies": { "@expo-google-fonts/material-symbols": "^0.4.1", "sf-symbols-typescript": "^2.0.0" }, "peerDependencies": { "expo": "*", "expo-font": "*", "react": "*", "react-native": "*" } }, "sha512-uuK5yHLVR7kExUCrO/ItBvp/kp1maQ9Nkb6KvNy5ZUQnN0NMKwuhJ4GvbfS9N3ACmvCjTT4gKvg4yH5UuKIYNA=="], "expo-system-ui": ["expo-system-ui@57.0.4", "", { "dependencies": { "@react-native/normalize-colors": "0.86.3", "debug": "^4.3.2" }, "peerDependencies": { "expo": "*", "react-native": "*", "react-native-web": "*" }, "optionalPeers": ["react-native-web"] }, "sha512-z//rxQJzhTNA1PcKrUtWmrd21jAS3nEDu1b0n8B/7LTTR933OcsZYP1HnbaZifuo2ZH/h7nce2Ow61WZ1Ig2bg=="], - "expo-updates": ["expo-updates@57.0.26", "", { "dependencies": { "@expo/code-signing-certificates": "^0.0.6", "@expo/plist": "^0.8.1", "@expo/spawn-async": "^1.8.0", "arg": "^4.1.0", "chalk": "^4.1.2", "debug": "^4.3.4", "expo-eas-client": "~57.0.5", "expo-manifests": "~57.0.2", "expo-structured-headers": "~57.0.1", "expo-updates-interface": "~57.0.2", "getenv": "^2.0.0", "glob": "^13.0.0", "ignore": "^5.3.1", "nullthrows": "^1.1.1", "resolve-from": "^5.0.0" }, "peerDependencies": { "expo": "*", "expo-dev-client": "*", "react": "*", "react-native": "*" }, "optionalPeers": ["expo-dev-client"], "bin": { "expo-updates": "bin/cli.js" } }, "sha512-Dloc9rkoR22qx2HtxzDHOZQcU5rABqsvl8QWA0gFx8N6mHicTdbaxuQ6QCK/wp5fXAK6DQnfzTiQtvJ5IfMTew=="], - "expo-updates-interface": ["expo-updates-interface@57.0.2", "", { "peerDependencies": { "expo": "*" } }, "sha512-x3SA5toiHZEkW+5oeNdUM1Rvt6M3ExegQsSwS3Z1+S9gn9utGYTGBkb8MBQivhjIZiRlQYDIhauxA8kySQEWtQ=="], "expo-web-browser": ["expo-web-browser@57.0.3", "", { "peerDependencies": { "expo": "*", "react-native": "*" } }, "sha512-+ecvhyS/PdWkpv4ai6FF1Trd6Y/4kn/eQ3O86mie2ecU3w+I8bKZh13kppY/jw1uSL7yikt03L5W/iiHojrFwQ=="], @@ -2701,8 +2695,6 @@ "expo-splash-screen/@expo/config-plugins": ["@expo/config-plugins@57.0.10", "", { "dependencies": { "@expo/config-types": "^57.0.2", "@expo/json-file": "~11.0.1", "@expo/plist": "^0.8.1", "@expo/require-utils": "^57.0.6", "@expo/sdk-runtime-versions": "^1.0.0", "chalk": "^4.1.2", "debug": "^4.3.5", "getenv": "^2.0.0", "glob": "^13.0.0", "semver": "^7.5.4", "slugify": "^1.6.6", "xcode": "^3.0.1", "xml2js": "0.6.0" } }, "sha512-XFcj01blofSohoOxibrPsrsFPt2gAigrcWE3s6Vg+rSHvP9QVEfnyfmJNVsuIVT0EjY/1rZVJ4SajNDR5cJjpA=="], - "expo-updates/ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], - "fbjs/promise": ["promise@7.3.1", "", { "dependencies": { "asap": "~2.0.3" } }, "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg=="], "fbjs/ua-parser-js": ["ua-parser-js@1.0.41", "", { "bin": { "ua-parser-js": "script/cli.js" } }, "sha512-LbBDqdIC5s8iROCUjMbW1f5dJQTEFB1+KO9ogbvlb3nm9n4YHa5p4KTvFPWvh2Hs8gZMBuiB1/8+pdfe/tDPug=="], diff --git a/codemagic-patch.config.json b/codemagic-patch.config.json new file mode 100644 index 0000000..e684c08 --- /dev/null +++ b/codemagic-patch.config.json @@ -0,0 +1,15 @@ +{ + "serverUrl": "https://ota.codemagicpatch.dev", + "teamId": "team_d7a5cb3f206a4469aa838eebf6d70389", + "apps": { + "android": { + "app": "BooKoo-Android", + "deployment": "Production" + }, + "ios": { + "app": "BooKoo-iOS", + "deployment": "Production" + } + }, + "bundler": "expo" +} diff --git a/docs/ai/WORKFLOWS.md b/docs/ai/WORKFLOWS.md index f2a375f..3710514 100644 --- a/docs/ai/WORKFLOWS.md +++ b/docs/ai/WORKFLOWS.md @@ -346,7 +346,7 @@ OCR review/cancel/apply, and Duo transitions on the new artifact. Primary source: https://github.com/expo/expo/pull/50435. -## Production EAS Update policy +## Production OTA policy The September 13 release instruction authorizes finishing the reviewed changes, submission and production OTA without another owner-confirmation pause. Play @@ -356,10 +356,14 @@ Automatically release this version selected; `store.config.js` preserves `automaticRelease: true`. A future native release still needs actual store submission; automatic publication does not submit an unsubmitted build. -BooKoo keeps Martie's useful production OTA capability but makes the release -boundary explicit. `expo-updates`, the EAS project URL, the `production` build -channel, and the app-version runtime policy are configured in the app. The EAS -`production` channel points to the same-named update branch. +BooKoo ships over-the-air updates through Codemagic Patch (hosted for the +OpenIAP team at `https://ota.codemagicpatch.dev`, apps `BooKoo-iOS` and +`BooKoo-Android`). Store builds read the `Production` deployment and QA builds +read `Staging`; the keys live in `shared/otaDeployments.json`. A release targets +the binary's marketing version and Patch checks the native fingerprint. The +first Patch binary is 1.5.0; store binaries up to 1.4.0 still run expo-updates +and only receive EAS Update, so `bun ota:release` reaches devices only after +`package.json` and the store builds carry 1.5.0. Production OTA publishing is manual and is allowed only for a JavaScript/assets- compatible change from a clean checkout whose `HEAD` exactly matches @@ -368,25 +372,26 @@ package scripts with both an explicit compatibility acknowledgement and release message: ```sh -EAS_UPDATE_CONFIRM_COMPATIBLE=1 \ -EAS_UPDATE_MESSAGE="" \ -bun eas:prod:updates +OTA_CONFIRM_COMPATIBLE=1 \ +OTA_MESSAGE="" \ +bun ota:release ``` -Add `EAS_UPDATE_DRY_RUN=1` to verify the branch, clean-tree, exact-main and CI +Add `OTA_DRY_RUN=1` to verify the branch, clean-tree, exact-main and CI gates without bundling or publishing an update. When GitHub Actions cannot run (for example its included minutes are used up), -add `EAS_UPDATE_VERIFY=local`. The script then runs, on that exact clean commit, +add `OTA_VERIFY=local`. The script then runs, on that exact clean commit, the commands of CI's `check` job (`bun lint:all`, `bun typecheck`, `bun run test`) in place of the CI lookup, and every other gate still applies. The Convex budget suite and the history secret scan stay CI-only, so the mode is only for the JavaScript/assets-only updates the compatibility acknowledgement already requires, and a change under `convex/` must wait for a real CI run. -Use `eas:prod:updates:ios` or `eas:prod:updates:android` only when the compatible -change is intentionally platform-specific. The command publishes through the -`production` channel and EAS environment. It never creates an EAS cloud build. +Use `ota:release:ios` or `ota:release:android` only when the compatible change +is intentionally platform-specific. The command bundles with the `production` +EAS environment through `eas env:exec` and publishes to the Patch `Production` +deployment. It never creates a cloud build. Do not publish an OTA automatically on every merge. Any native dependency, config plugin, permission, entitlement, manifest, Pod/Gradle input, or native @@ -523,13 +528,10 @@ successful39 retry in [.notes/qa](../../.notes/qa/2026-10-09-apple-gallery-1-1-0 ### Metadata-only store versions and native compatibility -The store version in package.json and the compatible native runtime in -app.config.ts have distinct roles. iOS1.1.1 changes only its Korean store name -and retains runtime1.1.0, matching public Android32/iOS41. The guarded production -OTA commands therefore still target these compatible binaries. Advance the -explicit runtimeVersion whenever native dependencies, plugins, permissions or -the native contract change. A shared runtime bump requires both new iOS and -Android binaries before OTA delivery; a marketing-only bump does not advance it. +Patch targets each OTA at the marketing version in package.json and compares +the native fingerprint, so an incompatible binary never receives it. Whenever +native dependencies, plugins, permissions or the native contract change, ship +both new iOS and Android binaries before any OTA that depends on them. No OTA accompanies this metadata task. The canonical Apple gallery selector is sourceVersion in diff --git a/jest.config.ts b/jest.config.ts index a1ba3d8..b4af607 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -20,6 +20,7 @@ const TRANSFORMED_NODE_MODULES = [ '.pnpm', '(jest-)?react-native', // + react-native-{svg,mmkv,gesture-handler,reanimated,worklets,keyboard-controller,edge-to-edge,safe-area-context,screens,web,error-boundary} '@react-native', // + @react-native-community, @react-native-seoul/*, @react-native-google-signin/* + '@codemagic/react-native-patch', 'expo(nent)?', // + expo-* '@expo(nent)?', // + @expo/vector-icons, @expo/match-media, @expo/react-native-action-sheet '@expo-google-fonts', @@ -97,6 +98,8 @@ export default async (): Promise => { setupFiles: [ '/test/testSetup.ts', './node_modules/react-native-gesture-handler/jestSetup.js', + // Fakes the Patch TurboModule: a store binary with no update waiting. + './node_modules/@codemagic/react-native-patch/jest-setup.js', ], cacheDirectory: '.jest/cache', setupFilesAfterEnv: ['/test/testSetupAfterEnv.ts'], diff --git a/package.json b/package.json index 67f40c0..6a1498b 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,12 @@ "eas:purchase-test:android": "NODE_ENV=production bunx eas-cli@23.0.0 build --profile purchase-test --platform android --local", "eas:prod:android": "scripts/eas-local-production.zsh android", "eas:prod:ios": "scripts/eas-local-ios.zsh production", - "eas:prod:updates": "scripts/eas-update-production.zsh all", - "eas:prod:updates:ios": "scripts/eas-update-production.zsh ios", - "eas:prod:updates:android": "scripts/eas-update-production.zsh android" + "ota:release": "scripts/ota-release.zsh all", + "ota:release:ios": "scripts/ota-release.zsh ios", + "ota:release:android": "scripts/ota-release.zsh android" }, "dependencies": { + "@codemagic/react-native-patch": "0.7.0", "@convex-dev/auth": "0.0.95", "@convex-dev/rate-limiter": "0.3.2", "@convex-dev/workpool": "0.4.10", @@ -104,7 +105,6 @@ "expo-splash-screen": "~57.0.10", "expo-status-bar": "~57.0.1", "expo-system-ui": "~57.0.3", - "expo-updates": "~57.0.26", "expo-web-browser": "~57.0.2", "i18n-js": "4.5.3", "jose": "6.2.10", diff --git a/scripts/eas-update-production.zsh b/scripts/eas-update-production.zsh deleted file mode 100755 index 2c5a190..0000000 --- a/scripts/eas-update-production.zsh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/zsh - -set -euo pipefail - -platform="${1:-}" -if [[ "$platform" != "ios" && "$platform" != "android" && "$platform" != "all" ]]; then - print -u2 "usage: $0 " - exit 64 -fi - -if [[ "${EAS_UPDATE_CONFIRM_COMPATIBLE:-}" != "1" ]]; then - print -u2 \ - "set EAS_UPDATE_CONFIRM_COMPATIBLE=1 only after confirming the change is JavaScript/assets-only" - exit 64 -fi - -update_message="${EAS_UPDATE_MESSAGE:-}" -if [[ -z "$update_message" ]]; then - print -u2 "set EAS_UPDATE_MESSAGE to a short, user-facing description" - exit 64 -fi - -script_dir="${0:A:h}" -repo_root="${script_dir:h}" -cd "$repo_root" - -current_branch="$(git branch --show-current)" -if [[ "$current_branch" != "main" ]]; then - print -u2 "production EAS Update must run from main, not $current_branch" - exit 1 -fi - -if [[ -n "$(git status --porcelain)" ]]; then - print -u2 "production EAS Update requires a clean worktree" - exit 1 -fi - -git fetch --quiet origin main -local_head="$(git rev-parse HEAD)" -remote_head="$(git rev-parse origin/main)" -if [[ "$local_head" != "$remote_head" ]]; then - print -u2 "production EAS Update requires HEAD to match origin/main" - exit 1 -fi - -verify_mode="${EAS_UPDATE_VERIFY:-ci}" -if [[ "$verify_mode" == "ci" ]]; then - ci_state="$( - gh run list \ - --workflow CI \ - --commit "$local_head" \ - --event push \ - --limit 1 \ - --json headSha,status,conclusion \ - --jq 'if length == 1 then "\(.[0].headSha):\(.[0].status):\(.[0].conclusion)" else "" end' - )" - if [[ "$ci_state" != "${local_head}:completed:success" ]]; then - print -u2 "production EAS Update requires successful CI for exact main@$local_head" - exit 1 - fi -elif [[ "$verify_mode" == "local" ]]; then - # For when GitHub Actions cannot run (its included minutes are used up). - # This runs the commands of CI's `check` job on this exact clean commit. The - # Convex budget suite and the history secret scan stay CI-only, which is why - # this mode is only for the JavaScript/assets-only updates that - # EAS_UPDATE_CONFIRM_COMPATIBLE already attests to. - print "Verifying main@$local_head locally: lint:all, typecheck, test" - bun lint:all - bun typecheck - bun run test --silent -else - print -u2 "EAS_UPDATE_VERIFY must be ci (default) or local, not $verify_mode" - exit 64 -fi - -if [[ "${EAS_UPDATE_DRY_RUN:-}" == "1" ]]; then - print "Verified BooKoo $platform OTA release gates for main@$local_head" - exit 0 -fi - -print "Publishing BooKoo $platform OTA from main@$local_head" -exec env \ - NODE_ENV=production \ - STAGE=production \ - BOOKOO_APP_VARIANT=production \ - EXPO_NO_DOTENV=1 \ - bunx eas-cli@23.0.0 update \ - --channel production \ - --environment production \ - --message "$update_message" \ - --platform "$platform" \ - --non-interactive diff --git a/scripts/ota-release.zsh b/scripts/ota-release.zsh new file mode 100755 index 0000000..e7eb8b7 --- /dev/null +++ b/scripts/ota-release.zsh @@ -0,0 +1,104 @@ +#!/bin/zsh + +set -euo pipefail + +platform="${1:-}" +if [[ "$platform" != "ios" && "$platform" != "android" && "$platform" != "all" ]]; then + print -u2 "usage: $0 " + exit 64 +fi + +if [[ "${OTA_CONFIRM_COMPATIBLE:-}" != "1" ]]; then + print -u2 \ + "set OTA_CONFIRM_COMPATIBLE=1 only after confirming the change is JavaScript/assets-only" + exit 64 +fi + +update_message="${OTA_MESSAGE:-}" +if [[ -z "$update_message" ]]; then + print -u2 "set OTA_MESSAGE to a short, user-facing description" + exit 64 +fi + +script_dir="${0:A:h}" +repo_root="${script_dir:h}" +cd "$repo_root" + +current_branch="$(git branch --show-current)" +if [[ "$current_branch" != "main" ]]; then + print -u2 "production OTA must run from main, not $current_branch" + exit 1 +fi + +if [[ -n "$(git status --porcelain)" ]]; then + print -u2 "production OTA requires a clean worktree" + exit 1 +fi + +git fetch --quiet origin main +local_head="$(git rev-parse HEAD)" +remote_head="$(git rev-parse origin/main)" +if [[ "$local_head" != "$remote_head" ]]; then + print -u2 "production OTA requires HEAD to match origin/main" + exit 1 +fi + +verify_mode="${OTA_VERIFY:-ci}" +if [[ "$verify_mode" == "ci" ]]; then + ci_state="$( + gh run list \ + --workflow CI \ + --commit "$local_head" \ + --event push \ + --limit 1 \ + --json headSha,status,conclusion \ + --jq 'if length == 1 then "\(.[0].headSha):\(.[0].status):\(.[0].conclusion)" else "" end' + )" + if [[ "$ci_state" != "${local_head}:completed:success" ]]; then + print -u2 "production OTA requires successful CI for exact main@$local_head" + exit 1 + fi +elif [[ "$verify_mode" == "local" ]]; then + # For when GitHub Actions cannot run (its included minutes are used up). + # This runs the commands of CI's `check` job on this exact clean commit. The + # Convex budget suite and the history secret scan stay CI-only, which is why + # this mode is only for the JavaScript/assets-only updates that + # OTA_CONFIRM_COMPATIBLE already attests to. + print "Verifying main@$local_head locally: lint:all, typecheck, test" + bun lint:all + bun typecheck + bun run test --silent +else + print -u2 "OTA_VERIFY must be ci (default) or local, not $verify_mode" + exit 64 +fi + +if [[ "${OTA_DRY_RUN:-}" == "1" ]]; then + print "Verified BooKoo $platform OTA release gates for main@$local_head" + exit 0 +fi + +version="$(bun -e 'process.stdout.write(require("./package.json").version)')" +case "$platform" in + ios) targets=(ios) ;; + android) targets=(android) ;; + all) targets=(ios android) ;; +esac + +for target in $targets; do + app_name="BooKoo-iOS" + [[ "$target" == "android" ]] && app_name="BooKoo-Android" + print "Publishing BooKoo $target OTA $version from main@$local_head" + # EAS stays the source of the production environment: `env:exec` injects the + # same EXPO_PUBLIC_* values the store builds were compiled with. + bunx eas-cli@23.0.0 env:exec production --non-interactive \ + "NODE_ENV=production STAGE=production BOOKOO_APP_VARIANT=production EXPO_NO_DOTENV=1 \ + bunx @codemagic/patch-cli@0.10.0 release-react \ + --server-url https://ota.codemagicpatch.dev \ + --app $app_name \ + --deployment Production \ + --platform $target \ + --target-binary-version $version \ + --release-notes ${(q)update_message} \ + --non-interactive --yes" +done diff --git a/scripts/verify-dependencies.ts b/scripts/verify-dependencies.ts index c8eba00..470272e 100644 --- a/scripts/verify-dependencies.ts +++ b/scripts/verify-dependencies.ts @@ -55,9 +55,12 @@ const ownershipGroups: readonly (readonly [string, readonly string[]])[] = [ 'expo-splash-screen', 'expo-status-bar', 'expo-system-ui', - 'expo-updates', ], ], + [ + 'Over-the-air updates through Codemagic Patch — scripts/ota-release.zsh', + ['@codemagic/react-native-patch'], + ], [ 'Authentication, app lock and provider hand-off', [ diff --git a/shared/otaDeployments.json b/shared/otaDeployments.json new file mode 100644 index 0000000..afb3df1 --- /dev/null +++ b/shared/otaDeployments.json @@ -0,0 +1,14 @@ +{ + "apiUrl": "https://ota.codemagicpatch.dev", + "downloadBaseUrl": "https://ota-storage.codemagicpatch.dev", + "deploymentKeys": { + "ios": { + "staging": "dep_21bd504172704257ac0ca4400d2f881f", + "production": "dep_275d59cd58f04380839a2365dcf2ca5e" + }, + "android": { + "staging": "dep_c5979e6273c84da8ae0bf6d8d3413ecb", + "production": "dep_bbc9c24e08154da99ae04b4736fbd5d7" + } + } +} diff --git a/src/components/providers/index.tsx b/src/components/providers/index.tsx index e63b9c5..f6f0dca 100644 --- a/src/components/providers/index.tsx +++ b/src/components/providers/index.tsx @@ -37,9 +37,8 @@ export function CpkReadySplashBoundary({ const updating = useColdStartUpdate(); useEffect(() => { - // `fallbackToCacheTimeout: 0` means the native layer never waits for an - // update, so without this gate a staged update first appears on the NEXT - // launch. Hold the splash across the bounded check instead; the timeout in + // Codemagic Patch never waits for an update before launching the bundle, + // so without this gate a staged update first appears on the NEXT launch. Hold the splash across the bounded check instead; the timeout in // `coldStartUpdate` is what keeps a flaky network from hiding the recovery // screens below this boundary. if (!updating) void SplashScreen.hideAsync(); diff --git a/src/features/release/screens.tsx b/src/features/release/screens.tsx index 97860ea..1a991bf 100644 --- a/src/features/release/screens.tsx +++ b/src/features/release/screens.tsx @@ -14,7 +14,7 @@ import {usePaginatedQuery, useQuery} from 'convex-helpers/react/cache'; import {useMutation} from 'convex/react'; import Constants from 'expo-constants'; import * as Clipboard from 'expo-clipboard'; -import * as Updates from 'expo-updates'; +import * as Patch from '@codemagic/react-native-patch'; import {Directory, File, Paths} from 'expo-file-system'; import * as Sharing from 'expo-sharing'; import * as ImageManipulator from 'expo-image-manipulator'; @@ -61,6 +61,7 @@ import {navigateToNotification} from '~/features/push/provider'; import {useLocale} from '~/hooks/useLocale'; import {useAdRuntime} from '~/features/ads/provider'; import {uploadFile} from '~/features/media/upload'; +import {otaUpdatesEnabled} from '~/features/runtime/coldStartUpdate'; import { hasCameraAccess, hasPhotoPickerAccess, @@ -1297,14 +1298,28 @@ export function OpsScreen(): ReactElement { export function DiagnosticsScreen(): ReactElement { const {theme} = useCPK(); const [rows, setRows] = useState(() => diagnosticSnapshot()); + // Hash of the Patch update in this process; null on the store build's bundle. + const [updateHash, setUpdateHash] = useState(null); + useEffect(() => { + if (!otaUpdatesEnabled) return; + let active = true; + void Patch.getRunningBundleUpdateMetadata() + .then((running) => { + if (active) setUpdateHash(running?.packageHash ?? null); + }) + .catch(() => undefined); + return () => { + active = false; + }; + }, []); const bundle = { schemaVersion: 1, appVersion, build: Constants.nativeBuildVersion ?? 'unknown', platform: Platform.OS, osMajor: String(Platform.Version).split('.')[0] ?? 'unknown', - updateIdPrefix: Updates.updateId?.slice(0, 8) ?? null, - updatesEnabled: Updates.isEnabled, + updateIdPrefix: updateHash?.slice(0, 8) ?? null, + updatesEnabled: otaUpdatesEnabled, rows, } as const; return ( diff --git a/src/features/runtime/coldStartUpdate.tsx b/src/features/runtime/coldStartUpdate.tsx index 64d0bda..10a0ee3 100644 --- a/src/features/runtime/coldStartUpdate.tsx +++ b/src/features/runtime/coldStartUpdate.tsx @@ -1,5 +1,5 @@ -import {useEffect, useRef, useState} from 'react'; -import * as Updates from 'expo-updates'; +import {useEffect, useState} from 'react'; +import * as Patch from '@codemagic/react-native-patch'; import {diagnostic} from '~/features/diagnostics/ring'; import {Storage, storage} from '~/utils/storage'; @@ -34,6 +34,7 @@ const timeout = async (ms: number): Promise<'TIMEOUT'> => async function runSequence( deps: ColdStartUpdateDeps, + timedOut: () => boolean, ): Promise { let result: {isAvailable: boolean}; try { @@ -49,6 +50,9 @@ async function runSequence( diagnostic({kind: 'UPDATE', outcome: 'DOWNLOAD_FAILED'}); return 'FAILED'; } + // Past the budget the splash is gone and the user may be mid-entry, so the + // staged update waits for the next cold start instead of restarting now. + if (timedOut()) return 'TIMEOUT'; // `reload` restarts the app, so this promise normally never settles. The // caller keeps holding the splash until the process is replaced. await deps.reload(); @@ -65,7 +69,14 @@ export async function applyColdStartUpdate( ): Promise { if (!deps.isEnabled) return 'DISABLED'; const budget = deps.timeoutMs ?? COLD_START_UPDATE_TIMEOUT_MS; - const outcome = await Promise.race([runSequence(deps), timeout(budget)]); + let expired = false; + const outcome = await Promise.race([ + runSequence(deps, () => expired), + timeout(budget).then((value) => { + expired = true; + return value; + }), + ]); return outcome; } @@ -74,29 +85,39 @@ export const coldStartUpdateHoldsSplash = ( ): boolean => outcome === null || outcome === 'APPLIED'; /** - * expo-updates checks and downloads on load by default, so the runtime can - * stage an update on its own — and when it wins that race our explicit - * `checkForUpdate` reports nothing available while the OLD bundle keeps - * running. Martie covers this with an unconditional `isUpdatePending` reload. - * BooKoo reloads only while the splash is still up: after first paint the user - * may be mid-entry, and `SoftUpdateSheet` asks before taking their input away. + * Over-the-air updates come from Codemagic Patch. Development builds load their + * bundle from Metro, so Patch has nothing to replace there. */ -export const shouldReloadForPendingUpdate = ( - isUpdatePending: boolean, - outcome: ColdStartUpdateOutcome | null, - elapsedSinceMountMs: number, - budgetMs: number = COLD_START_UPDATE_TIMEOUT_MS, -): boolean => { - if (!isUpdatePending) return false; - // A reload is already replacing the process. - if (outcome === 'APPLIED') return false; - // Still holding the splash, or close enough to launch that nothing the user - // typed can be lost. `NONE` belongs here: the explicit check reports nothing - // available precisely because the runtime already staged the newer bundle. - return ( - coldStartUpdateHoldsSplash(outcome) || elapsedSinceMountMs < budgetMs - ); -}; +export const otaUpdatesEnabled = !__DEV__; + +/** + * Patch dependencies for one cold start. The check result is kept between the + * calls so `fetchUpdate` stages exactly the package `checkForUpdate` found. + * An `embedded-revert` answer means the server withdrew every update for this + * binary; staging it returns the app to the bundle that shipped in the store + * build. + */ +export function patchColdStartDeps(): ColdStartUpdateDeps { + let found: Patch.UpdateCheckResult | null = null; + return { + isEnabled: otaUpdatesEnabled, + checkForUpdate: async () => { + found = await Patch.checkForUpdate(); + return {isAvailable: found.action !== 'up-to-date'}; + }, + fetchUpdate: async () => { + if (found === null || found.action === 'up-to-date') return; + const target = + found.action === 'ota-update' + ? await Patch.downloadUpdate(found.remotePackage) + : found; + await Patch.installUpdate(target, { + installMode: Patch.InstallMode.ON_NEXT_RESTART, + }); + }, + reload: () => Patch.restartApp(), + }; +} /** * True while the native splash must stay up. Cold start is the only moment an @@ -105,34 +126,20 @@ export const shouldReloadForPendingUpdate = ( * user may be mid-entry. */ export function useColdStartUpdate(): boolean { - const {isUpdatePending} = Updates.useUpdates(); const [outcome, setOutcome] = useState(null); - // Mirrors `outcome` without re-running the effects that read it. - const outcomeRef = useRef(null); - const mountedAtRef = useRef(null); useEffect(() => { let active = true; - mountedAtRef.current = Date.now(); - const settle = (value: ColdStartUpdateOutcome): void => { - outcomeRef.current = value; - setOutcome(value); - }; - void applyColdStartUpdate({ - isEnabled: Updates.isEnabled, - checkForUpdate: () => Updates.checkForUpdateAsync(), - fetchUpdate: () => Updates.fetchUpdateAsync(), - reload: () => Updates.reloadAsync(), - }) + // `SoftUpdateSheet` can mount while the splash is still up and checks on + // mount too. Recording the attempt before it starts lets that sheet's 24h + // throttle skip a second, concurrent download of the same package. + if (otaUpdatesEnabled) storage.set(Storage.LastOtaCheckAt, Date.now()); + void applyColdStartUpdate(patchColdStartDeps()) .then((value) => { - // `SoftUpdateSheet` checks on mount too. Recording the attempt lets its - // 24h throttle swallow the duplicate request right after a cold start. - if (value !== 'DISABLED') - storage.set(Storage.LastOtaCheckAt, Date.now()); - if (active) settle(value); + if (active) setOutcome(value); }) .catch(() => { - if (active) settle('FAILED'); + if (active) setOutcome('FAILED'); }); return () => { active = false; @@ -140,21 +147,13 @@ export function useColdStartUpdate(): boolean { }, []); useEffect(() => { - const settle = (value: ColdStartUpdateOutcome): void => { - outcomeRef.current = value; - setOutcome(value); - }; - if ( - !shouldReloadForPendingUpdate( - isUpdatePending, - outcomeRef.current, - Date.now() - (mountedAtRef.current ?? Date.now()), - ) - ) + // Patch rolls a freshly installed update back on the next launch unless the + // running bundle reports itself healthy. Reaching the first paint is that + // proof; a reload already under way belongs to the next bundle instead. + if (!otaUpdatesEnabled || outcome === null || outcome === 'APPLIED') return; - settle('APPLIED'); - void Updates.reloadAsync().catch(() => settle('FAILED')); - }, [isUpdatePending]); + void Patch.notifyAppReady().catch(() => undefined); + }, [outcome]); return coldStartUpdateHoldsSplash(outcome); } diff --git a/src/features/runtime/softUpdate.tsx b/src/features/runtime/softUpdate.tsx index 2b5eb1f..200ff25 100644 --- a/src/features/runtime/softUpdate.tsx +++ b/src/features/runtime/softUpdate.tsx @@ -10,7 +10,7 @@ import { } from 'react-native'; import {useQuery} from 'convex-helpers/react/cache'; import * as Application from 'expo-application'; -import * as Updates from 'expo-updates'; +import * as Patch from '@codemagic/react-native-patch'; import {Button, Typography, useCPK} from 'cpk-ui'; import {usePathname} from 'expo-router'; @@ -19,6 +19,7 @@ import {diagnostic} from '~/features/diagnostics/ring'; import {t} from '~/utils/i18n'; import {Storage, storage} from '~/utils/storage'; import {compareSemver} from './boot'; +import {otaUpdatesEnabled, patchColdStartDeps} from './coldStartUpdate'; const OTA_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; const SOFT_DISMISSAL_MS = 7 * 24 * 60 * 60 * 1000; @@ -88,7 +89,7 @@ export function SoftUpdateSheet(): ReactElement | null { }, [latest, mountedAt]); useEffect(() => { - if (!Updates.isEnabled) return; + if (!otaUpdatesEnabled) return; let active = true; let checking = false; const check = (): void => { @@ -97,10 +98,12 @@ export function SoftUpdateSheet(): ReactElement | null { if (checking || now - last < OTA_CHECK_INTERVAL_MS) return; checking = true; storage.set(Storage.LastOtaCheckAt, now); - void Updates.checkForUpdateAsync() + const ota = patchColdStartDeps(); + void ota + .checkForUpdate() .then(async (result) => { if (!active || !result.isAvailable) return; - await Updates.fetchUpdateAsync(); + await ota.fetchUpdate(); if (active) setOtaReady(true); }) .catch(() => { @@ -135,7 +138,7 @@ export function SoftUpdateSheet(): ReactElement | null {