π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(ci): merge nested allowBuilds into the desktop overlay (#20310)
Inneie7297017cbe1
diff --git a/.github/actions/business-overlay/action.yml b/.github/actions/business-overlay/action.ymlindex 08e58265aba..5cd209be938 100644--- a/.github/actions/business-overlay/action.yml+++ b/.github/actions/business-overlay/action.yml@@ -89,47 +89,11 @@ runs:if (skip.has(entry)) continue;copy(path.join(source, entry), path.join(target, entry));}-- const parseAllowBuilds = (text) => {- const map = {};- const lines = text.split('\n');- let inBlock = false;- for (const line of lines) {- if (!inBlock) {- if (/^allowBuilds:\s*$/.test(line)) inBlock = true;- continue;- }- const match = line.match(- /^(\s+)((?:'[^']+'|"[^"]+"|[A-Za-z0-9@._/-]+)):\s*(true|false)\s*$/,- );- if (!match) break;- map[match[2].replace(/^['"]|['"]$/g, '')] = match[3] === 'true';- }- return map;- };-- const quoteKey = (key) => (/[@:]/.test(key) ? `'${key}'` : key);- const rootFile = path.join(target, 'pnpm-workspace.yaml');- const rootText = fs.readFileSync(rootFile, 'utf8');- const rootMap = parseAllowBuilds(rootText);- const extras = {};- for (const rel of ['pnpm-workspace.yaml', 'apps/desktop/pnpm-workspace.yaml']) {- const extraFile = path.join(process.env.GITHUB_WORKSPACE, rel);- if (!fs.existsSync(extraFile)) continue;- Object.assign(extras, parseAllowBuilds(fs.readFileSync(extraFile, 'utf8')));- }- const missing = Object.keys(extras)- .filter((key) => !(key in rootMap))- .sort();- if (missing.length > 0) {- const insert = missing- .map((key) => ` ${quoteKey(key)}: ${extras[key]}\n`)- .join('');- if (!/^allowBuilds:\n/m.test(rootText)) {- throw new Error('overlay pnpm-workspace.yaml is missing an allowBuilds block');- }- fs.writeFileSync(rootFile, rootText.replace(/^allowBuilds:\n/m, `allowBuilds:\n${insert}`));- }NODE+ node "$GITHUB_ACTION_PATH/../../scripts/mergeAllowBuilds.mjs" \+ "$overlay_root/pnpm-workspace.yaml" \+ "$GITHUB_WORKSPACE/pnpm-workspace.yaml" \+ "$GITHUB_WORKSPACE/apps/desktop/pnpm-workspace.yaml"+echo "β Overlay repository $resolved_overlay_ref applied at $overlay_root"diff --git a/.github/actions/desktop-build-setup/action.yml b/.github/actions/desktop-build-setup/action.ymlindex f5973f2d35b..e8611260e89 100644--- a/.github/actions/desktop-build-setup/action.yml+++ b/.github/actions/desktop-build-setup/action.yml@@ -94,6 +94,11 @@ runs:}NODE+ node "$GITHUB_ACTION_PATH/../../scripts/mergeAllowBuilds.mjs" \+ "$cloud_root/pnpm-workspace.yaml" \+ "$GITHUB_WORKSPACE/pnpm-workspace.yaml" \+ "$GITHUB_WORKSPACE/apps/desktop/pnpm-workspace.yaml"+echo "CLOUD_DESKTOP=1" >> "$GITHUB_ENV"echo "β Cloud repository $resolved_cloud_ref overlaid at $cloud_root"diff --git a/.github/scripts/mergeAllowBuilds.mjs b/.github/scripts/mergeAllowBuilds.mjsnew file mode 100644index 00000000000..f89f4e96fde--- /dev/null+++ b/.github/scripts/mergeAllowBuilds.mjs@@ -0,0 +1,60 @@+import fs from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++const ALLOW_BUILDS_LINE = /^allowBuilds:\s*$/;+const ALLOW_BUILDS_ENTRY = /^(\s+)('[^']+'|"[^"]+"|[\w@./-]+):\s*(true|false)\s*$/;++export const parseAllowBuilds = (text) => {+ const map = {};+ const lines = text.split('\n');+ let inBlock = false;+ for (const line of lines) {+ if (!inBlock) {+ if (ALLOW_BUILDS_LINE.test(line)) inBlock = true;+ continue;+ }+ const match = line.match(ALLOW_BUILDS_ENTRY);+ if (!match) break;+ map[match[2].replaceAll(/^['"]|['"]$/g, '')] = match[3] === 'true';+ }+ return map;+};++const quoteKey = (key) => (/[@:]/.test(key) ? `'${key}'` : key);++export const mergeAllowBuilds = ({ rootText, extraTexts }) => {+ const rootMap = parseAllowBuilds(rootText);+ const extras = {};+ for (const text of extraTexts) Object.assign(extras, parseAllowBuilds(text));+ const missing = Object.keys(extras)+ .filter((key) => !(key in rootMap))+ .sort();+ if (missing.length === 0) return rootText;+ if (!/^allowBuilds:\n/m.test(rootText)) {+ throw new Error('overlay pnpm-workspace.yaml is missing an allowBuilds block');+ }+ const insert = missing.map((key) => ` ${quoteKey(key)}: ${extras[key]}\n`).join('');+ return rootText.replace(/^allowBuilds:\n/m, `allowBuilds:\n${insert}`);+};++export const mergeAllowBuildsFiles = ({ rootFile, extraFiles }) => {+ const rootText = fs.readFileSync(rootFile, 'utf8');+ const extraTexts = extraFiles+ .filter((file) => fs.existsSync(file))+ .map((file) => fs.readFileSync(file, 'utf8'));+ const next = mergeAllowBuilds({ extraTexts, rootText });+ if (next !== rootText) fs.writeFileSync(rootFile, next);+ return next;+};++const isMain =+ Boolean(process.argv[1]) && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);++if (isMain) {+ const [rootFile, ...extraFiles] = process.argv.slice(2);+ if (!rootFile) {+ throw new Error('usage: mergeAllowBuilds.mjs <root-pnpm-workspace.yaml> [extra.yaml...]');+ }+ mergeAllowBuildsFiles({ extraFiles, rootFile });+}diff --git a/.github/scripts/mergeAllowBuilds.test.mjs b/.github/scripts/mergeAllowBuilds.test.mjsnew file mode 100644index 00000000000..cd0b6c12081--- /dev/null+++ b/.github/scripts/mergeAllowBuilds.test.mjs@@ -0,0 +1,73 @@+import assert from 'node:assert/strict';+import { mkdtemp, readFile, writeFile } from 'node:fs/promises';+import os from 'node:os';+import path from 'node:path';+import { test } from 'node:test';++import { mergeAllowBuilds, mergeAllowBuildsFiles, parseAllowBuilds } from './mergeAllowBuilds.mjs';++const overlayWorkspace = `packages:+ - packages/**+ - lobehub++allowBuilds:+ esbuild: false+ sharp: false+`;++const innerWorkspace = `allowBuilds:+ '@google/genai': true+ '@mongodb-js/zstd': false+ esbuild: true+ node-liblzma: false+`;++test('parseAllowBuilds reads quoted scoped packages and booleans', () => {+ assert.deepEqual(parseAllowBuilds(innerWorkspace), {+ '@google/genai': true,+ '@mongodb-js/zstd': false,+ 'esbuild': true,+ 'node-liblzma': false,+ });+});++test('mergeAllowBuilds copies inner decisions the overlay has not recorded', () => {+ const merged = mergeAllowBuilds({+ extraTexts: [innerWorkspace],+ rootText: overlayWorkspace,+ });++ assert.deepEqual(parseAllowBuilds(merged), {+ '@google/genai': true,+ '@mongodb-js/zstd': false,+ 'esbuild': false,+ 'node-liblzma': false,+ 'sharp': false,+ });+ assert.match(merged, /'@mongodb-js\/zstd': false/);+ assert.match(merged, /node-liblzma: false/);+ assert.match(merged, /esbuild: false/);+});++test('mergeAllowBuildsFiles writes only when the overlay is missing keys', async () => {+ const dir = await mkdtemp(path.join(os.tmpdir(), 'merge-allow-builds-'));+ const rootFile = path.join(dir, 'pnpm-workspace.yaml');+ const extraFile = path.join(dir, 'inner.yaml');+ await writeFile(rootFile, overlayWorkspace);+ await writeFile(extraFile, innerWorkspace);++ mergeAllowBuildsFiles({ extraFiles: [extraFile, path.join(dir, 'missing.yaml')], rootFile });++ const written = await readFile(rootFile, 'utf8');+ assert.equal(+ written,+ mergeAllowBuilds({ extraTexts: [innerWorkspace], rootText: overlayWorkspace }),+ );+});++test('mergeAllowBuilds throws when the overlay has no allowBuilds block', () => {+ assert.throws(+ () => mergeAllowBuilds({ extraTexts: [innerWorkspace], rootText: 'packages:\n - .\n' }),+ /missing an allowBuilds block/,+ );+});diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 1bea699d176..f3d593f341f 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -65,7 +65,8 @@ jobs:node --test \.github/scripts/vercel-ignored-build-step.test.cjs \.github/scripts/bundle-size-gate.test.cjs \- .github/scripts/size-gate-comment.test.cjs+ .github/scripts/size-gate-comment.test.cjs \+ .github/scripts/mergeAllowBuilds.test.mjs- name: Setup environmentuses: ./.github/actions/setup-env