🤯 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
👷 ci(workbench): skip deploys whose build output is unchanged (#20122)
Innei640414f8446c
diff --git a/.agents/skills/split-micro-app/SKILL.md b/.agents/skills/split-micro-app/SKILL.mdindex c8ab5dd6b3d..5abbc939da2 100644--- a/.agents/skills/split-micro-app/SKILL.md+++ b/.agents/skills/split-micro-app/SKILL.md@@ -109,6 +109,14 @@ the one manual rule. See `apps/workbench/scripts/should-build.mjs` +`.github/workflows/deploy-workbench.yml`; the overlay-hosted variant is lobehub-cloud's`scripts/shouldBuildShare.ts` + `.github/workflows/deploy-share.yml` (§1b).+The manifest is only a pre-filter: it lists every module the build loaded, so type-only files,+barrels and tree-shaken code trigger builds too. The deploy decision is the **output hash**+(`scripts/workerOutputHash.ts`): the build is deterministic (comment-only edits hash+identically), so `deploy.ts` hashes `build/`, compares it with the `output-hash.txt` carried in+the same artifact, and skips upload + `wrangler deploy` when equal — keeping Cloudflare's+100-version rollback window for real releases. Manual dispatch passes no previous hash and+always deploys. Workbench has it; share does not yet.+**PR-time verify is a separate workflow per repo that can change the artifact** — deployownership (§1b) does not decide verify ownership. Each verify builds the worker, uploads anon-deployed preview **version** (`wrangler versions upload --preview-alias`, dry-run whendiff --git a/.github/workflows/deploy-workbench.yml b/.github/workflows/deploy-workbench.ymlindex ffeb9587dd1..cea45734524 100644--- a/.github/workflows/deploy-workbench.yml+++ b/.github/workflows/deploy-workbench.yml@@ -44,6 +44,9 @@ jobs:if gh run download "${{ steps.base.outputs.run_id }}" --repo "${{ github.repository }}" \-n workbench-build-inputs -D /tmp/workbench-manifest; thenecho "path=/tmp/workbench-manifest/build-inputs.txt" >> "$GITHUB_OUTPUT"+ if [ -f /tmp/workbench-manifest/output-hash.txt ]; then+ echo "output_hash=/tmp/workbench-manifest/output-hash.txt" >> "$GITHUB_OUTPUT"+ fielseecho "no manifest artifact on last successful run"fi@@ -81,6 +84,8 @@ jobs:ASSET_S3_PUBLIC_DOMAIN: ${{ secrets.ASSET_S3_PUBLIC_DOMAIN }}ASSET_S3_REGION: ${{ secrets.ASSET_S3_REGION }}ASSET_S3_SECRET_ACCESS_KEY: ${{ secrets.ASSET_S3_SECRET_ACCESS_KEY }}+ # Unset on manual dispatch, which always deploys.+ WORKBENCH_PREVIOUS_OUTPUT_HASH_FILE: ${{ steps.manifest.outputs.output_hash }}run: bun run deployworking-directory: apps/workbench@@ -89,7 +94,9 @@ jobs:uses: actions/upload-artifact@v4with:name: workbench-build-inputs- path: apps/workbench/build-inputs.txt+ path: |+ apps/workbench/build-inputs.txt+ apps/workbench/output-hash.txtretention-days: 90- name: Carry forward previous manifest@@ -97,5 +104,5 @@ jobs:uses: actions/upload-artifact@v4with:name: workbench-build-inputs- path: ${{ steps.manifest.outputs.path }}+ path: /tmp/workbench-manifest/retention-days: 90diff --git a/apps/workbench/.gitignore b/apps/workbench/.gitignoreindex 5e2212a791d..b1480192792 100644--- a/apps/workbench/.gitignore+++ b/apps/workbench/.gitignore@@ -3,3 +3,4 @@.wrangler/build/build-inputs.txt+output-hash.txtdiff --git a/apps/workbench/scripts/deploy.ts b/apps/workbench/scripts/deploy.tsindex 720dfff445f..d2009876e41 100644--- a/apps/workbench/scripts/deploy.ts+++ b/apps/workbench/scripts/deploy.ts@@ -1,15 +1,21 @@import { execFileSync, execSync } from 'node:child_process';-import { existsSync } from 'node:fs';+import { existsSync, writeFileSync } from 'node:fs';import { resolve } from 'node:path';import dotenv from 'dotenv';import { uploadAssets } from '../../../scripts/mobileSpaWorkflow/upload';-import { localOperator, workerDeployAnnotationArgs } from '../../../scripts/workerDeployAnnotations';+import {+ localOperator,+ workerDeployAnnotationArgs,+} from '../../../scripts/workerDeployAnnotations';+import { hashBuildOutput, readOutputHash } from '../../../scripts/workerOutputHash';const workbenchRoot = resolve(__dirname, '..');const repoRoot = resolve(workbenchRoot, '../..');-const assetsDir = resolve(workbenchRoot, 'build/client/assets');+const buildDir = resolve(workbenchRoot, 'build');+const assetsDir = resolve(buildDir, 'client/assets');+const outputHashFile = resolve(workbenchRoot, 'output-hash.txt');dotenv.config({ path: resolve(repoRoot, '.env') });@@ -51,6 +57,17 @@ async function main() {if (!existsSync(assetsDir)) throw new Error(`Build output not found at ${assetsDir}`);+ const outputHash = hashBuildOutput(buildDir);+ writeFileSync(outputHashFile, `${outputHash}\n`);++ // A build input can change without changing a byte of output (comments, types, code the+ // bundle tree-shakes). Redeploying that output would only push real releases out of+ // Cloudflare's 100-version rollback window.+ if (outputHash === readOutputHash(process.env.WORKBENCH_PREVIOUS_OUTPUT_HASH_FILE)) {+ console.log(`\n=== Output unchanged (${outputHash.slice(0, 12)}), skipping deploy ===`);+ return;+ }+console.log('\n=== Step 2: Upload assets to S3 ===');await uploadAssets(assetsDir, {accessKeyId: requireEnv('ASSET_S3_ACCESS_KEY_ID', 'MOBILE_S3_ACCESS_KEY_ID'),diff --git a/scripts/workerOutputHash.test.ts b/scripts/workerOutputHash.test.tsnew file mode 100644index 00000000000..dd3dcb53d2c--- /dev/null+++ b/scripts/workerOutputHash.test.ts@@ -0,0 +1,60 @@+import { mkdirSync, mkdtempSync, renameSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';++import { describe, expect, it } from 'vitest';++import { hashBuildOutput, readOutputHash } from './workerOutputHash';++const makeBuild = (files: Record<string, string>) => {+ const dir = mkdtempSync(path.join(tmpdir(), 'worker-output-'));+ for (const [file, content] of Object.entries(files)) {+ mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });+ writeFileSync(path.join(dir, file), content);+ }+ return dir;+};++const baseline = {+ 'client/assets/entry-abc.js': 'console.log(1)',+ 'server/index.js': 'export default {}',+ 'server/wrangler.json': '{"name":"lobehub-workbench"}',+};++describe('hashBuildOutput', () => {+ it('gives identical builds the same hash regardless of write order', () => {+ const reversed = Object.fromEntries(Object.entries(baseline).reverse());++ expect(hashBuildOutput(makeBuild(baseline))).toBe(hashBuildOutput(makeBuild(reversed)));+ });++ it('changes when any deployable file changes', () => {+ const changedWorkerConfig = { ...baseline, 'server/wrangler.json': '{"name":"other"}' };++ expect(hashBuildOutput(makeBuild(changedWorkerConfig))).not.toBe(+ hashBuildOutput(makeBuild(baseline)),+ );+ });++ it('changes when a file moves even though its bytes do not', () => {+ const dir = makeBuild(baseline);+ const before = hashBuildOutput(dir);+ renameSync(+ path.join(dir, 'client/assets/entry-abc.js'),+ path.join(dir, 'client/assets/entry-def.js'),+ );++ expect(hashBuildOutput(dir)).not.toBe(before);+ });+});++describe('readOutputHash', () => {+ it('treats a missing or empty record as no previous deploy', () => {+ const dir = makeBuild({ 'empty.txt': '\n', 'hash.txt': 'abc123\n' });++ expect(readOutputHash(undefined)).toBeUndefined();+ expect(readOutputHash(path.join(dir, 'missing.txt'))).toBeUndefined();+ expect(readOutputHash(path.join(dir, 'empty.txt'))).toBeUndefined();+ expect(readOutputHash(path.join(dir, 'hash.txt'))).toBe('abc123');+ });+});diff --git a/scripts/workerOutputHash.ts b/scripts/workerOutputHash.tsnew file mode 100644index 00000000000..e139bba2cab--- /dev/null+++ b/scripts/workerOutputHash.ts@@ -0,0 +1,26 @@+import { createHash } from 'node:crypto';+import { existsSync, readdirSync, readFileSync } from 'node:fs';+import path from 'node:path';++const listFiles = (dir: string, prefix = ''): string[] =>+ readdirSync(path.join(dir, prefix), { withFileTypes: true }).flatMap((entry) => {+ const relative = prefix ? `${prefix}/${entry.name}` : entry.name;+ if (entry.isDirectory()) return listFiles(dir, relative);+ return entry.isFile() ? [relative] : [];+ });++export const hashBuildOutput = (dir: string): string => {+ const hash = createHash('sha256');+ for (const file of listFiles(dir).sort()) {+ const content = createHash('sha256')+ .update(readFileSync(path.join(dir, file)))+ .digest('hex');+ hash.update(`${file}\0${content}\n`);+ }+ return hash.digest('hex');+};++export const readOutputHash = (file: string | undefined): string | undefined => {+ if (!file || !existsSync(file)) return undefined;+ return readFileSync(file, 'utf8').trim() || undefined;+};