Skip to content

Commit 829646a

Browse files
Merge remote-tracking branch 'origin/main' into t3code/takeover-19339
2 parents 040c15a + bb4e4e7 commit 829646a

43 files changed

Lines changed: 2454 additions & 1564 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/scripts/mirror-play-apk.cjs‎

Lines changed: 109 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Mirrors the newest build on a Google Play track to a rolling GitHub
2-
// prerelease as a universal APK. Play generates and signs that APK from the
1+
// Publishes closed-testing betas, or downloads the internal APK for a normal
2+
// nightly release. Play generates and signs the APK from the
33
// uploaded bundle with the app signing key, so it carries the same signature
44
// as the Play Store install. Run by .github/workflows/mobile-android-apk.yml.
55
const { execFileSync } = require("node:child_process");
@@ -77,43 +77,57 @@ function gh(...args) {
7777

7878
function readRelease(tag) {
7979
try {
80-
return JSON.parse(gh("release", "view", tag, "--json", "assets,body"));
80+
return JSON.parse(gh("release", "view", tag, "--json", "assets,body,isDraft"));
8181
} catch {
8282
return undefined;
8383
}
8484
}
8585

86-
// Downloads the build's universal APK and uploads it, creating the release on
87-
// first use. Returns false when Play lists no universal APK, which happens
88-
// while it is still processing a fresh upload.
89-
async function uploadApk({ token, appUrl, build, tag, apkName, notes, title, release }) {
86+
// Download to a temporary directory so a failed request cannot leave a partial
87+
// APK among the release assets.
88+
async function downloadApk({ token, appUrl, build, apkName }) {
9089
const generated = await (
9190
await play(token, "GET", `${appUrl}/generatedApks/${build.versionCode}`)
9291
).json();
93-
// One entry per app signing key. More than one means a key rotation, so
94-
// fail rather than guess which signature testers should get.
9592
const universal = (generated.generatedApks ?? []).filter((entry) => entry.generatedUniversalApk);
96-
if (universal.length === 0) return false;
93+
if (universal.length === 0) return undefined;
9794
if (universal.length > 1) {
9895
throw new Error(`Play returned ${universal.length} universal APKs, one per signing key.`);
9996
}
10097
const { downloadId } = universal[0].generatedUniversalApk;
98+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "apk-"));
99+
const apkPath = path.join(directory, apkName);
100+
try {
101+
const download = await play(
102+
token,
103+
"GET",
104+
`${appUrl}/generatedApks/${build.versionCode}/downloads/${encodeURIComponent(downloadId)}:download?alt=media`,
105+
);
106+
await pipeline(Readable.fromWeb(download.body), fs.createWriteStream(apkPath));
107+
return apkPath;
108+
} catch (error) {
109+
fs.rmSync(directory, { recursive: true, force: true });
110+
throw error;
111+
}
112+
}
101113

102-
const apkPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "apk-")), apkName);
103-
const download = await play(
104-
token,
105-
"GET",
106-
`${appUrl}/generatedApks/${build.versionCode}/downloads/${encodeURIComponent(downloadId)}:download?alt=media`,
107-
);
108-
await pipeline(Readable.fromWeb(download.body), fs.createWriteStream(apkPath));
109-
114+
function publishBeta(tag, apkPath, notes, title) {
115+
const release = readRelease(tag);
116+
if (
117+
release &&
118+
!release.isDraft &&
119+
release.assets.some(
120+
(asset) =>
121+
asset.name === path.basename(apkPath) && asset.state === "uploaded" && asset.size > 0,
122+
)
123+
)
124+
return;
110125
if (!release) {
111-
// Prerelease with a non-v tag: release.yml, the desktop updater, the CLI,
112-
// and the marketing site's latest-release lookup all ignore it.
113126
gh(
114127
"release",
115128
"create",
116129
tag,
130+
"--draft",
117131
"--prerelease",
118132
"--latest=false",
119133
"--title",
@@ -122,106 +136,92 @@ async function uploadApk({ token, appUrl, build, tag, apkName, notes, title, rel
122136
notes,
123137
);
124138
}
125-
// --clobber replaces an asset a failed upload left behind.
126139
gh("release", "upload", tag, apkPath, "--clobber");
127-
return true;
140+
gh(
141+
"release",
142+
"edit",
143+
tag,
144+
"--draft=false",
145+
"--prerelease",
146+
"--latest=false",
147+
"--title",
148+
title,
149+
"--notes",
150+
notes,
151+
);
128152
}
129153

130154
async function main() {
131155
const packageName = requireEnv("PACKAGE_NAME");
132-
const tag = requireEnv("RELEASE_TAG");
133-
const title = "T3 Code for Android (testing)";
134-
const key = JSON.parse(requireEnv("GOOGLE_PLAY_SERVICE_ACCOUNT_JSON"));
135-
const summary = (line) =>
136-
process.env.GITHUB_STEP_SUMMARY &&
137-
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${line}\n`);
138-
139-
const token = await playAccessToken(key);
156+
const outputDirectory = process.env.APK_OUTPUT_DIR;
157+
const channel = outputDirectory ? "internal" : "beta";
158+
const track = outputDirectory ? "internal" : "alpha";
159+
const token = await playAccessToken(JSON.parse(requireEnv("GOOGLE_PLAY_SERVICE_ACCOUNT_JSON")));
140160
const appUrl = `${PLAY_API}/${packageName}`;
141-
let release = readRelease(tag);
142-
const assets = release?.assets ?? [];
143-
const sections = [];
144-
for (const { track, channel, label, stability } of [
145-
{
146-
track: "alpha",
147-
channel: "beta",
148-
label: "Beta",
149-
stability:
150-
"Promoted for wider testing. Recommended over internal builds, but may still contain bugs.",
151-
},
152-
{
153-
track: "internal",
154-
channel: "internal",
155-
label: "Internal",
156-
stability: "Newest, less-tested builds. May contain serious bugs.",
157-
},
158-
]) {
159-
const prefix = `t3code-android-${channel}-`;
160-
let available = assets.filter(
161-
(asset) => asset.name.startsWith(prefix) && asset.state === "uploaded" && asset.size > 0,
161+
const build = await newestTrackBuild(token, appUrl, track);
162+
if (!build) {
163+
console.log(`The ${track} track has no live release.`);
164+
return;
165+
}
166+
const safeName = build.versionName.replace(/[^0-9A-Za-z.]+/g, "-").replace(/^-|-$/g, "");
167+
const apkName = `t3code-android-${channel}-${safeName}-${build.versionCode}.apk`;
168+
const tag = outputDirectory ? undefined : requireEnv("RELEASE_TAG");
169+
const snapshotTag = `android-beta-${build.versionCode}`;
170+
const release = tag ? readRelease(tag) : undefined;
171+
const snapshot = tag ? readRelease(snapshotTag) : undefined;
172+
const hasApk = (value) =>
173+
value &&
174+
!value.isDraft &&
175+
value.assets.some(
176+
(asset) => asset.name === apkName && asset.state === "uploaded" && asset.size > 0,
162177
);
163-
const build = await newestTrackBuild(token, appUrl, track);
164-
if (build) {
165-
const safeName = build.versionName.replace(/[^0-9A-Za-z.]+/g, "-").replace(/^-|-$/g, "");
166-
const apkName = `${prefix}${safeName}-${build.versionCode}.apk`;
167-
const published = assets.some(
168-
(asset) => asset.name === apkName && asset.state === "uploaded" && asset.size > 0,
169-
);
170-
if (
171-
published ||
172-
(await uploadApk({
173-
token,
174-
appUrl,
175-
build,
176-
tag,
177-
apkName,
178-
notes: "Android testing APKs. Release notes are being updated.",
179-
title,
180-
release,
181-
}))
182-
) {
183-
release ??= { assets: [], body: "" };
184-
available = [{ name: apkName }];
185-
summary(`Published or verified \`${apkName}\` on \`${tag}\`.`);
186-
// Clean up only this track after its replacement is available. Retire
187-
// the legacy unlabelled APK when the beta replacement is published.
188-
for (const stale of assets) {
189-
const belongsToTrack =
190-
stale.name.startsWith(prefix) ||
191-
(track === "alpha" && /^t3code-android-(?!beta-|internal-).*\.apk$/.test(stale.name));
192-
if (belongsToTrack && stale.name.endsWith(".apk") && stale.name !== apkName) {
193-
gh("release", "delete-asset", tag, stale.name, "--yes");
194-
}
195-
}
196-
} else {
197-
summary(
198-
`Play is still processing the ${track} APK for ${build.versionCode}; keeping the previous download.`,
199-
);
178+
const pruneBetaAssets = () => {
179+
for (const stale of release?.assets ?? []) {
180+
if (stale.name.endsWith(".apk") && stale.name !== apkName) {
181+
gh("release", "delete-asset", tag, stale.name, "--yes");
200182
}
201183
}
202-
sections.push(
203-
`## ${label}`,
204-
"",
205-
stability,
206-
"",
207-
...available.map(
208-
(asset) =>
209-
`- [${asset.name}](https://github.com/${requireEnv("GH_REPO")}/releases/download/${tag}/${asset.name})`,
210-
),
211-
...(available.length ? [] : ["No APK available yet."]),
184+
};
185+
if (hasApk(release) && hasApk(snapshot)) {
186+
pruneBetaAssets();
187+
console.log(`${apkName} is already published.`);
188+
return;
189+
}
190+
const apkPath = await downloadApk({ token, appUrl, build, apkName });
191+
if (!apkPath) {
192+
console.log(`Play is still processing the ${track} APK for ${build.versionCode}.`);
193+
return;
194+
}
195+
try {
196+
if (outputDirectory) {
197+
fs.mkdirSync(outputDirectory, { recursive: true });
198+
const destination = path.join(outputDirectory, apkName);
199+
const temporary = `${destination}.tmp`;
200+
try {
201+
fs.copyFileSync(apkPath, temporary);
202+
fs.renameSync(temporary, destination);
203+
} finally {
204+
fs.rmSync(temporary, { force: true });
205+
}
206+
return;
207+
}
208+
const notes = [
209+
`T3 Code for Android beta, mirrored from Google Play closed testing. Build: ${build.versionName} (${build.versionCode}).`,
212210
"",
211+
"These builds have been promoted for wider testing, but may still contain bugs. The beta is optional; the store app also works with Nightly servers.",
212+
].join("\n");
213+
// Publish the versioned beta first, then advance the stable download page.
214+
// The build number makes retries and unchanged hourly checks idempotent.
215+
publishBeta(
216+
snapshotTag,
217+
apkPath,
218+
notes,
219+
`Android beta ${build.versionName} (${build.versionCode})`,
213220
);
214-
}
215-
if (!release) return;
216-
const notes = [
217-
"T3 Code Android APKs mirrored from Google Play. Only the newest available APK from each track is kept here.",
218-
"",
219-
...sections,
220-
]
221-
.join("\n")
222-
.trim();
223-
if (release.body.replace(/\r\n/g, "\n").trim() !== notes) {
224-
gh("release", "edit", tag, "--title", title, "--notes", notes);
221+
publishBeta(tag, apkPath, notes, "T3 Code for Android (beta)");
222+
pruneBetaAssets();
223+
} finally {
224+
fs.rmSync(path.dirname(apkPath), { recursive: true, force: true });
225225
}
226226
}
227227

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ jobs:
225225
- name: Test preview artifact validation
226226
run: python3 -B .github/scripts/stage-preview-bundle.test.py
227227

228-
- name: Test nightly release checks
228+
- name: Test release checks
229229
run: node --test .github/scripts/check-nightly-release.test.cjs
230230

231231
- name: Finish installing browser secret helper build libraries

‎.github/workflows/mobile-android-apk.yml‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
name: Mobile Android APK
22

3-
# Publishes the newest Alpha and internal-testing Android builds as a sideloadable APK
4-
# on the rolling "android-nightly" prerelease for users who can't join
5-
# the Play testing group. Play re-signs uploaded bundles with the app signing
6-
# key, so its universal APK matches the Play Store install and needs no signing
7-
# secrets here. EAS submits asynchronously (--no-wait), so this polls Play
8-
# instead of chaining off mobile-eas-production.yml; runs with nothing new exit
9-
# early.
3+
# Checks closed testing hourly. New beta builds get a versioned prerelease and
4+
# update the android-beta download page. Unchanged checks publish nothing.
105
on:
116
schedule:
127
# Avoid minute zero, when GitHub scheduled jobs are busiest.
@@ -19,14 +14,14 @@ concurrency:
1914

2015
jobs:
2116
mirror:
22-
name: Mirror Play APKs
17+
name: Mirror beta APK
2318
runs-on: blacksmith-2vcpu-ubuntu-2404
2419
timeout-minutes: 10
2520
permissions:
2621
contents: write
2722
env:
2823
PACKAGE_NAME: com.t3tools.t3code
29-
RELEASE_TAG: android-nightly
24+
RELEASE_TAG: android-beta
3025
steps:
3126
- id: credentials
3227
name: Check for Play credentials

‎.github/workflows/release.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,18 @@ jobs:
807807
merge-multiple: true
808808
path: release-assets
809809

810+
- name: Download internal Android APK for Nightly
811+
if: needs.preflight.outputs.release_channel == 'nightly'
812+
continue-on-error: true
813+
env:
814+
GOOGLE_PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
815+
PACKAGE_NAME: com.t3tools.t3code
816+
APK_OUTPUT_DIR: release-assets
817+
run: |
818+
if [ -n "$GOOGLE_PLAY_SERVICE_ACCOUNT_JSON" ]; then
819+
node .github/scripts/mirror-play-apk.cjs
820+
fi
821+
810822
# Installers verify archives against this file, so it is written from the
811823
# signed bytes that get uploaded, never from an earlier stage.
812824
- name: Write CLI archive checksums
@@ -888,6 +900,10 @@ jobs:
888900
echo 'release-assets/*.yml'
889901
fi
890902
echo 'release-assets/*.tar.gz'
903+
# Only list APKs when Play has a processed internal build available.
904+
for apk in release-assets/*.apk; do
905+
[[ -f "$apk" ]] && echo "$apk"
906+
done
891907
echo 'release-assets/SHA256SUMS'
892908
echo 'EOF'
893909
} >> "$GITHUB_OUTPUT"

‎apps/desktop/src/preview/DesktopBrowserHost.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as Schema from "effect/Schema";
2424
import * as Stream from "effect/Stream";
2525

2626
import { createCdpRelayConnection, type CdpRelayConnection } from "./CdpRelay.ts";
27+
import { sendPageCommand } from "./GuestInput.ts";
2728

2829
const encodeEvent = Schema.encodeSync(Schema.fromJsonString(DesktopBrowserEvent));
2930
const decodeCommand = Schema.decodeUnknownOption(Schema.fromJsonString(DesktopBrowserCommand));
@@ -115,7 +116,7 @@ export const make = Effect.gen(function* () {
115116
{
116117
send: (method, params, sessionId) =>
117118
sessionId === undefined
118-
? debuggee.sendCommand(method, params)
119+
? sendPageCommand(webContents, debuggee, method, params)
119120
: debuggee.sendCommand(method, params, sessionId),
120121
targetId: () =>
121122
debuggee

0 commit comments

Comments
 (0)