create-disposabl-app 0.14.7 → 0.14.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/disposabl.js +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/default/.github/scripts/mobile.sh +6 -3
- package/dist/templates/default/.github/scripts/release.sh +37 -2
- package/dist/templates/default/packages/tests/android-ota-artifacts.test.ts +325 -0
- package/dist/templates/default/packages/tests/android-ota-selection.test.ts +111 -0
- package/package.json +1 -1
package/dist/disposabl.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
8
8
|
import { Command, CommanderError } from "commander";
|
|
9
9
|
import * as p2 from "@clack/prompts";
|
|
10
10
|
// package.json
|
|
11
|
-
var version = "0.14.
|
|
11
|
+
var version = "0.14.9";
|
|
12
12
|
|
|
13
13
|
// ../disposabl-kit/platforms.ts
|
|
14
14
|
var platforms = [
|
|
@@ -67,7 +67,7 @@ artifact=android.apk
|
|
|
67
67
|
export artifact
|
|
68
68
|
for ((page=1; ; page++)); do
|
|
69
69
|
gh api "repos/$GH_REPO/releases?per_page=100&page=$page" > "$RUNNER_TEMP/releases.json"
|
|
70
|
-
jq --arg artifact "$artifact" --arg tag "$RELEASE_PREFIX-$CHANNEL-android" --arg
|
|
70
|
+
jq --arg artifact "$artifact" --arg tag "$RELEASE_PREFIX-$CHANNEL-android" --arg channel "$CHANNEL" '[.[] | select(.draft | not) | select(.tag_name == $tag or ($channel == "production" and (.tag_name | startswith($tag + "-")) and (.tag_name | ltrimstr($tag + "-") | test("^[0-9]+-[0-9]+$")))) | select(any(.assets[]; .name == $artifact))] | sort_by(.tag_name != $tag) | .[0] // {}' "$RUNNER_TEMP/releases.json" > "$RUNNER_TEMP/release.json"
|
|
71
71
|
if jq -e '.id' "$RUNNER_TEMP/release.json" > /dev/null || [[ $(jq length "$RUNNER_TEMP/releases.json") -lt 100 ]]; then break; fi
|
|
72
72
|
done
|
|
73
73
|
RUNTIME=$(bun x --no-install expo-updates runtimeversion:resolve --platform android --workflow managed | jq -er 'select(.fingerprintSources != null) | .runtimeVersion | select(test("^[a-f0-9]{40,64}$"))')
|
|
@@ -95,14 +95,17 @@ bun -e '
|
|
|
95
95
|
artifact=android.apk
|
|
96
96
|
mkdir -p dist/release
|
|
97
97
|
gh release download "$TAG" --pattern "$artifact" --dir dist/release
|
|
98
|
-
echo "$SHA dist/release/$artifact" | sha256sum
|
|
98
|
+
echo "$SHA dist/release/$artifact" | sha256sum -c -
|
|
99
99
|
cd apps/mobile
|
|
100
100
|
MANIFEST=$(manifest)
|
|
101
101
|
bun x --no-install expo export --platform android --output-dir dist/update
|
|
102
102
|
test "$(bun x --no-install expo-updates runtimeversion:resolve --platform android --workflow managed | jq -er .runtimeVersion)" = "$RUNTIME"
|
|
103
103
|
test "$(gh api "repos/$GH_REPO/$SOURCE_PATH" --jq 'if has("head") then (if .state == "open" then .head.sha else "closed" end) else .object.sha end')" = "$SOURCE"
|
|
104
104
|
bun x "$EAS_CLI" update --platform android --channel "$CHANNEL" --environment "$EAS_ENVIRONMENT" --skip-bundler --input-dir dist/update --message "$SOURCE" --non-interactive
|
|
105
|
-
jq --arg sha "$SHA" '. + {sha256: $sha, action: "update"}' <<< "$MANIFEST" > ../../dist/release/android.json
|
|
105
|
+
jq --arg sha "$SHA" --arg tag "$TAG" '. + {sha256: $sha, action: "update", sourceTag: $tag}' <<< "$MANIFEST" > ../../dist/release/android.json
|
|
106
|
+
# The trusted publisher retrieves this verified binary from its existing release.
|
|
107
|
+
# Actions only needs the new OTA metadata, not another copy of the same APK.
|
|
108
|
+
rm "../../dist/release/$artifact"
|
|
106
109
|
;;
|
|
107
110
|
android-build)
|
|
108
111
|
bash ../../.github/scripts/android-runner.sh check
|
|
@@ -51,10 +51,40 @@ for platform in android linux windows; do
|
|
|
51
51
|
check_source
|
|
52
52
|
tag="app-$CHANNEL-$platform"
|
|
53
53
|
if [[ "$CHANNEL" == production ]]; then tag+="-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"; fi
|
|
54
|
+
preserve_apk=false
|
|
55
|
+
if [[ "$platform" == android && ! -f "$directory/android.apk" ]]; then
|
|
56
|
+
source_tag=$(jq -er 'select(.action == "update") | .sourceTag | strings | select(length > 0)' "$directory/android.json")
|
|
57
|
+
base="app-$CHANNEL-android"
|
|
58
|
+
if [[ "$source_tag" != "$base" ]]; then
|
|
59
|
+
[[ "$CHANNEL" == production && "$source_tag" == "$base-"* && "${source_tag#"$base-"}" =~ ^[0-9]+-[0-9]+$ ]] || { echo 'Invalid Android source release'; exit 1; }
|
|
60
|
+
fi
|
|
61
|
+
gh api "repos/$GH_REPO/releases/tags/$source_tag" > "$RUNNER_TEMP/android-source.json"
|
|
62
|
+
ANDROID_MANIFEST="$directory/android.json" node --input-type=module -e '
|
|
63
|
+
import {readFileSync} from "node:fs";
|
|
64
|
+
const wanted = JSON.parse(readFileSync(process.env.ANDROID_MANIFEST, "utf8"));
|
|
65
|
+
const release = JSON.parse(readFileSync(`${process.env.RUNNER_TEMP}/android-source.json`, "utf8"));
|
|
66
|
+
const prior = JSON.parse(/<!-- android (\{[^\n]+\}) -->/.exec(release.body || "")?.[1] || "null");
|
|
67
|
+
const fields = ["channel", "projectId", "applicationId", "runtimeVersion", "sha256"];
|
|
68
|
+
if (release.draft !== false || !prior || wanted.channel !== process.env.CHANNEL
|
|
69
|
+
|| !/^[a-f0-9]{40,64}$/.test(wanted.runtimeVersion || "") || !/^[a-f0-9]{64}$/.test(wanted.sha256 || "")
|
|
70
|
+
|| !fields.every(k => typeof wanted[k] === "string" && wanted[k].trim() && prior[k] === wanted[k])
|
|
71
|
+
|| !release.assets?.some(a => a.name === "android.apk" && a.state === "uploaded" && a.size > 0 && a.digest === `sha256:${wanted.sha256}`)) {
|
|
72
|
+
throw new Error("Android source release does not match the OTA manifest.");
|
|
73
|
+
}
|
|
74
|
+
'
|
|
75
|
+
gh release download "$source_tag" --pattern android.apk --dir "$directory"
|
|
76
|
+
printf '%s %s\n' "$(jq -er .sha256 "$directory/android.json")" "$directory/android.apk" | sha256sum -c -
|
|
77
|
+
check_source
|
|
78
|
+
if [[ "$source_tag" == "$tag" ]]; then preserve_apk=true; fi
|
|
79
|
+
fi
|
|
54
80
|
printf 'Platform: %s\nSource: %s\n' "$platform" "$SOURCE" > "$RUNNER_TEMP/release-notes.md"
|
|
55
81
|
if [[ -f "$directory/android.json" ]]; then printf '<!-- android %s -->\n' "$(jq -c . "$directory/android.json")" >> "$RUNNER_TEMP/release-notes.md"; fi
|
|
56
82
|
if gh release view "$tag" --json assets,isDraft > "$RUNNER_TEMP/previous-release.json"; then
|
|
57
|
-
|
|
83
|
+
# --clobber deletes before uploading. Keep the verified source APK intact so
|
|
84
|
+
# a failed metadata upload can retry without losing its only stored binary.
|
|
85
|
+
assets=("$directory/"*)
|
|
86
|
+
if [[ "$preserve_apk" == true ]]; then assets=("$directory/android.json"); fi
|
|
87
|
+
gh release upload "$tag" "${assets[@]}" --clobber
|
|
58
88
|
while IFS= read -r asset; do
|
|
59
89
|
if [[ ! -f "$directory/$asset" ]]; then check_source; gh release delete-asset "$tag" "$asset" --yes; fi
|
|
60
90
|
done < <(jq -r '.assets[].name' "$RUNNER_TEMP/previous-release.json")
|
|
@@ -78,7 +108,12 @@ check_source() { test "$(gh api "repos/$GH_REPO/$SOURCE_PATH" --jq 'if has("head
|
|
|
78
108
|
check_source
|
|
79
109
|
for file in dist/release/*; do test -f "$file"; test -s "$file"; done
|
|
80
110
|
case "$PLATFORM" in
|
|
81
|
-
android)
|
|
111
|
+
android)
|
|
112
|
+
test -s dist/release/android.json
|
|
113
|
+
if [[ ! -s dist/release/android.apk ]]; then
|
|
114
|
+
jq -e '(.action == "update") and (.sourceTag | type == "string" and length > 0)' dist/release/android.json > /dev/null
|
|
115
|
+
fi
|
|
116
|
+
;;
|
|
82
117
|
ios) test -s dist/release/ios.ipa; test -s dist/release/ios.json ;;
|
|
83
118
|
linux) compgen -G 'dist/release/*.deb' > /dev/null; compgen -G 'dist/release/*.rpm' > /dev/null ;;
|
|
84
119
|
windows) compgen -G 'dist/release/*.exe' > /dev/null; compgen -G 'dist/release/*.nupkg' > /dev/null; test -s dist/release/RELEASES ;;
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import {
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
} from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
|
+
|
|
15
|
+
const script = resolve(import.meta.dirname, "../../.github/scripts/release.sh");
|
|
16
|
+
const binary = "verified native APK fixture";
|
|
17
|
+
const sha256 = createHash("sha256").update(binary).digest("hex");
|
|
18
|
+
const source = "a".repeat(40);
|
|
19
|
+
|
|
20
|
+
function publish(
|
|
21
|
+
options: { production?: boolean; native?: boolean; fault?: string } = {},
|
|
22
|
+
) {
|
|
23
|
+
const cwd = mkdtempSync(join(tmpdir(), "android-ota-artifacts-"));
|
|
24
|
+
try {
|
|
25
|
+
for (const path of ["bin", ".github/scripts", "artifacts/release-android"])
|
|
26
|
+
mkdirSync(join(cwd, path), { recursive: true });
|
|
27
|
+
const channel = options.production ? "production" : "pr-1";
|
|
28
|
+
const sourceTag = `app-${channel}-android${options.production ? "-8-1" : ""}`;
|
|
29
|
+
const manifest = {
|
|
30
|
+
channel,
|
|
31
|
+
projectId: "project",
|
|
32
|
+
applicationId: "app.fixture",
|
|
33
|
+
runtimeVersion: "b".repeat(40),
|
|
34
|
+
sha256,
|
|
35
|
+
action: options.native ? "build" : "update",
|
|
36
|
+
sourceTag,
|
|
37
|
+
};
|
|
38
|
+
const prior = { ...manifest };
|
|
39
|
+
if (options.fault === "runtime") prior.runtimeVersion = "c".repeat(40);
|
|
40
|
+
if (options.fault === "channel") prior.channel = "pr-2";
|
|
41
|
+
if (options.fault === "project") prior.projectId = "different";
|
|
42
|
+
if (options.fault === "application") prior.applicationId = "app.different";
|
|
43
|
+
if (options.fault === "tag") manifest.sourceTag = "app-pr-2-android";
|
|
44
|
+
writeFileSync(
|
|
45
|
+
join(cwd, "artifacts/release-android/android.json"),
|
|
46
|
+
JSON.stringify(manifest),
|
|
47
|
+
);
|
|
48
|
+
if (options.native)
|
|
49
|
+
writeFileSync(join(cwd, "artifacts/release-android/android.apk"), binary);
|
|
50
|
+
writeFileSync(
|
|
51
|
+
join(cwd, "fixture.json"),
|
|
52
|
+
JSON.stringify({
|
|
53
|
+
...options,
|
|
54
|
+
binary,
|
|
55
|
+
source,
|
|
56
|
+
sourceTag,
|
|
57
|
+
release: {
|
|
58
|
+
isDraft: options.fault === "draft",
|
|
59
|
+
draft: options.fault === "draft",
|
|
60
|
+
body: `<!-- android ${JSON.stringify(prior)} -->`,
|
|
61
|
+
assets:
|
|
62
|
+
options.fault === "missing"
|
|
63
|
+
? []
|
|
64
|
+
: [
|
|
65
|
+
{
|
|
66
|
+
name: "android.apk",
|
|
67
|
+
state: "uploaded",
|
|
68
|
+
size: binary.length,
|
|
69
|
+
digest: `sha256:${options.fault === "digest" ? "d".repeat(64) : sha256}`,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
writeFileSync(
|
|
76
|
+
join(cwd, "bin/gh"),
|
|
77
|
+
`#!${process.execPath}
|
|
78
|
+
import {readFileSync, writeFileSync, appendFileSync, existsSync} from "node:fs";
|
|
79
|
+
import {join} from "node:path";
|
|
80
|
+
const args = process.argv.slice(2);
|
|
81
|
+
const f = JSON.parse(readFileSync(process.env.FIXTURE, "utf8"));
|
|
82
|
+
appendFileSync("commands.jsonl", JSON.stringify(args) + "\\n");
|
|
83
|
+
if (args[0] === "api" && args[1].includes("/releases/tags/")) {
|
|
84
|
+
console.log(JSON.stringify(f.release));
|
|
85
|
+
} else if (args[0] === "api") {
|
|
86
|
+
console.log(args.includes("PATCH") ? "{}" : f.fault === "stale" || (f.fault === "stale-after-download" && existsSync("downloaded")) ? "stale" : f.source);
|
|
87
|
+
} else if (args[1] === "view") {
|
|
88
|
+
if (f.production && args[2] !== f.sourceTag) process.exit(1);
|
|
89
|
+
console.log(JSON.stringify(f.release));
|
|
90
|
+
} else if (args[1] === "download") {
|
|
91
|
+
if (f.fault === "download") process.exit(1);
|
|
92
|
+
writeFileSync(join(args[args.indexOf("--dir") + 1], "android.apk"), f.fault === "corrupt" ? "corrupt" : f.binary);
|
|
93
|
+
writeFileSync("downloaded", "yes");
|
|
94
|
+
} else if (args[1] === "upload" && f.fault === "upload-once" && !existsSync("upload-failed")) {
|
|
95
|
+
// gh --clobber removes the existing asset before an upload can fail.
|
|
96
|
+
if (args.some(a => a.endsWith("/android.apk"))) f.release.assets = [];
|
|
97
|
+
writeFileSync(process.env.FIXTURE, JSON.stringify(f));
|
|
98
|
+
writeFileSync("upload-failed", "yes");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
`,
|
|
102
|
+
{ mode: 0o755 },
|
|
103
|
+
);
|
|
104
|
+
writeFileSync(
|
|
105
|
+
join(cwd, ".github/scripts/disposabl.mjs"),
|
|
106
|
+
'import {writeFileSync} from "node:fs"; writeFileSync("reported", process.argv.slice(2).join(" "));',
|
|
107
|
+
);
|
|
108
|
+
const run = () =>
|
|
109
|
+
spawnSync("bash", [script, "release-publish"], {
|
|
110
|
+
cwd,
|
|
111
|
+
encoding: "utf8",
|
|
112
|
+
env: {
|
|
113
|
+
...process.env,
|
|
114
|
+
PATH: `${join(cwd, "bin")}:${process.env.PATH}`,
|
|
115
|
+
FIXTURE: join(cwd, "fixture.json"),
|
|
116
|
+
RUNNER_TEMP: cwd,
|
|
117
|
+
GH_REPO: "fixture/app",
|
|
118
|
+
SOURCE: source,
|
|
119
|
+
CHANNEL: channel,
|
|
120
|
+
PR: "1",
|
|
121
|
+
PRERELEASE: String(!options.production),
|
|
122
|
+
GITHUB_RUN_ID: "9",
|
|
123
|
+
GITHUB_RUN_ATTEMPT: "1",
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
let result = run();
|
|
127
|
+
if (options.fault === "upload-once") {
|
|
128
|
+
assert.notEqual(result.status, 0, "first upload must fail");
|
|
129
|
+
// A fresh publisher starts with only the metadata Actions artifact.
|
|
130
|
+
rmSync(join(cwd, "artifacts/release-android/android.apk"));
|
|
131
|
+
result = run();
|
|
132
|
+
}
|
|
133
|
+
const commands: string[][] = readFileSync(
|
|
134
|
+
join(cwd, "commands.jsonl"),
|
|
135
|
+
"utf8",
|
|
136
|
+
)
|
|
137
|
+
.trim()
|
|
138
|
+
.split("\n")
|
|
139
|
+
.map((line) => JSON.parse(line));
|
|
140
|
+
return {
|
|
141
|
+
status: result.status,
|
|
142
|
+
output: result.stdout + result.stderr,
|
|
143
|
+
commands,
|
|
144
|
+
};
|
|
145
|
+
} finally {
|
|
146
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
test("metadata-only OTA restores the verified APK for PR and production publication", () => {
|
|
151
|
+
for (const production of [false, true]) {
|
|
152
|
+
const result = publish({ production });
|
|
153
|
+
assert.equal(result.status, 0, result.output);
|
|
154
|
+
assert.equal(
|
|
155
|
+
result.commands.filter((args) => args[1] === "download").length,
|
|
156
|
+
1,
|
|
157
|
+
);
|
|
158
|
+
const published = result.commands.find(
|
|
159
|
+
(args) => args[1] === (production ? "create" : "upload"),
|
|
160
|
+
)!;
|
|
161
|
+
assert.equal(
|
|
162
|
+
published.includes("artifacts/release-android/android.apk"),
|
|
163
|
+
production,
|
|
164
|
+
);
|
|
165
|
+
assert.equal(
|
|
166
|
+
published[2],
|
|
167
|
+
production ? "app-production-android-9-1" : "app-pr-1-android",
|
|
168
|
+
);
|
|
169
|
+
assert.equal(
|
|
170
|
+
result.commands.some((args) => args[1] === "delete-asset"),
|
|
171
|
+
false,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("same-tag metadata upload failure preserves the source APK for a fresh retry", () => {
|
|
177
|
+
const result = publish({ fault: "upload-once" });
|
|
178
|
+
assert.equal(result.status, 0, result.output);
|
|
179
|
+
assert.equal(
|
|
180
|
+
result.commands.filter((args) => args[1] === "download").length,
|
|
181
|
+
2,
|
|
182
|
+
);
|
|
183
|
+
assert.equal(
|
|
184
|
+
result.commands.filter((args) => args[1] === "upload").length,
|
|
185
|
+
2,
|
|
186
|
+
);
|
|
187
|
+
assert.equal(
|
|
188
|
+
result.commands.some(
|
|
189
|
+
(args) =>
|
|
190
|
+
args[1] === "upload" &&
|
|
191
|
+
args.includes("artifacts/release-android/android.apk"),
|
|
192
|
+
),
|
|
193
|
+
false,
|
|
194
|
+
);
|
|
195
|
+
assert.equal(
|
|
196
|
+
result.commands.some((args) => args[1] === "delete-asset"),
|
|
197
|
+
false,
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("OTA reuse rejects mismatched, missing, corrupt and stale inputs before publication", () => {
|
|
202
|
+
for (const fault of [
|
|
203
|
+
"runtime",
|
|
204
|
+
"channel",
|
|
205
|
+
"project",
|
|
206
|
+
"application",
|
|
207
|
+
"tag",
|
|
208
|
+
"draft",
|
|
209
|
+
"missing",
|
|
210
|
+
"digest",
|
|
211
|
+
"corrupt",
|
|
212
|
+
"download",
|
|
213
|
+
"stale",
|
|
214
|
+
"stale-after-download",
|
|
215
|
+
]) {
|
|
216
|
+
const result = publish({ fault });
|
|
217
|
+
assert.notEqual(result.status, 0, fault);
|
|
218
|
+
assert.equal(
|
|
219
|
+
result.commands.some((args) =>
|
|
220
|
+
["upload", "create", "edit", "delete-asset"].includes(args[1]),
|
|
221
|
+
),
|
|
222
|
+
false,
|
|
223
|
+
fault,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("native builds still publish their supplied APK without reuse", () => {
|
|
229
|
+
const result = publish({ native: true });
|
|
230
|
+
assert.equal(result.status, 0, result.output);
|
|
231
|
+
assert.equal(
|
|
232
|
+
result.commands.some((args) => args[1] === "download"),
|
|
233
|
+
false,
|
|
234
|
+
);
|
|
235
|
+
assert.ok(
|
|
236
|
+
result.commands
|
|
237
|
+
.find((args) => args[1] === "upload")
|
|
238
|
+
?.includes("artifacts/release-android/android.apk"),
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("OTA build verifies bytes before EAS publication and transfers only metadata", () => {
|
|
243
|
+
for (const corrupt of [false, true]) {
|
|
244
|
+
const cwd = mkdtempSync(join(tmpdir(), "android-ota-build-"));
|
|
245
|
+
try {
|
|
246
|
+
for (const path of ["bin", "apps/mobile"])
|
|
247
|
+
mkdirSync(join(cwd, path), { recursive: true });
|
|
248
|
+
writeFileSync(
|
|
249
|
+
join(cwd, "bin/gh"),
|
|
250
|
+
`#!${process.execPath}
|
|
251
|
+
import {writeFileSync} from "node:fs";
|
|
252
|
+
import {join} from "node:path";
|
|
253
|
+
const args=process.argv.slice(2);
|
|
254
|
+
if(args[0]==="api") console.log(${JSON.stringify(source)});
|
|
255
|
+
else writeFileSync(join(args[args.indexOf("--dir")+1],"android.apk"),${JSON.stringify(corrupt ? "corrupt" : binary)});
|
|
256
|
+
`,
|
|
257
|
+
{ mode: 0o755 },
|
|
258
|
+
);
|
|
259
|
+
writeFileSync(
|
|
260
|
+
join(cwd, "bin/bun"),
|
|
261
|
+
`#!${process.execPath}
|
|
262
|
+
import {writeFileSync,mkdirSync} from "node:fs";
|
|
263
|
+
const args=process.argv.slice(2);
|
|
264
|
+
if(args.includes("config")) console.log(JSON.stringify({android:{package:"app.fixture"},extra:{eas:{projectId:"project"}}}));
|
|
265
|
+
else if(args.includes("runtimeversion:resolve")) console.log(JSON.stringify({runtimeVersion:"${"b".repeat(40)}"}));
|
|
266
|
+
else if(args.includes("export")) mkdirSync("dist/update",{recursive:true});
|
|
267
|
+
else if(args.includes("update")) writeFileSync("../../published-update","yes");
|
|
268
|
+
else process.exit(1);
|
|
269
|
+
`,
|
|
270
|
+
{ mode: 0o755 },
|
|
271
|
+
);
|
|
272
|
+
const env = {
|
|
273
|
+
...process.env,
|
|
274
|
+
PATH: `${join(cwd, "bin")}:${process.env.PATH}`,
|
|
275
|
+
TAG: "app-pr-1-android",
|
|
276
|
+
SHA: sha256,
|
|
277
|
+
RUNTIME: "b".repeat(40),
|
|
278
|
+
CHANNEL: "pr-1",
|
|
279
|
+
SOURCE: source,
|
|
280
|
+
GH_REPO: "fixture/app",
|
|
281
|
+
SOURCE_PATH: "pulls/1",
|
|
282
|
+
PLATFORM: "android",
|
|
283
|
+
EAS_CLI: "fixture-eas",
|
|
284
|
+
EAS_ENVIRONMENT: "preview",
|
|
285
|
+
RUNNER_TEMP: cwd,
|
|
286
|
+
};
|
|
287
|
+
const result = spawnSync(
|
|
288
|
+
"bash",
|
|
289
|
+
[
|
|
290
|
+
resolve(import.meta.dirname, "../../.github/scripts/mobile.sh"),
|
|
291
|
+
"expo-update",
|
|
292
|
+
],
|
|
293
|
+
{ cwd, env, encoding: "utf8" },
|
|
294
|
+
);
|
|
295
|
+
if (corrupt) {
|
|
296
|
+
assert.notEqual(result.status, 0);
|
|
297
|
+
assert.throws(() => readFileSync(join(cwd, "published-update")));
|
|
298
|
+
} else {
|
|
299
|
+
assert.equal(result.status, 0, result.stdout + result.stderr);
|
|
300
|
+
assert.equal(
|
|
301
|
+
readFileSync(join(cwd, "published-update"), "utf8"),
|
|
302
|
+
"yes",
|
|
303
|
+
);
|
|
304
|
+
assert.throws(() =>
|
|
305
|
+
readFileSync(join(cwd, "dist/release/android.apk")),
|
|
306
|
+
);
|
|
307
|
+
const file = join(cwd, "dist/release/android.json");
|
|
308
|
+
const manifest = JSON.parse(readFileSync(file, "utf8"));
|
|
309
|
+
assert.equal(manifest.sourceTag, env.TAG);
|
|
310
|
+
assert.equal(manifest.sha256, sha256);
|
|
311
|
+
assert.equal(
|
|
312
|
+
spawnSync("bash", [script, "verify-artifacts"], { cwd, env }).status,
|
|
313
|
+
0,
|
|
314
|
+
);
|
|
315
|
+
writeFileSync(file, JSON.stringify({ ...manifest, action: "build" }));
|
|
316
|
+
assert.notEqual(
|
|
317
|
+
spawnSync("bash", [script, "verify-artifacts"], { cwd, env }).status,
|
|
318
|
+
0,
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
} finally {
|
|
322
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
mkdtempSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
|
|
14
|
+
test("OTA selection accepts only source tags supported by the trusted publisher", () => {
|
|
15
|
+
for (const [channel, tag, reusable] of [
|
|
16
|
+
["pr-1", "app-pr-1-android", true],
|
|
17
|
+
["production", "app-production-android", true],
|
|
18
|
+
["production", "app-production-android-8-1", true],
|
|
19
|
+
["pr-1", "app-pr-1", false],
|
|
20
|
+
["production", "app-production", false],
|
|
21
|
+
["pr-1", "app-pr-1-android-8-1", false],
|
|
22
|
+
["production", "app-production-android-invalid", false],
|
|
23
|
+
["pr-1", "app-pr-2-android", false],
|
|
24
|
+
["pr-1", "app-pr-1-windows", false],
|
|
25
|
+
] as const) {
|
|
26
|
+
const cwd = mkdtempSync(join(tmpdir(), "android-ota-selection-"));
|
|
27
|
+
try {
|
|
28
|
+
mkdirSync(join(cwd, "bin"));
|
|
29
|
+
const runtime = "b".repeat(40);
|
|
30
|
+
const hash = "a".repeat(64);
|
|
31
|
+
const manifest = {
|
|
32
|
+
channel,
|
|
33
|
+
projectId: "project",
|
|
34
|
+
applicationId: "app.fixture",
|
|
35
|
+
runtimeVersion: runtime,
|
|
36
|
+
sha256: hash,
|
|
37
|
+
};
|
|
38
|
+
const release = {
|
|
39
|
+
id: 1,
|
|
40
|
+
tag_name: tag,
|
|
41
|
+
draft: false,
|
|
42
|
+
body: `<!-- android ${JSON.stringify(manifest)} -->`,
|
|
43
|
+
assets: [
|
|
44
|
+
{
|
|
45
|
+
name: "android.apk",
|
|
46
|
+
state: "uploaded",
|
|
47
|
+
size: 1,
|
|
48
|
+
digest: `sha256:${hash}`,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
writeFileSync(
|
|
53
|
+
join(cwd, "bin/gh"),
|
|
54
|
+
`#!${process.execPath}\nconsole.log(${JSON.stringify(JSON.stringify([release]))});\n`,
|
|
55
|
+
{ mode: 0o755 },
|
|
56
|
+
);
|
|
57
|
+
writeFileSync(
|
|
58
|
+
join(cwd, "bin/bun"),
|
|
59
|
+
`#!${process.execPath}
|
|
60
|
+
const args=process.argv.slice(2);
|
|
61
|
+
if(args[0]==="-e") {
|
|
62
|
+
const child=Bun.spawnSync([process.execPath,...args],{stdout:"inherit",stderr:"inherit"});
|
|
63
|
+
process.exit(child.exitCode);
|
|
64
|
+
}
|
|
65
|
+
if(args.includes("config")) console.log(JSON.stringify({android:{package:"app.fixture"},extra:{eas:{projectId:"project"}}}));
|
|
66
|
+
else if(args.includes("runtimeversion:resolve")) console.log(JSON.stringify({runtimeVersion:"${runtime}",fingerprintSources:[]}));
|
|
67
|
+
else process.exit(1);
|
|
68
|
+
`,
|
|
69
|
+
{ mode: 0o755 },
|
|
70
|
+
);
|
|
71
|
+
const output = join(cwd, "output");
|
|
72
|
+
const result = spawnSync(
|
|
73
|
+
"bash",
|
|
74
|
+
[
|
|
75
|
+
resolve(import.meta.dirname, "../../.github/scripts/mobile.sh"),
|
|
76
|
+
"expo-fingerprint",
|
|
77
|
+
],
|
|
78
|
+
{
|
|
79
|
+
cwd,
|
|
80
|
+
encoding: "utf8",
|
|
81
|
+
env: {
|
|
82
|
+
...process.env,
|
|
83
|
+
PATH: `${join(cwd, "bin")}:${process.env.PATH}`,
|
|
84
|
+
RUNNER_TEMP: cwd,
|
|
85
|
+
GH_REPO: "fixture/app",
|
|
86
|
+
CHANNEL: channel,
|
|
87
|
+
RELEASE_PREFIX: "app",
|
|
88
|
+
GITHUB_OUTPUT: output,
|
|
89
|
+
ANDROID_SIGNING_READY: "true",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
assert.equal(
|
|
94
|
+
result.status,
|
|
95
|
+
0,
|
|
96
|
+
`${tag}: ${result.stdout}${result.stderr}`,
|
|
97
|
+
);
|
|
98
|
+
const selected = readFileSync(output, "utf8");
|
|
99
|
+
assert.ok(
|
|
100
|
+
selected.includes(`build=${!reusable}\n`),
|
|
101
|
+
`${tag}: ${selected}`,
|
|
102
|
+
);
|
|
103
|
+
assert.ok(
|
|
104
|
+
selected.includes(`tag=${reusable ? tag : ""}\n`),
|
|
105
|
+
`${tag}: ${selected}`,
|
|
106
|
+
);
|
|
107
|
+
} finally {
|
|
108
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|