Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore(desktop): make canary releases recoverable after a failed upload (#22312)

YuTengjing240912e02efe
diff --git a/.github/actions/desktop-publish-s3/action.yml b/.github/actions/desktop-publish-s3/action.yml
index 8fe0abd9bbe..e44b027649f 100644
--- a/.github/actions/desktop-publish-s3/action.yml
+++ b/.github/actions/desktop-publish-s3/action.yml
@@ -39,7 +39,7 @@ outputs:
value: ${{ steps.base.outputs.published }}
installers-published:
description: Whether installer files and manifests were uploaded
- value: ${{ steps.installers.outputs.published }}
+ value: ${{ steps.manifests.outputs.published }}
runs:
using: composite
@@ -100,6 +100,53 @@ runs:
'{shellAbi: $shellAbi, shellVersion: $shellVersion, publishedAt: $publishedAt}' > release/shell.json
cat release/shell.json
+ # Installers go up before the core and shell.json: until shell.json lands, clients and later
+ # core-only runs keep targeting the previous shell, so a failed installer upload leaves nothing
+ # half-published and the job can simply be re-run.
+ - name: Upload installers to S3
+ id: installers
+ if: inputs.upload-release-files == 'true' && inputs.s3-bucket != ''
+ shell: bash
+ env:
+ AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
+ AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }}
+ AWS_REGION: ${{ inputs.s3-region }}
+ S3_BUCKET: ${{ inputs.s3-bucket }}
+ S3_ENDPOINT: ${{ inputs.s3-endpoint }}
+ CHANNEL: ${{ inputs.channel }}
+ VERSION: ${{ inputs.version }}
+ run: |
+ set -euo pipefail
+ ENDPOINT_ARGS=()
+ if [ -n "$S3_ENDPOINT" ]; then
+ ENDPOINT_ARGS=(--endpoint-url "$S3_ENDPOINT")
+ echo "📡 Using custom S3 endpoint: $S3_ENDPOINT"
+ fi
+ # aws s3 cp retries individual requests, but not a whole multipart upload: R2 can reject
+ # CompleteMultipartUpload with InvalidPart after every part succeeded, which failed the
+ # 2.3.2-canary.2 dmg upload (https://github.com/lobehub/lobehub/actions/runs/41944676897).
+ # Retrying the file starts a fresh multipart upload.
+ s3_cp() {
+ local attempt
+ for attempt in 1 2 3; do
+ aws s3 cp "$@" "${ENDPOINT_ARGS[@]}" && return 0
+ [ "$attempt" -lt 3 ] || break
+ echo "::warning::aws s3 cp $1 failed (attempt $attempt/3); retrying in $((attempt * 15))s"
+ sleep $((attempt * 15))
+ done
+ echo "::error::aws s3 cp $1 failed after 3 attempts"
+ return 1
+ }
+
+ echo "📦 Uploading release files to s3://$S3_BUCKET/$CHANNEL/$VERSION/"
+ for file in release/*.dmg release/*.zip release/*.exe release/*.AppImage release/*.deb release/*.rpm release/*.snap release/*.tar.gz release/*.blockmap; do
+ if [ -f "$file" ]; then
+ filename=$(basename "$file")
+ echo " ↗️ $filename"
+ s3_cp "$file" "s3://$S3_BUCKET/$CHANNEL/$VERSION/$filename"
+ fi
+ done
+
- name: Publish shell.json and r0 core
id: base
uses: ./.github/actions/desktop-publish-core-ota
@@ -115,8 +162,10 @@ runs:
s3-region: ${{ inputs.s3-region }}
s3-endpoint: ${{ inputs.s3-endpoint }}
- - name: Upload to S3
- id: installers
+ # The manifests are what electron-updater clients poll, so they go up last, once both the
+ # installers they point at and the new shell's core exist.
+ - name: Publish installer manifests to S3
+ id: manifests
if: inputs.upload-release-files == 'true'
shell: bash
env:
@@ -135,30 +184,28 @@ runs:
exit 0
fi
- # 构建端点参数
- ENDPOINT_ARG=""
+ ENDPOINT_ARGS=()
if [ -n "$S3_ENDPOINT" ]; then
- ENDPOINT_ARG="--endpoint-url $S3_ENDPOINT"
- echo "📡 Using custom S3 endpoint: $S3_ENDPOINT"
+ ENDPOINT_ARGS=(--endpoint-url "$S3_ENDPOINT")
fi
+ # aws s3 cp retries individual requests, but not a whole multipart upload: R2 can reject
+ # CompleteMultipartUpload with InvalidPart after every part succeeded, which failed the
+ # 2.3.2-canary.2 dmg upload (https://github.com/lobehub/lobehub/actions/runs/41944676897).
+ # Retrying the file starts a fresh multipart upload.
+ s3_cp() {
+ local attempt
+ for attempt in 1 2 3; do
+ aws s3 cp "$@" "${ENDPOINT_ARGS[@]}" && return 0
+ [ "$attempt" -lt 3 ] || break
+ echo "::warning::aws s3 cp $1 failed (attempt $attempt/3); retrying in $((attempt * 15))s"
+ sleep $((attempt * 15))
+ done
+ echo "::error::aws s3 cp $1 failed after 3 attempts"
+ return 1
+ }
- echo "🚀 Uploading to S3 bucket: $S3_BUCKET"
- echo "📁 Target path: s3://$S3_BUCKET/$CHANNEL/"
- echo ""
-
- # 1. 上传安装包到版本目录
- echo "📦 Uploading release files to s3://$S3_BUCKET/$CHANNEL/$VERSION/"
- for file in release/*.dmg release/*.zip release/*.exe release/*.AppImage release/*.deb release/*.rpm release/*.snap release/*.tar.gz release/*.blockmap; do
- if [ -f "$file" ]; then
- filename=$(basename "$file")
- echo " ↗️ $filename"
- aws s3 cp "$file" "s3://$S3_BUCKET/$CHANNEL/$VERSION/$filename" $ENDPOINT_ARG
- fi
- done
-
- # 2. stable 渠道补充 stable*.yml
+ # 1. stable 渠道补充 stable*.yml
# electron-builder 对稳定版默认生成 latest*.yml
- echo ""
if [ "$CHANNEL" = "stable" ]; then
echo "📋 Creating stable*.yml from latest*.yml..."
for yml in release/latest*.yml; do
@@ -170,7 +217,7 @@ runs:
done
fi
- # 3. 为所有 yml manifest 的 URL 加版本目录前缀
+ # 2. 为所有 yml manifest 的 URL 加版本目录前缀
# merge-mac-files 步骤已生成 {channel}*.yml (如 canary-mac.yml)
# 安装包在 s3://$BUCKET/$CHANNEL/$VERSION/ 下,URL 需加 $VERSION/ 前缀
echo ""
@@ -182,7 +229,7 @@ runs:
fi
done
- # 4. 上传 installer manifest 到根目录和版本目录
+ # 3. 上传 installer manifest 到根目录和版本目录
# 根目录: electron-updater 需要,每次发版覆盖
# 版本目录: 作为存档保留
echo ""
@@ -191,9 +238,9 @@ runs:
if [ -f "$yml" ]; then
filename=$(basename "$yml")
echo " ↗️ $filename -> s3://$S3_BUCKET/$CHANNEL/$filename"
- aws s3 cp "$yml" "s3://$S3_BUCKET/$CHANNEL/$filename" $ENDPOINT_ARG
+ s3_cp "$yml" "s3://$S3_BUCKET/$CHANNEL/$filename"
echo " ↗️ $filename -> s3://$S3_BUCKET/$CHANNEL/$VERSION/$filename (archive)"
- aws s3 cp "$yml" "s3://$S3_BUCKET/$CHANNEL/$VERSION/$filename" $ENDPOINT_ARG
+ s3_cp "$yml" "s3://$S3_BUCKET/$CHANNEL/$VERSION/$filename"
fi
done
@@ -202,10 +249,10 @@ runs:
echo "✅ S3 upload completed!"
echo ""
echo "📋 Files in s3://$S3_BUCKET/$CHANNEL/:"
- aws s3 ls "s3://$S3_BUCKET/$CHANNEL/" $ENDPOINT_ARG || true
+ aws s3 ls "s3://$S3_BUCKET/$CHANNEL/" "${ENDPOINT_ARGS[@]}" || true
echo ""
echo "📋 Files in s3://$S3_BUCKET/$CHANNEL/$VERSION/:"
- aws s3 ls "s3://$S3_BUCKET/$CHANNEL/$VERSION/" $ENDPOINT_ARG || true
+ aws s3 ls "s3://$S3_BUCKET/$CHANNEL/$VERSION/" "${ENDPOINT_ARGS[@]}" || true
- name: Preserve release publication diagnostics
if: always()
diff --git a/.github/scripts/desktop-publish-s3.test.mjs b/.github/scripts/desktop-publish-s3.test.mjs
new file mode 100644
index 00000000000..2e4e8115082
--- /dev/null
+++ b/.github/scripts/desktop-publish-s3.test.mjs
@@ -0,0 +1,90 @@
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import os from 'node:os';
+import path from 'node:path';
+import { test } from 'node:test';
+
+import { parse } from 'yaml';
+
+const loadSteps = async () =>
+ parse(
+ await readFile(new URL('../actions/desktop-publish-s3/action.yml', import.meta.url), 'utf8'),
+ ).runs.steps;
+
+/** A fake `aws` that fails its first FAIL_TIMES calls the way R2 rejected the 2.3.2-canary.2 dmg. */
+const FAKE_AWS = `#!/usr/bin/env node
+const fs = require('fs');
+const count = (fs.existsSync(process.env.AWS_COUNT) ? Number(fs.readFileSync(process.env.AWS_COUNT, 'utf8')) : 0) + 1;
+fs.writeFileSync(process.env.AWS_COUNT, String(count));
+fs.appendFileSync(process.env.AWS_CALLS, JSON.stringify(process.argv.slice(2)) + '\\n');
+if (count <= Number(process.env.FAIL_TIMES || 0)) {
+ console.error('An error occurred (InvalidPart) when calling the CompleteMultipartUpload operation');
+ process.exit(1);
+}
+`;
+
+const runInstallers = async (root, script, failTimes) => {
+ const calls = path.join(root, `calls-${failTimes}.jsonl`);
+ const result = spawnSync('bash', ['-e', '-o', 'pipefail', '-c', script], {
+ cwd: root,
+ encoding: 'utf8',
+ env: {
+ ...process.env,
+ AWS_CALLS: calls,
+ AWS_COUNT: path.join(root, `count-${failTimes}`),
+ CHANNEL: 'canary',
+ FAIL_TIMES: String(failTimes),
+ PATH: `${path.join(root, 'bin')}:${process.env.PATH}`,
+ S3_BUCKET: 'fixture',
+ S3_ENDPOINT: 'https://r2.example',
+ VERSION: '2.3.2-canary.2',
+ },
+ });
+ const uploads = (await readFile(calls, 'utf8')).trim().split('\n').map(JSON.parse);
+ return { result, uploads };
+};
+
+test('installers upload before the core and shell.json, manifests only after them', async () => {
+ const ids = (await loadSteps()).map((step) => step.id);
+ const at = (id) => ids.indexOf(id);
+ assert.ok(at('installers') !== -1 && at('base') !== -1 && at('manifests') !== -1);
+ assert.ok(at('installers') < at('base'), 'installers must precede the core publish');
+ assert.ok(at('base') < at('manifests'), 'manifests must follow the core publish');
+});
+
+test('an installer upload rejected by R2 is retried as a whole file, up to three attempts', async () => {
+ const root = await mkdtemp(path.join(os.tmpdir(), 'desktop-publish-s3-'));
+ try {
+ await mkdir(path.join(root, 'bin'));
+ await mkdir(path.join(root, 'release'));
+ await writeFile(path.join(root, 'bin/aws'), FAKE_AWS);
+ // Skip the real backoff so the test stays fast.
+ await writeFile(path.join(root, 'bin/sleep'), '#!/bin/sh\nexit 0\n');
+ await chmod(path.join(root, 'bin/aws'), 0o755);
+ await chmod(path.join(root, 'bin/sleep'), 0o755);
+ await writeFile(path.join(root, 'release/LobeHub-2.3.2-canary.2-arm64.dmg'), 'dmg');
+ const { run } = (await loadSteps()).find((step) => step.id === 'installers');
+ const target = 's3://fixture/canary/2.3.2-canary.2/LobeHub-2.3.2-canary.2-arm64.dmg';
+
+ const recovered = await runInstallers(root, run, 2);
+ assert.equal(recovered.result.status, 0, recovered.result.stderr);
+ assert.equal(recovered.uploads.length, 3);
+ for (const args of recovered.uploads)
+ assert.deepEqual(args, [
+ 's3',
+ 'cp',
+ 'release/LobeHub-2.3.2-canary.2-arm64.dmg',
+ target,
+ '--endpoint-url',
+ 'https://r2.example',
+ ]);
+
+ const exhausted = await runInstallers(root, run, 3);
+ assert.notEqual(exhausted.result.status, 0);
+ assert.equal(exhausted.uploads.length, 3);
+ assert.match(exhausted.result.stdout, /failed after 3 attempts/);
+ } finally {
+ await rm(root, { force: true, recursive: true });
+ }
+});
diff --git a/.github/scripts/release-desktop-canary.test.mjs b/.github/scripts/release-desktop-canary.test.mjs
new file mode 100644
index 00000000000..098245a1590
--- /dev/null
+++ b/.github/scripts/release-desktop-canary.test.mjs
@@ -0,0 +1,51 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import { test } from 'node:test';
+
+import { parse } from 'yaml';
+
+const loadJobs = async () =>
+ parse(await readFile(new URL('../workflows/release-desktop-canary.yml', import.meta.url), 'utf8'))
+ .jobs;
+
+const needsOf = (job) => [job.needs ?? []].flat();
+
+test('a force_full run reaches every release job although core-ota is skipped', async () => {
+ const jobs = await loadJobs();
+ assert.match(String(jobs['core-ota'].if), /!inputs\.force_full/);
+
+ // A skipped ancestor skips every job left on the default success() condition, so each job
+ // downstream of core-ota must state its own condition on its direct dependencies.
+ const downstream = new Set(['core-ota']);
+ let grew = true;
+ while (grew) {
+ grew = false;
+ for (const [id, job] of Object.entries(jobs)) {
+ if (!downstream.has(id) && needsOf(job).some((need) => downstream.has(need))) {
+ downstream.add(id);
+ grew = true;
+ }
+ }
+ }
+ downstream.delete('core-ota');
+ assert.ok(
+ downstream.has('build') && downstream.has('publish-s3') && downstream.has('publish-sparkle'),
+ );
+
+ for (const id of downstream) {
+ const condition = String(jobs[id].if ?? '');
+ assert.match(
+ condition,
+ /!cancelled\(\)/,
+ `${id} must not rely on the default success() condition`,
+ );
+ // calculate-version gates on check-trigger's outputs and core-ota's result itself.
+ if (id === 'calculate-version') continue;
+ for (const need of needsOf(jobs[id])) {
+ assert.ok(
+ condition.includes(`needs.${need}.result == 'success'`),
+ `${id} must require ${need} to have succeeded`,
+ );
+ }
+ }
+});
diff --git a/.github/workflows/release-desktop-canary.yml b/.github/workflows/release-desktop-canary.yml
index 85f003c0dff..6acf65ab114 100644
--- a/.github/workflows/release-desktop-canary.yml
+++ b/.github/workflows/release-desktop-canary.yml
@@ -254,6 +254,10 @@ jobs:
test:
name: Code quality check
needs: [calculate-version]
+ # force_full skips core-ota, and a skipped ancestor skips every job on the default
+ # success() condition, even when calculate-version itself succeeded. Each job below
+ # therefore checks its direct dependencies explicitly.
+ if: ${{ !cancelled() && needs.calculate-version.result == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout base
@@ -275,6 +279,7 @@ jobs:
# ============================================
build:
needs: [calculate-version, test]
+ if: ${{ !cancelled() && needs.calculate-version.result == 'success' && needs.test.result == 'success' }}
name: Build Desktop App
runs-on: ${{ matrix.os }}
strategy:
@@ -431,6 +436,7 @@ jobs:
# ============================================
merge-mac-files:
needs: [build]
+ if: ${{ !cancelled() && needs.build.result == 'success' }}
name: Merge macOS Release Files
runs-on: ubuntu-latest
permissions:
@@ -477,6 +483,7 @@ jobs:
# ============================================
publish-release:
needs: [merge-mac-files, calculate-version]
+ if: ${{ !cancelled() && needs.merge-mac-files.result == 'success' && needs.calculate-version.result == 'success' }}
name: Publish Canary Release
runs-on: ubuntu-latest
permissions:
@@ -522,6 +529,7 @@ jobs:
# ============================================
publish-s3:
needs: [merge-mac-files, calculate-version]
+ if: ${{ !cancelled() && needs.merge-mac-files.result == 'success' && needs.calculate-version.result == 'success' }}
name: Publish to S3
runs-on: ubuntu-latest
steps:
@@ -551,6 +559,7 @@ jobs:
# ============================================
publish-sparkle:
needs: [publish-s3, calculate-version]
+ if: ${{ !cancelled() && needs.publish-s3.result == 'success' && needs.calculate-version.result == 'success' }}
name: Publish Sparkle Appcast
runs-on: macos-15
steps:
@@ -581,6 +590,7 @@ jobs:
# ============================================
cleanup-old-canaries:
needs: [publish-release, publish-s3]
+ if: ${{ !cancelled() && needs.publish-release.result == 'success' && needs.publish-s3.result == 'success' }}
name: Cleanup Old Canary Releases
runs-on: ubuntu-latest
permissions:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 62a97ef133e..3ae6f519b96 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -82,6 +82,9 @@ jobs:
- name: Verify hotfix operator CLI
run: node --test .github/scripts/hotfixWorkflow.test.mjs
+ - name: Verify desktop release workflows
+ run: node --test .github/scripts/desktop-publish-s3.test.mjs .github/scripts/release-desktop-canary.test.mjs
+
- name: Test CLI build configuration, bundle and model-facing docs
run: bunx vitest run --config vitest.config.mts --silent='passed-only' tsdown.config.test.ts bundle.test.ts src/modelFacingDocs.test.ts
working-directory: apps/cli
diff --git a/apps/desktop/scripts/__tests__/reportRendererOta.test.mjs b/apps/desktop/scripts/__tests__/reportRendererOta.test.mjs
index 0ddaef14939..493a6411de4 100644
--- a/apps/desktop/scripts/__tests__/reportRendererOta.test.mjs
+++ b/apps/desktop/scripts/__tests__/reportRendererOta.test.mjs
@@ -99,6 +99,15 @@ describe('classifyResult', () => {
expect(
classifyResult({ base: { outcome: 'success', outputs: { published: 'true' } } }, 'release'),
).toMatchObject({ published: true });
+ expect(
+ classifyResult(
+ {
+ base: { outcome: 'success', outputs: { published: 'true' } },
+ manifests: { outcome: 'failure' },
+ },
+ 'release',
+ ),
+ ).toMatchObject({ outcome: 'failed', reason: 'installer-manifest-upload-failed' });
expect(
classifyResult(
{
diff --git a/apps/desktop/scripts/reportRendererOta.mjs b/apps/desktop/scripts/reportRendererOta.mjs
index 908424d5cd5..65b5286f71c 100644
--- a/apps/desktop/scripts/reportRendererOta.mjs
+++ b/apps/desktop/scripts/reportRendererOta.mjs
@@ -40,6 +40,7 @@ const stageMaps = {
installers: 'installer-upload-failed',
shell: 'shell-json-failed',
base: 'core-r0-upload-failed',
+ manifests: 'installer-manifest-upload-failed',
},
};