AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
perf(release): parallelize Play delivery
tianma-if81933658a26d
diff --git a/.github/workflows/release-timings.yml b/.github/workflows/release-timings.ymlindex 1a09b7c7..e91dbcfc 100644--- a/.github/workflows/release-timings.yml+++ b/.github/workflows/release-timings.yml@@ -37,6 +37,10 @@ on:description: "Draft GHCR preparation Run ID"required: truetype: string+ store_run_id:+ description: "Google Play delivery Run ID when Android was rebuilt"+ required: false+ type: stringpermissions:actions: read@@ -163,6 +167,7 @@ jobs:DESKTOP_RUN_ID: ${{ inputs.desktop_run_id }}DOCKER_RUN_ID: ${{ inputs.docker_run_id }}MOBILE_RUN_ID: ${{ inputs.mobile_run_id }}+ STORE_RUN_ID: ${{ inputs.store_run_id }}TCR_RUN_ID: ${{ steps.release.outputs.tcr_run_id }}run: |collect_run() {@@ -179,6 +184,9 @@ jobs:collect_run desktop "$DESKTOP_RUN_ID"collect_run mobile "$MOBILE_RUN_ID"collect_run docker "$DOCKER_RUN_ID"+ if [[ -n "$STORE_RUN_ID" ]]; then+ collect_run store "$STORE_RUN_ID"+ ficollect_run cloudflare "$DEMO_RUN_ID"collect_run tcr-source "$TCR_RUN_ID"@@ -188,6 +196,10 @@ jobs:TCR_READY_AT: ${{ steps.tcr.outputs.ready_at }}TCR_STATUS: ${{ steps.tcr.outputs.status }}run: |+ store_args=()+ if [[ -f "$RUNNER_TEMP/store.json" ]]; then+ store_args=(--store "$RUNNER_TEMP/store.json")+ finode scripts/report-release-timings.mjs \--tag "${{ inputs.release_tag }}" \--sha "${{ inputs.release_sha }}" \@@ -198,6 +210,7 @@ jobs:--mobile "$RUNNER_TEMP/mobile.json" \--mobile-mode "${{ inputs.mobile_mode }}" \--docker "$RUNNER_TEMP/docker.json" \+ "${store_args[@]}" \--cloudflare "$RUNNER_TEMP/cloudflare.json" \--tcr-source "$RUNNER_TEMP/tcr-source.json" \--tcr-ready-at "$TCR_READY_AT" \diff --git a/.github/workflows/store-delivery.yml b/.github/workflows/store-delivery.ymlindex c6e5efa3..14d159b5 100644--- a/.github/workflows/store-delivery.yml+++ b/.github/workflows/store-delivery.yml@@ -166,9 +166,15 @@ jobs:- name: Install dependenciesif: ${{ !inputs.recover_play_apk }}- run: >-- bun install --frozen-lockfile- --cache-dir "$RUNNER_TEMP/edgeever-bun-cache-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"+ run: |+ for attempt in 1 2 3; do+ if bun install --frozen-lockfile \+ --cache-dir "$RUNNER_TEMP/edgeever-bun-cache-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${attempt}"; then+ exit 0+ fi+ echo "Dependency install failed on attempt ${attempt}/3" >&2+ done+ exit 1- name: Install Play APK recovery dependencyif: ${{ inputs.recover_play_apk }}diff --git a/scripts/release.mjs b/scripts/release.mjsindex 3bf2d4be..4ab08a2f 100644--- a/scripts/release.mjs+++ b/scripts/release.mjs@@ -25,6 +25,7 @@ export const RELEASE_WORKFLOWS = {desktop: "desktop-build.yml",mobile: "mobile-build.yml",androidPlaySignature: "android-play-signature-audit.yml",+ storeDelivery: "store-delivery.yml",docker: "docker-image.yml",demo: "deploy-demo.yml",timings: "release-timings.yml",@@ -624,11 +625,134 @@ const listWorkflowRuns = ({ repository, workflow, event }) => ghJson(["databaseId,displayTitle,headSha,createdAt,url,status,conclusion",]);+const releaseCheckpointMarker = (tag) =>+ `<!-- edgeever-release-checkpoint:${tag}\n`;++export const parseReleaseCheckpoint = (body, tag) => {+ const marker = releaseCheckpointMarker(tag);+ if (!body?.startsWith(marker)) return null;+ const jsonEnd = body.lastIndexOf("\n-->");+ if (jsonEnd <= marker.length) return null;+ try {+ return JSON.parse(body.slice(marker.length, jsonEnd));+ } catch {+ return null;+ }+};++const loadReleaseCheckpoint = ({ repository, issueNumber, tag }) => {+ const comments = ghJson([+ "api",+ `repos/${repository}/issues/${issueNumber}/comments?per_page=100`,+ ]);+ const comment = comments.find(({ body }) =>+ body?.startsWith(releaseCheckpointMarker(tag)),+ );+ return {+ commentId: comment?.id ?? null,+ state: parseReleaseCheckpoint(comment?.body, tag) ?? {},+ };+};++const saveReleaseCheckpoint = ({+ repository,+ issueNumber,+ tag,+ commentId,+ state,+}) => {+ const body = `${releaseCheckpointMarker(tag)}${JSON.stringify(state)}\n-->`;+ if (commentId) {+ run("gh", [+ "api",+ "--method",+ "PATCH",+ `repos/${repository}/issues/comments/${commentId}`,+ "--raw-field",+ `body=${body}`,+ ], { capture: true });+ return commentId;+ }+ const comment = ghJson([+ "api",+ "--method",+ "POST",+ `repos/${repository}/issues/${issueNumber}/comments`,+ "--raw-field",+ `body=${body}`,+ ]);+ return comment.id;+};++const viewWorkflowRun = ({ repository, runId }) => ghJson([+ "run",+ "view",+ String(runId),+ "--repo",+ repository,+ "--json",+ "status,conclusion,url,headSha,jobs",+]);++const waitForRerunStart = async ({ repository, runId }) => {+ const deadline = Date.now() + 30_000;+ while (Date.now() < deadline) {+ const current = viewWorkflowRun({ repository, runId });+ if (current.status !== "completed" || current.conclusion === "success") return;+ await wait(2_000);+ }+ throw new Error(`Timed out waiting for rerun ${runId} to start.`);+};++export const draftRunResumeAction = ({ runId, runView, headSha }) => {+ if (!runId || !runView || runView.headSha !== headSha) return "dispatch";+ if (runView.status === "completed" && runView.conclusion !== "success") {+ return "rerun";+ }+ return "reuse";+};++const resumeDraftWorkflowRun = async ({ repository, runId, headSha, label }) => {+ if (!runId) return null;+ const existing = viewWorkflowRun({ repository, runId });+ const action = draftRunResumeAction({ runId, runView: existing, headSha });+ if (action === "dispatch") return null;+ if (action === "rerun") {+ console.log(`[release] rerunning failed ${label}: ${existing.url}`);+ run("gh", [+ "run",+ "rerun",+ String(runId),+ "--repo",+ repository,+ "--failed",+ ]);+ await waitForRerunStart({ repository, runId });+ } else {+ console.log(`[release] reusing ${label}: ${existing.url}`);+ }+ return Number(runId);+};++export const playDeliveryFailureStrategy = (runView) => {+ const androidJob = runView.jobs?.find(+ (job) => job.name === "Deliver Google Play",+ );+ const uploadStep = androidJob?.steps?.find(+ (step) => step.name === "Upload bundle to Google Play",+ );+ if (!uploadStep || ["skipped", null, undefined].includes(uploadStep.conclusion)) {+ return "rerun";+ }+ return "recover";+};+const dispatchReleaseWorkflow = async ({repository,workflow,tag,headSha,+ inputs = { release_tag: tag },}) => {const existingRunIds = new Set(listWorkflowRuns({@@ -646,8 +770,10 @@ const dispatchReleaseWorkflow = async ({repository,"--ref","main",- "-f",- `release_tag=${tag}`,+ ...Object.entries(inputs).flatMap(([key, value]) => [+ "-f",+ `${key}=${value}`,+ ]),], { capture: true });const returnedRunId = parseRunId(output);if (returnedRunId) {@@ -673,6 +799,155 @@ const dispatchReleaseWorkflow = async ({throw new Error(`Timed out discovering dispatched ${workflow} run for ${tag}.`);};+const dispatchStoreDeliveryWorkflow = ({+ repository,+ tag,+ headSha,+ recoverPlayApk,+}) => dispatchReleaseWorkflow({+ repository,+ workflow: RELEASE_WORKFLOWS.storeDelivery,+ tag,+ headSha,+ inputs: {+ release_tag: tag,+ platform: "android",+ android_track: "production",+ recover_play_apk: recoverPlayApk,+ },+});++const dispatchAndWaitForPlayRecovery = async ({+ repository,+ tag,+ headSha,+ checkpoint,+ persistCheckpoint,+}) => {+ const recoveryRunId = await dispatchStoreDeliveryWorkflow({+ repository,+ tag,+ headSha,+ recoverPlayApk: true,+ });+ checkpoint.storeRecoveryRunId = recoveryRunId;+ persistCheckpoint();+ await waitForRun({+ repository,+ runId: recoveryRunId,+ label: "Recover Play-signed Draft APK",+ });+ return recoveryRunId;+};++const ensurePlayDelivery = async ({+ repository,+ tag,+ headSha,+ checkpoint,+ persistCheckpoint,+}) => {+ let storeRunId = checkpoint.storeRunId;+ if (!storeRunId) {+ storeRunId = await dispatchStoreDeliveryWorkflow({+ repository,+ tag,+ headSha,+ recoverPlayApk: false,+ });+ checkpoint.storeRunId = storeRunId;+ persistCheckpoint();+ } else {+ const existing = viewWorkflowRun({ repository, runId: storeRunId });+ if (existing.headSha !== headSha) {+ throw new Error("Stored Play delivery Run targets a different commit.");+ }+ console.log(`[release] reusing Google Play delivery: ${existing.url}`);+ }++ try {+ await waitForRun({+ repository,+ runId: storeRunId,+ label: "Google Play delivery",+ });+ return storeRunId;+ } catch (error) {+ const failedRun = viewWorkflowRun({ repository, runId: storeRunId });+ if (playDeliveryFailureStrategy(failedRun) === "recover") {+ console.log(+ "[release] Play upload may have completed; recovering its signed APK without re-uploading",+ );+ await dispatchAndWaitForPlayRecovery({+ repository,+ tag,+ headSha,+ checkpoint,+ persistCheckpoint,+ });+ return storeRunId;+ }++ console.log("[release] Play upload did not start; dispatching a clean delivery retry");+ storeRunId = await dispatchStoreDeliveryWorkflow({+ repository,+ tag,+ headSha,+ recoverPlayApk: false,+ });+ checkpoint.storeRunId = storeRunId;+ persistCheckpoint();+ await waitForRun({+ repository,+ runId: storeRunId,+ label: "Google Play delivery retry",+ });+ return storeRunId;+ }+};++const requirePlaySignedDraftApk = async ({+ repository,+ tag,+ headSha,+ checkpoint,+ persistCheckpoint,+ allowRecovery,+}) => {+ const dispatchGate = async () => {+ const runId = await dispatchReleaseWorkflow({+ repository,+ workflow: RELEASE_WORKFLOWS.androidPlaySignature,+ tag,+ headSha,+ });+ checkpoint.androidPlaySignatureRunId = runId;+ persistCheckpoint();+ await waitForRun({+ repository,+ runId,+ label: "Draft Android Play signature gate",+ });+ };++ try {+ await dispatchGate();+ } catch (error) {+ if (!allowRecovery) throw error;+ console.log(+ "[release] restoring the already delivered Play-signed APK before retrying its signature gate",+ );+ await dispatchAndWaitForPlayRecovery({+ repository,+ tag,+ headSha,+ checkpoint,+ persistCheckpoint,+ });+ await dispatchGate();+ }+};+const findReleaseRun = async ({repository,workflow,@@ -1013,42 +1288,89 @@ const releaseMain = async (options) => {console.log(`[release] Draft created: ${draftUrl}`);}- const [desktopRunId, mobileRunId, dockerRunId] = await Promise.all([- dispatchReleaseWorkflow({+ const storedCheckpoint = loadReleaseCheckpoint({+ repository: options.repository,+ issueNumber,+ tag,+ });+ let checkpointCommentId = storedCheckpoint.commentId;+ const checkpoint =+ storedCheckpoint.state.releaseSha === releaseSha+ ? storedCheckpoint.state+ : { releaseSha };+ const persistCheckpoint = () => {+ checkpointCommentId = saveReleaseCheckpoint({repository: options.repository,- workflow: RELEASE_WORKFLOWS.desktop,+ issueNumber,tag,- headSha: releaseSha,- }),- dispatchReleaseWorkflow({+ commentId: checkpointCommentId,+ state: checkpoint,+ });+ };+ persistCheckpoint();++ const resolveDraftRun = async (field, workflow, label) => {+ const reusableRunId = resumedDraft+ ? await resumeDraftWorkflowRun({+ repository: options.repository,+ runId: checkpoint[field],+ headSha: releaseSha,+ label,+ })+ : null;+ return reusableRunId ?? dispatchReleaseWorkflow({repository: options.repository,- workflow: RELEASE_WORKFLOWS.mobile,+ workflow,tag,headSha: releaseSha,- }),- dispatchReleaseWorkflow({+ });+ };++ const [desktopRunId, mobileRunId, dockerRunId] = await Promise.all([+ resolveDraftRun("desktopRunId", RELEASE_WORKFLOWS.desktop, "Draft desktop assets"),+ resolveDraftRun("mobileRunId", RELEASE_WORKFLOWS.mobile, "Draft Android assets"),+ resolveDraftRun("dockerRunId", RELEASE_WORKFLOWS.docker, "Draft Docker image"),+ ]);+ Object.assign(checkpoint, { desktopRunId, mobileRunId, dockerRunId });+ persistCheckpoint();++ const androidReleaseReady = (async () => {+ await waitForRun({+ repository: options.repository,+ runId: mobileRunId,+ label: "Draft Android assets",+ });+ if (mobilePlan.rebuild) {+ await ensurePlayDelivery({+ repository: options.repository,+ tag,+ headSha: releaseSha,+ checkpoint,+ persistCheckpoint,+ });+ }+ await requirePlaySignedDraftApk({repository: options.repository,- workflow: RELEASE_WORKFLOWS.docker,tag,headSha: releaseSha,- }),- ]);+ checkpoint,+ persistCheckpoint,+ allowRecovery: mobilePlan.rebuild,+ });+ })();+await Promise.all([waitForRun({repository: options.repository,runId: desktopRunId,label: "Draft desktop assets",}),- waitForRun({- repository: options.repository,- runId: mobileRunId,- label: "Draft Android assets",- }),waitForRun({repository: options.repository,runId: dockerRunId,label: "Draft Docker image",}),+ androidReleaseReady,]);const draft = ghJson([@@ -1075,22 +1397,6 @@ const releaseMain = async (options) => {mobileRebuild: mobilePlan.rebuild,});- console.log(- `[release] requiring the Draft Android APK to use the Google Play app-signing certificate; ` +- `if this fails, run "bun run publish:stores -- --release ${tag} --platform android --android-track production" and resume the release.`,- );- const androidPlaySignatureRunId = await dispatchReleaseWorkflow({- repository: options.repository,- workflow: RELEASE_WORKFLOWS.androidPlaySignature,- tag,- headSha: releaseSha,- });- await waitForRun({- repository: options.repository,- runId: androidPlaySignatureRunId,- label: "Draft Android Play signature gate",- });-const publishedAt = Date.now();const releaseUrl = run("gh", ["release",@@ -1203,6 +1509,9 @@ const releaseMain = async (options) => {`mobile_mode=${mobilePlan.rebuild ? "rebuild" : "reuse"}`,"-f",`docker_run_id=${dockerRunId}`,+ ...(checkpoint.storeRunId+ ? ["-f", `store_run_id=${checkpoint.storeRunId}`]+ : []),], { allowFailure: true });if (timingDispatch.status === 0) {console.log(diff --git a/scripts/release.test.mjs b/scripts/release.test.mjsindex d447934c..3a0aa4c8 100644--- a/scripts/release.test.mjs+++ b/scripts/release.test.mjs@@ -6,8 +6,11 @@ import {buildReleaseNotes,buildReleaseSummary,buildReleaseTitle,+ draftRunResumeAction,nextVersion,+ parseReleaseCheckpoint,parseReleaseArgs,+ playDeliveryFailureStrategy,RELEASE_WORKFLOWS,RELEASE_VALIDATIONS,resolveReleaseVersion,@@ -27,6 +30,7 @@ describe("release automation", () => {expect(releaseSource).toContain("desktop_run_id=\${desktopRunId}");expect(releaseSource).toContain("mobile_run_id=\${mobileRunId}");expect(releaseSource).toContain("docker_run_id=\${dockerRunId}");+ expect(releaseSource).toContain("store_run_id=\${checkpoint.storeRunId}");expect(releaseSource).toContain("endpoint timing report continues in background");});@@ -40,6 +44,58 @@ describe("release automation", () => {expect(publication).toBeGreaterThan(signatureGate);});+ test("starts Play delivery as soon as Android preparation finishes", () => {+ const releaseSource = readFileSync(new URL("./release.mjs", import.meta.url), "utf8");+ const androidReady = releaseSource.lastIndexOf("const androidReleaseReady");+ const mobileWait = releaseSource.indexOf('label: "Draft Android assets"', androidReady);+ const playDelivery = releaseSource.indexOf("await ensurePlayDelivery", androidReady);+ const allDraftGates = releaseSource.indexOf("await Promise.all", androidReady);++ expect(RELEASE_WORKFLOWS.storeDelivery).toBe("store-delivery.yml");+ expect(mobileWait).toBeGreaterThan(androidReady);+ expect(playDelivery).toBeGreaterThan(mobileWait);+ expect(playDelivery).toBeLessThan(allDraftGates);+ });++ test("restores an exact Draft checkpoint without exposing it in Issue text", () => {+ const checkpoint = { releaseSha: "abc", desktopRunId: 123 };+ const body = `<!-- edgeever-release-checkpoint:v1.42.0\n${JSON.stringify(checkpoint)}\n-->`;+ expect(parseReleaseCheckpoint(body, "v1.42.0")).toEqual(checkpoint);+ expect(parseReleaseCheckpoint(body, "v1.42.1")).toBeNull();+ expect(parseReleaseCheckpoint("malformed", "v1.42.0")).toBeNull();+ });++ test("reuses successful Draft runs and reruns only failed ones", () => {+ const headSha = "abc";+ expect(draftRunResumeAction({+ runId: 1,+ runView: { headSha, status: "completed", conclusion: "success" },+ headSha,+ })).toBe("reuse");+ expect(draftRunResumeAction({+ runId: 2,+ runView: { headSha, status: "completed", conclusion: "failure" },+ headSha,+ })).toBe("rerun");+ expect(draftRunResumeAction({+ runId: 3,+ runView: { headSha: "different", status: "completed", conclusion: "success" },+ headSha,+ })).toBe("dispatch");+ });++ test("only retries a Play delivery when upload definitely did not start", () => {+ const run = (conclusion) => ({+ jobs: [{+ name: "Deliver Google Play",+ steps: [{ name: "Upload bundle to Google Play", conclusion }],+ }],+ });+ expect(playDeliveryFailureStrategy(run("skipped"))).toBe("rerun");+ expect(playDeliveryFailureStrategy(run("success"))).toBe("recover");+ expect(playDeliveryFailureStrategy(run("failure"))).toBe("recover");+ });+test("runs the complete project regression suite before release", () => {expect(RELEASE_VALIDATIONS).toContainEqual({label: "Project regression tests",diff --git a/scripts/report-release-timings.mjs b/scripts/report-release-timings.mjsindex 70088842..07e1df98 100644--- a/scripts/report-release-timings.mjs+++ b/scripts/report-release-timings.mjs@@ -139,6 +139,7 @@ export function createReleaseTimingReport({mobile,mobileMode,docker,+ store = null,cloudflare,tcrSource,tcrReadyAt,@@ -148,6 +149,12 @@ export function createReleaseTimingReport({const cloudflareStep = findStep(cloudflareJob, "Deploy Demo Worker");const dockerJob = findJob(docker, "Publish official multi-platform image");const dockerStep = findStep(dockerJob, "Build and publish image");+ const storeJob = store ? findJob(store, "Deliver Google Play") : null;+ const storeBuildStep = findStep(+ storeJob,+ "Build and verify signed Play bundle",+ );+ const storeUploadStep = findStep(storeJob, "Upload bundle to Google Play");const tcrSourceJob = findJob(tcrSource,"Trigger asynchronous Tencent-side image build",@@ -182,6 +189,18 @@ export function createReleaseTimingReport({},...nativeRows(desktop, "desktop", desktopMode),...nativeRows(mobile, "android", mobileMode),+ ...(storeJob+ ? [+ componentRow({+ target: "Google Play signed APK",+ mode: "build + deliver",+ candidate: storeJob,+ duration: jobDurationMs(storeJob),+ detail: `AAB build ${formatDuration(stepDurationMs(storeBuildStep))}; Play upload ${formatDuration(stepDurationMs(storeUploadStep))}`,+ url: storeJob.html_url ?? store.run.html_url,+ }),+ ]+ : []),];const publishedAt = timestamp(release.publishedAt);@@ -282,6 +301,7 @@ if (import.meta.main) {mobile: readJson(options.mobile),mobileMode: options["mobile-mode"],docker: readJson(options.docker),+ store: options.store ? readJson(options.store) : null,cloudflare: readJson(options.cloudflare),tcrSource: readJson(options["tcr-source"]),tcrReadyAt: options["tcr-ready-at"] || null,diff --git a/scripts/report-release-timings.test.mjs b/scripts/report-release-timings.test.mjsindex 4dc6e2eb..02470527 100644--- a/scripts/report-release-timings.test.mjs+++ b/scripts/report-release-timings.test.mjs@@ -57,6 +57,12 @@ describe("release timing report", () => {step("Build and publish image", start, 240),]),]),+ store: payload("Store", start, 660, [+ job("Deliver Google Play", start, 660, [+ step("Build and verify signed Play bundle", start, 180),+ step("Upload bundle to Google Play", start, 240),+ ]),+ ]),cloudflare: payload("Cloudflare", start, 120, [job("Build and deploy Demo Worker", start, 120, [step("Deploy Demo Worker", start, 60),@@ -78,6 +84,7 @@ describe("release timing report", () => {"macOS arm64","macOS x64","Android arm64",+ "Google Play signed APK",]);const markdown = renderReleaseTimingMarkdown(report);expect(markdown).toContain(@@ -89,6 +96,9 @@ describe("release timing report", () => {expect(markdown).toContain("| macOS x64 | rebuild | success | 10m 00s | package + notarize 5m 00s |",);+ expect(markdown).toContain(+ "| Google Play signed APK | build + deliver | success | 11m 00s | AAB build 3m 00s; Play upload 4m 00s |",+ );});test("reports reused native assets without pretending they were rebuilt", () => {diff --git a/scripts/store-delivery.test.mjs b/scripts/store-delivery.test.mjsindex 1cbb5476..b3393fe5 100644--- a/scripts/store-delivery.test.mjs+++ b/scripts/store-delivery.test.mjs@@ -48,6 +48,8 @@ describe("store delivery command", () => {);expect(workflow.match(/eas-version: 21\.4\.0/g)).toHaveLength(2);expect(workflow.match(/packager: npm/g)).toHaveLength(2);+ expect(workflow).toContain("for attempt in 1 2 3");+ expect(workflow).toContain("Dependency install failed on attempt ${attempt}/3");expect(workflow.match(/edgeever-bun-cache-\$\{GITHUB_RUN_ID\}-\$\{GITHUB_RUN_ATTEMPT\}/g,