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.

👷 ci(release): fix README sync on tag checkout and retry macOS staple (#21155)

Lobehub Coderfd940ffd2437
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 50add8436cb..58917f07b6a 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -64,6 +64,30 @@ jobs:
- name: Test App
run: bun run test-app
+ sync-readme:
+ name: Sync README
+ needs: release
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/create-github-app-token@v2
+ id: app-token
+ with:
+ app-id: ${{ vars.LOBEHUB_BOT_APP_ID }}
+ private-key: ${{ secrets.LOBEHUB_BOT_APP_PRIVATE_KEY }}
+
+ # Tag checkouts are a detached HEAD, so commit the README onto canary instead.
+ - uses: actions/checkout@v7
+ with:
+ ref: canary
+ token: ${{ steps.app-token.outputs.token }}
+
+ - name: Setup environment
+ uses: ./.github/actions/setup-env
+
+ - name: Install deps
+ run: pnpm install
+
- name: Workflow
run: bun run workflow:readme
@@ -72,8 +96,8 @@ jobs:
git diff
git config --global user.name "lobehubbot"
git config --global user.email "[email protected]"
- git add .
+ git add README.md README.zh-CN.md
git commit -m "📝 docs(bot): Auto sync agents & plugin to readme" || exit 0
- git push
+ git push origin canary
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
diff --git a/apps/desktop/electron-builder.mjs b/apps/desktop/electron-builder.mjs
index 5f29131750b..36a59b54b59 100644
--- a/apps/desktop/electron-builder.mjs
+++ b/apps/desktop/electron-builder.mjs
@@ -21,6 +21,7 @@ import {
resolveComputerUseHelperVersion,
verifyComputerUseHelper,
} from './scripts/computerUseHelper.mjs';
+import { notarizeMacApp } from './scripts/notarizeMacApp.mjs';
import { packBuiltinCore } from './scripts/packBuiltinCore.mjs';
import { toSparkleBuildVersion } from './scripts/sparkleBuildVersion.mjs';
import { resolveSparklePackaging } from './scripts/sparklePackaging.mjs';
@@ -286,6 +287,12 @@ const config = {
{ version: computerUseHelperVersion },
);
console.info('✅ Computer Use helper kept its notarized signature');
+
+ if (hasAppleCertificate) {
+ await notarizeMacApp(
+ path.join(context.appOutDir, `${context.packager.appInfo.productFilename}.app`),
+ );
+ }
}
},
appId: macAppId,
@@ -398,7 +405,8 @@ const config = {
hardenedRuntime: hasAppleCertificate,
// Ship the notarized helper as built; re-signing drops its stapled ticket.
signIgnore: [COMPUTER_USE_HELPER_SIGN_IGNORE],
- notarize: hasAppleCertificate,
+ // Notarized in afterSign so a transient staple failure retries instead of failing the build.
+ notarize: false,
...(hasAppleCertificate ? {} : { identity: null }),
target: [
{ arch: [arch === 'arm64' ? 'arm64' : 'x64'], target: 'dmg' },
diff --git a/apps/desktop/scripts/__tests__/notarizeMacApp.test.mjs b/apps/desktop/scripts/__tests__/notarizeMacApp.test.mjs
new file mode 100644
index 00000000000..700f4c5226a
--- /dev/null
+++ b/apps/desktop/scripts/__tests__/notarizeMacApp.test.mjs
@@ -0,0 +1,101 @@
+import { describe, expect, it, vi } from 'vitest';
+
+import {
+ notarizeMacApp,
+ resolveNotaryCredentialArgs,
+ stapleWithRetry,
+} from '../notarizeMacApp.mjs';
+
+const logger = { info: vi.fn(), warn: vi.fn() };
+const appleIdEnv = {
+ APPLE_APP_SPECIFIC_PASSWORD: 'app-password',
+ APPLE_ID: '[email protected]',
+ APPLE_TEAM_ID: 'TEAM123',
+};
+
+const createExecute = ({ stapleFailures = 0, status = 'Accepted' } = {}) => {
+ let stapleCalls = 0;
+ return vi.fn((command, args) => {
+ if (command === 'xcrun' && args[0] === 'notarytool')
+ return JSON.stringify({ id: 'sub-1', status });
+ if (command === 'xcrun' && args[0] === 'stapler') {
+ stapleCalls += 1;
+ if (stapleCalls <= stapleFailures)
+ throw new Error('The staple and validate action failed! Error 68.');
+ }
+ return '';
+ });
+};
+
+describe('macOS notarization', () => {
+ it('resolves Apple ID and API key credentials', () => {
+ expect(resolveNotaryCredentialArgs(appleIdEnv)).toEqual([
+ '--apple-id',
+ '--password',
+ 'app-password',
+ '--team-id',
+ 'TEAM123',
+ ]);
+ expect(
+ resolveNotaryCredentialArgs({
+ APPLE_API_ISSUER: 'issuer',
+ APPLE_API_KEY: '/keys/AuthKey.p8',
+ APPLE_API_KEY_ID: 'KEY1',
+ }),
+ ).toEqual(['--key', '/keys/AuthKey.p8', '--key-id', 'KEY1', '--issuer', 'issuer']);
+ expect(resolveNotaryCredentialArgs({})).toBeNull();
+ expect(() => resolveNotaryCredentialArgs({ APPLE_ID: '[email protected]' })).toThrow();
+ });
+
+ it('retries stapling after a transient CloudKit failure instead of failing the build', async () => {
+ const execute = createExecute({ stapleFailures: 2 });
+ const wait = vi.fn();
+
+ await expect(stapleWithRetry('/build/LobeHub.app', { execute, logger, wait })).resolves.toBe(3);
+ expect(wait).toHaveBeenCalledTimes(2);
+ });
+
+ it('fails once every staple attempt is exhausted', async () => {
+ const execute = createExecute({ stapleFailures: 5 });
+
+ await expect(
+ stapleWithRetry('/build/LobeHub.app', { attempts: 3, execute, logger, wait: vi.fn() }),
+ ).rejects.toThrow('after 3 attempts');
+ });
+
+ it('submits once and staples after the notary accepts the app', async () => {
+ const execute = createExecute({ stapleFailures: 1 });
+
+ await expect(
+ notarizeMacApp('/build/LobeHub.app', {
+ environment: appleIdEnv,
+ execute,
+ logger,
+ staple: { wait: vi.fn() },
+ }),
+ ).resolves.toEqual({ notarized: true });
+
+ const submits = execute.mock.calls.filter(([, args]) => args[0] === 'notarytool');
+ expect(submits).toHaveLength(1);
+ expect(submits[0][1]).toEqual(expect.arrayContaining(['--wait', '--team-id', 'TEAM123']));
+ });
+
+ it('rejects a submission the notary did not accept', async () => {
+ const execute = createExecute({ status: 'Invalid' });
+
+ await expect(
+ notarizeMacApp('/build/LobeHub.app', { environment: appleIdEnv, execute, logger }),
+ ).rejects.toThrow('Apple notarization Invalid (submission sub-1)');
+ expect(execute.mock.calls.some(([, args]) => args[0] === 'stapler')).toBe(false);
+ });
+
+ it('skips notarization without credentials', async () => {
+ const execute = createExecute();
+
+ await expect(
+ notarizeMacApp('/build/LobeHub.app', { environment: {}, execute, logger }),
+ ).resolves.toEqual({ notarized: false });
+ expect(execute).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/scripts/notarizeMacApp.mjs b/apps/desktop/scripts/notarizeMacApp.mjs
new file mode 100644
index 00000000000..39b9d8ae739
--- /dev/null
+++ b/apps/desktop/scripts/notarizeMacApp.mjs
@@ -0,0 +1,102 @@
+import { execFileSync } from 'node:child_process';
+import fs from 'node:fs/promises';
+import os from 'node:os';
+import path from 'node:path';
+
+/**
+ * Notarize and staple a signed macOS app.
+ *
+ * Replaces electron-builder's built-in `notarize`, which fails the whole build when
+ * `stapler` cannot reach Apple's CloudKit ticket service (Error 68, NSURLErrorDomain -1005).
+ * The ticket already exists once notarytool accepts the submission, so stapling is retried
+ * instead of resubmitting.
+ */
+
+const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
+
+export const resolveNotaryCredentialArgs = (environment = process.env) => {
+ const { APPLE_ID, APPLE_APP_SPECIFIC_PASSWORD, APPLE_TEAM_ID } = environment;
+ if (APPLE_ID || APPLE_APP_SPECIFIC_PASSWORD) {
+ if (!APPLE_ID || !APPLE_APP_SPECIFIC_PASSWORD || !APPLE_TEAM_ID) {
+ throw new Error('APPLE_ID, APPLE_APP_SPECIFIC_PASSWORD and APPLE_TEAM_ID must all be set');
+ }
+ return [
+ '--apple-id',
+ APPLE_ID,
+ '--password',
+ APPLE_APP_SPECIFIC_PASSWORD,
+ '--team-id',
+ APPLE_TEAM_ID,
+ ];
+ }
+
+ const { APPLE_API_KEY, APPLE_API_KEY_ID, APPLE_API_ISSUER } = environment;
+ if (APPLE_API_KEY || APPLE_API_KEY_ID || APPLE_API_ISSUER) {
+ if (!APPLE_API_KEY || !APPLE_API_KEY_ID || !APPLE_API_ISSUER) {
+ throw new Error('APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER must all be set');
+ }
+ return ['--key', APPLE_API_KEY, '--key-id', APPLE_API_KEY_ID, '--issuer', APPLE_API_ISSUER];
+ }
+
+ return null;
+};
+
+export const stapleWithRetry = async (
+ appPath,
+ { attempts = 5, delayMs = 30_000, execute = execFileSync, logger = console, wait = sleep } = {},
+) => {
+ for (let attempt = 1; attempt <= attempts; attempt++) {
+ try {
+ execute('xcrun', ['stapler', 'staple', '-v', appPath], { encoding: 'utf8', stdio: 'pipe' });
+ logger.info(`✅ Stapled notarization ticket (attempt ${attempt}/${attempts})`);
+ return attempt;
+ } catch (error) {
+ if (attempt === attempts) {
+ throw new Error(`Failed to staple ${appPath} after ${attempts} attempts`, { cause: error });
+ }
+ logger.warn(
+ `⚠️ Staple attempt ${attempt}/${attempts} failed, retrying in ${delayMs / 1000}s`,
+ );
+ await wait(delayMs);
+ }
+ }
+};
+
+export const notarizeMacApp = async (
+ appPath,
+ { environment = process.env, execute = execFileSync, logger = console, staple = {} } = {},
+) => {
+ const credentialArgs = resolveNotaryCredentialArgs(environment);
+ if (!credentialArgs) {
+ logger.warn('⚠️ No Apple notarization credentials; macOS notarization skipped');
+ return { notarized: false };
+ }
+
+ const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'lobehub-notarize-'));
+ const zipPath = path.join(tempDir, `${path.basename(appPath, '.app')}.zip`);
+
+ try {
+ execute('ditto', ['-c', '-k', '--sequesterRsrc', '--keepParent', appPath, zipPath], {
+ stdio: 'inherit',
+ });
+ logger.info('• submitting app to Apple notary service…');
+ const output = execute(
+ 'xcrun',
+ ['notarytool', 'submit', zipPath, ...credentialArgs, '--wait', '--output-format', 'json'],
+ { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] },
+ );
+ // notarytool exits 0 for rejected submissions, so the status decides.
+ const { id, status } = JSON.parse(output);
+ if (status !== 'Accepted') {
+ throw new Error(
+ `Apple notarization ${status} (submission ${id}); run \`xcrun notarytool log ${id}\` for details`,
+ );
+ }
+ logger.info(`✅ Notarization accepted (submission ${id})`);
+ } finally {
+ await fs.rm(tempDir, { force: true, recursive: true });
+ }
+
+ await stapleWithRetry(appPath, { execute, logger, ...staple });
+ return { notarized: true };
+};