Skip to content

Commit 2a098b1

Browse files
robingenzclaude
andauthored
feat: the Android core comes from its release asset, pinned by version and checksum (#29)
* feat: the Android core comes from its release asset, pinned by version and checksum The Android module took com.hotcodepush:core-android by full sha from core-android's maven branch, which every customer build read from raw.githubusercontent.com. It now takes the Maven-layout zip of the 0.1.0 release: package.json pins its version and SHA-256 under hotcodepush.coreAndroid, and scripts/download-core-android.mjs checks the checksum and unpacks it into an ignored local Maven repository that ships in the npm package. The script refuses a Gradle file that names another version than the pin, and the maven branch stays the development pin only. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * docs: the release asset is the path, not a stop on the way to Maven Central Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent b734dcc commit 2a098b1

7 files changed

Lines changed: 94 additions & 19 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ node_modules
66
android/src/main/java/com/hotcodepush/reactnative/SdkVersion.kt
77
ios/SdkVersion.swift
88

9-
# The core's XCFramework, downloaded by every build
9+
# The cores, downloaded by every build: the Maven repository of the Android core and the XCFramework
10+
android/libs
1011
ios/Frameworks
1112

1213
# iOS

‎CLAUDE.md‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ ios/ the Turbo Module (Objective-C
1515
android/src/main/java/com/hotcodepush/reactnative the Turbo Module, the runtime, the first-render listener, the bundle loader, the reader of the embedded bundle and the React host over com.hotcodepush:core-android
1616
android/src/test/java/com/hotcodepush/reactnative the Robolectric tests of the Android runtime and the Turbo Module, which verify:android runs
1717
android/settings.gradle the library's own build, which takes React Native's Gradle plugin and react-android's version from node_modules
18-
android/hotcodepush.gradle the task that runs binary create for every variant, and core-android's maven branch among `:app`'s repositories; applied by the app's build.gradle
18+
android/hotcodepush.gradle the task that runs binary create for every variant, and the package's local Maven repository among `:app`'s repositories; applied by the app's build.gradle
1919
scripts/binary-create-xcode.sh binary create as the app's Xcode phase runs it
20+
scripts/download-core-android.mjs the core's Maven-layout zip into the ignored android/libs/m2, which both Gradle scripts read
2021
scripts/download-core-ios.mjs the core's XCFramework into the ignored ios/Frameworks, which the pod vendors
2122
benchmarks/ the size and cold-start baseline, measured on the demo
2223
```
2324

24-
The native cores live in `core-ios` and `core-android`. `core-ios` is the XCFramework of a release: `package.json` pins its URL and checksum under `hotcodepush.coreIos`, and `scripts/download-core-ios.mjs` unpacks it into the ignored `ios/Frameworks` for the pod's `vendored_frameworks`, so the app's Podfile names no core. The Android library comes from core-android's `maven` branch by full sha in `android/build.gradle`; a core change lands there first and arrives here as a bump of both pins.
25+
The native cores live in `core-ios` and `core-android`. `core-ios` is the XCFramework of a release: `package.json` pins its URL and checksum under `hotcodepush.coreIos`, and `scripts/download-core-ios.mjs` unpacks it into the ignored `ios/Frameworks` for the pod's `vendored_frameworks`, so the app's Podfile names no core. The Android module is the Maven-layout zip of a release, `core-android-<version>-maven.zip`: `package.json` pins its version and the zip's SHA-256 under `hotcodepush.coreAndroid`, and `scripts/download-core-android.mjs` unpacks it into the ignored `android/libs/m2`, the local Maven repository that `android/build.gradle` and the app's `android/hotcodepush.gradle` read. A bump of the core is a new version in `package.json` and in `android/build.gradle`, which the script checks against each other, and the checksum from the summary of core-android's release job. core-android's `maven` branch, pinned by full sha, is the development pin only, for trying a core change before its release; a published build never names it.
2526
This package keeps what is React Native's: which bundle the host loads, the reload, the readiness signal and the bridge. Nothing of the protocol lives here.
2627

2728
## How the SDK meets React Native
@@ -37,14 +38,14 @@ This package keeps what is React Native's: which bundle the host loads, the relo
3738

3839
## Commands
3940

40-
| Command | Does |
41-
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42-
| `npm run lint` | ESLint, Prettier and SwiftLint |
43-
| `npm run typecheck` | TypeScript |
44-
| `npm test` | Vitest over the JavaScript |
45-
| `npm run build` | the TypeScript into `dist/`; writes the SDK version from `package.json` into `SdkVersion.swift` and `SdkVersion.kt` and downloads the core's XCFramework, all ignored, so a fresh checkout runs it before opening the native projects |
46-
| `npm run verify` | lint, typecheck, the Vitest tests and the build |
47-
| `npm run verify:android` | Gradle builds, lints and unit-tests the Android library on its own, Robolectric; needs a JDK and the Android SDK |
41+
| Command | Does |
42+
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
43+
| `npm run lint` | ESLint, Prettier and SwiftLint |
44+
| `npm run typecheck` | TypeScript |
45+
| `npm test` | Vitest over the JavaScript |
46+
| `npm run build` | the TypeScript into `dist/`; writes the SDK version from `package.json` into `SdkVersion.swift` and `SdkVersion.kt` and downloads the cores, the XCFramework and the Android Maven repository, all ignored, so a fresh checkout runs it before opening the native projects |
47+
| `npm run verify` | lint, typecheck, the Vitest tests and the build |
48+
| `npm run verify:android` | Gradle builds, lints and unit-tests the Android library on its own, Robolectric; needs a JDK and the Android SDK |
4849

4950
Run `npm run fmt` before every commit.
5051
The iOS code compiles only inside an app: `ci.yml` builds the demo with the package from the commit, packed after `npm run build` so the pod carries the core; `benchmarks/prepare-demo.mjs` drops a core pod line the demo's Podfile still pins. The Android library also builds on its own: `android/settings.gradle` resolves React Native from the devDependency, so Codegen runs on the host, and `verify:android` runs its Robolectric tests in their own `ci.yml` job.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ See [hotcodepush.com/docs/sdks/react-native](https://hotcodepush.com/docs/sdks/r
5757
```sh
5858
nvm use
5959
npm ci
60-
npm run build # the TypeScript into dist/ and the iOS core into ios/Frameworks; run it before opening the native projects
60+
npm run build # the TypeScript into dist/ and the cores into ios/Frameworks and android/libs; run it before opening the native projects
6161
npm test
6262
npm run lint && npm run typecheck
6363
npm run verify:android # the Android library's build and Robolectric tests

‎android/build.gradle‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ kotlin {
3535
}
3636
}
3737

38-
// The core comes from core-android's maven branch at a pinned commit until the library is on Maven Central.
38+
// The core comes from its release asset, which scripts/download-core-android.mjs unpacks into libs/m2.
3939
repositories {
4040
google()
4141
mavenCentral()
4242
maven {
43-
url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/'
43+
url = file('libs/m2')
4444
content { includeGroup 'com.hotcodepush' }
4545
}
4646
}
4747

4848
dependencies {
4949
implementation 'com.facebook.react:react-android'
50-
implementation 'com.hotcodepush:core-android:a5bfc4aeede98739302f49510766a6f5decb9299'
50+
implementation 'com.hotcodepush:core-android:0.1.0'
5151
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2'
5252
testImplementation 'junit:junit:4.13.2'
5353
testImplementation 'org.mockito:mockito-core:5.20.0'

‎android/hotcodepush.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import javax.inject.Inject
55
import org.apache.tools.ant.taskdefs.condition.Os
66
import org.gradle.api.tasks.Optional
77

8-
// The app resolves the core from core-android's maven branch until the library is on Maven Central.
8+
// The app resolves the core from the package's local Maven repository beside this file.
99
repositories {
1010
maven {
11-
url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/'
11+
url = new File(buildscript.sourceFile.parentFile, 'libs/m2')
1212
content { includeGroup 'com.hotcodepush' }
1313
}
1414
}

‎package.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
"files": [
2929
"android/build.gradle",
3030
"android/hotcodepush.gradle",
31+
"android/libs/m2/",
3132
"android/src/main/",
3233
"dist/",
3334
"ios/",
3435
"!ios/Frameworks/HotCodePushCore.checksum",
3536
"scripts/",
3637
"!scripts/*.test.ts",
38+
"!scripts/download-core-android.mjs",
3739
"!scripts/download-core-ios.mjs",
3840
"!scripts/write-sdk-version.mjs",
3941
"src/",
@@ -42,14 +44,14 @@
4244
"HotcodepushReactNativeCodePush.podspec"
4345
],
4446
"scripts": {
45-
"build": "npm run clean && node scripts/write-sdk-version.mjs && node scripts/download-core-ios.mjs && tsc --project tsconfig.build.json",
47+
"build": "npm run clean && node scripts/write-sdk-version.mjs && node scripts/download-core-android.mjs && node scripts/download-core-ios.mjs && tsc --project tsconfig.build.json",
4648
"clean": "rimraf ./dist",
4749
"fmt": "eslint . --fix && prettier --write . && swiftlint --fix --quiet ios",
4850
"lint": "eslint . && prettier --check . && swiftlint lint --quiet --strict ios",
4951
"test": "vitest run",
5052
"typecheck": "tsc --noEmit",
5153
"verify": "npm run lint && npm run typecheck && npm test && npm run build",
52-
"verify:android": "node scripts/write-sdk-version.mjs && cd android && ./gradlew build --console=plain"
54+
"verify:android": "node scripts/write-sdk-version.mjs && node scripts/download-core-android.mjs && cd android && ./gradlew build --console=plain"
5355
},
5456
"codegenConfig": {
5557
"name": "HotCodePushSpec",
@@ -65,6 +67,10 @@
6567
}
6668
},
6769
"hotcodepush": {
70+
"coreAndroid": {
71+
"version": "0.1.0",
72+
"checksum": "7c9b91381c5c99bf9e2592fd14e912972f0bb8f3df1b0a3c340a75ca5ef3a65b"
73+
},
6874
"coreIos": {
6975
"url": "https://github.com/hotcodepush-team/core-ios/releases/download/0.3.0/HotCodePushCore.xcframework.zip",
7076
"checksum": "6d12e0613ce25748963f0ff492a6e33687a25bf291d94e2950d5b1867bbc3685"

‎scripts/download-core-android.mjs‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { execFileSync } from 'node:child_process';
2+
import { createHash } from 'node:crypto';
3+
import {
4+
existsSync,
5+
mkdirSync,
6+
readFileSync,
7+
rmSync,
8+
writeFileSync,
9+
} from 'node:fs';
10+
import { tmpdir } from 'node:os';
11+
import { dirname, join } from 'node:path';
12+
import { fileURLToPath } from 'node:url';
13+
14+
// Gradle cannot check a release asset's checksum before it resolves the core from it.
15+
// So every build fetches the release asset that package.json pins under hotcodepush.coreAndroid, checks its checksum and unpacks it into the ignored local Maven repository that android/build.gradle and android/hotcodepush.gradle name.
16+
17+
const packageDirectory = join(dirname(fileURLToPath(import.meta.url)), '..');
18+
const libsDirectory = join(packageDirectory, 'android/libs');
19+
const mavenDirectory = join(libsDirectory, 'm2');
20+
const checksumFile = join(libsDirectory, 'core-android.checksum');
21+
22+
const { version, checksum } =
23+
JSON.parse(readFileSync(join(packageDirectory, 'package.json'), 'utf8'))
24+
.hotcodepush?.coreAndroid ?? {};
25+
if (!version || !/^[0-9a-f]{64}$/.test(checksum ?? '')) {
26+
throw new Error(
27+
'package.json names no hotcodepush.coreAndroid with a version and a checksum',
28+
);
29+
}
30+
31+
const [, gradleVersion] =
32+
readFileSync(join(packageDirectory, 'android/build.gradle'), 'utf8').match(
33+
/'com\.hotcodepush:core-android:([^']+)'/,
34+
) ?? [];
35+
if (gradleVersion !== version) {
36+
throw new Error(
37+
`android/build.gradle names core-android ${gradleVersion}, package.json pins ${version}`,
38+
);
39+
}
40+
41+
if (
42+
existsSync(checksumFile) &&
43+
readFileSync(checksumFile, 'utf8') === checksum
44+
) {
45+
process.exit(0);
46+
}
47+
48+
const url = `https://github.com/hotcodepush-team/core-android/releases/download/${version}/core-android-${version}-maven.zip`;
49+
const response = await fetch(url);
50+
if (!response.ok) {
51+
throw new Error(`${url} answered ${response.status}`);
52+
}
53+
const archive = Buffer.from(await response.arrayBuffer());
54+
const actualChecksum = createHash('sha256').update(archive).digest('hex');
55+
if (actualChecksum !== checksum) {
56+
throw new Error(
57+
`${url} has the checksum ${actualChecksum}, package.json pins ${checksum}`,
58+
);
59+
}
60+
61+
const archiveFile = join(tmpdir(), `core-android-${checksum}.zip`);
62+
writeFileSync(archiveFile, archive);
63+
rmSync(libsDirectory, { recursive: true, force: true });
64+
mkdirSync(mavenDirectory, { recursive: true });
65+
execFileSync('unzip', ['-q', archiveFile, '-d', mavenDirectory]);
66+
rmSync(archiveFile);
67+
writeFileSync(checksumFile, checksum);

0 commit comments

Comments
 (0)