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(share,workbench): upload PR previews to sibling -preview Workers (#19103)

Innei011f947cf7c9
diff --git a/.agents/skills/split-micro-app/SKILL.md b/.agents/skills/split-micro-app/SKILL.md
index dc057386e05..8092a0a67f6 100644
--- a/.agents/skills/split-micro-app/SKILL.md
+++ b/.agents/skills/split-micro-app/SKILL.md
@@ -1,6 +1,6 @@
---
name: split-micro-app
-description: 'Use when splitting a monorepo surface into a standalone micro app (React Router SSR on Cloudflare Workers), splitting a surface whose rendering code lives in the lobehub-cloud business overlay, fighting SSR bundle bloat from main-src imports, deploying its assets to CDN/R2, adding SEO/OG meta to an SSR page, adding a target and route rules for it in the lobehub gateway (torii), wiring it into the OSS Docker image, or deciding whether Cloud Next should still build or rewrite it.'
+description: 'Use when splitting a monorepo surface into a standalone micro app (React Router SSR on Cloudflare Workers), splitting a surface whose rendering code lives in the lobehub-cloud business overlay, fighting SSR bundle bloat from main-src imports, deploying its assets to CDN/R2, adding SEO/OG meta to an SSR page, adding a target and route rules for it in the lobehub gateway (torii), setting up PR preview uploads on a sibling -preview Worker so the production script keeps its Cloudflare rollback window, wiring it into the OSS Docker image, or deciding whether Cloud Next should still build or rewrite it.'
user-invocable: false
---
@@ -115,8 +115,20 @@ non-deployed preview **version** (`wrangler versions upload --preview-alias`, dr
secrets are absent), enforces the 8MB-gzip guard, and comments the preview URL behind an HTML
marker (never `--edit-last` β€” other workflows comment as the same bot). Workbench: one repo,
one `verify-workbench.yml`. Share: **both** repos, because either side's change flows into the
-deployed worker β€” OSS `verify-share.yml` + cloud `verify-share.yml`. Alias namespaces must not
-collide on the shared worker: OSS uses `pr<N>`, cloud uses `cloudpr<N>`. Manifest source
+deployed worker β€” OSS `verify-share.yml` + cloud `verify-share.yml`.
+
+**Previews upload to a sibling Worker, never to the production script.** Cloudflare only rolls
+back to the **100 most recently uploaded versions** of a script, and preview uploads count: at
+share's PR rate (10 uploads in under an hour on a busy day) every real deployment left the
+window within a day, which broke the gateway admin's (ι³₯ε±…η•ͺ) rollback list. So every verify
+passes `--name lobehub-<name>-preview`, and the production script's version list holds only
+deployments. Two consequences: the preview Worker must exist before the first upload
+(`wrangler versions upload` refuses a never-deployed script β€” bootstrap it once with
+`wrangler deploy --name lobehub-<name>-preview` from any stub; the next upload replaces it),
+and the preview API token must be allowed to edit the `-preview` name. Preview URLs are then
+`https://<alias>-lobehub-<name>-preview.lobeobjects-tg.workers.dev`, and `VITE_CDN_BASE` must
+point at that same origin. Alias namespaces must not collide on the shared preview worker: OSS
+uses `pr<N>`, cloud uses `cloudpr<N>`. Manifest source
differs by what the repo can read: cloud verify borrows the deploy's `share-deploy-state`
artifact (same repo); OSS verify cannot read cloud artifacts, so it self-bootstraps from its
own last successful run's `share-build-inputs` (first run always builds).
@@ -361,6 +373,15 @@ To add a micro app:
drift), run the invariant suite, and re-run `verify --env staging`.
6. Verify with staging debug headers: `x-torii-target` / `x-torii-decision` per request, and
test document + `.data` + unaffected routes.
+7. Rollback and previews live in ι³₯ε±…η•ͺ's target detail pane, in a **Worker** card that every
+ target whose host is in the gateway repo's `bindings.ts` gets for free. **Releases** lists
+ the production script's Cloudflare deployments; a row is only rollbackable while its
+ version is within Cloudflare's 100-upload window β€” which is the reason previews stay off
+ the production script (Β§1). **Previews** lists the `-preview` Worker's versions (PR label
+ and actor come from the `--message` stamp) with Open and, under staging, **Set override**,
+ which writes the preview host into the target's `targetOverrides` immediately (a saved,
+ history-recorded config write β€” no editor Save). Adding a micro app to `bindings.ts` is
+ therefore part of wiring it into the gateway.
Landmine (fixed 2026-08, stay aware): the lobehub-com `react-router-data` plugin owns `.data`
protocol affinity for the landing pair; it consults `resolveRule` and lets other targets'
@@ -375,7 +396,8 @@ protocol affinity for the landing pair; it consults `resolveRule` and lets other
in the overlay repo too, if there is one.
4. Wire CDN deploy (`deploy.ts`, stable `_<name>/` prefix) + wrangler vars + redirects, plus a
PR-time verify workflow in **every repo whose changes reach the artifact** (Β§1 PR-time
- verify β€” preview version, size guard, non-colliding alias namespace).
+ verify β€” preview version on the bootstrapped `lobehub-<name>-preview` Worker, size guard,
+ non-colliding alias namespace).
5. Loader data + SWR fallback + meta builder + i18n narrowing (+ `error`); verify with
`/trpc`-blocked browser run (content must survive) and view-source (SSR content + meta present).
6. Deploy worker; verify workers.dev standalone (API proxy, `/` redirect).
diff --git a/.github/workflows/verify-share.yml b/.github/workflows/verify-share.yml
index 65f83596d1b..3e8fe8654a3 100644
--- a/.github/workflows/verify-share.yml
+++ b/.github/workflows/verify-share.yml
@@ -106,7 +106,7 @@ jobs:
# own workers.dev origin, the way production serves them from the CDN β€” never
# same-origin, because the gateway routes /assets to the landing target.
NODE_ENV: production
- VITE_CDN_BASE: https://pr${{ github.event.pull_request.number }}-lobehub-share.lobeobjects-tg.workers.dev/
+ VITE_CDN_BASE: https://pr${{ github.event.pull_request.number }}-lobehub-share-preview.lobeobjects-tg.workers.dev/
# `build:share` is the overlay repo's own build entry (tsconfig project,
# SSR stub list) β€” invoking it keeps that knowledge over there.
run: |
@@ -137,14 +137,21 @@ jobs:
shell: bash
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_PREVIEW_API_TOKEN || secrets.CLOUDFLARE_API_TOKEN }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR: ${{ github.event.pull_request.number }}
run: |
if [ "$SAME_REPO" = 'true' ]; then
- set -- --preview-alias "pr${PR}" --message "PR-${PR}"
+ set -- --preview-alias "pr${PR}" --tag "${HEAD_SHA::7}" \
+ --message "PR-${PR} ${GITHUB_ACTOR} ${GITHUB_REPOSITORY}@${HEAD_SHA::7} run ${GITHUB_RUN_ID}"
else
set -- --dry-run
fi
+ # Previews go to a sibling `-preview` Worker, never to the production script:
+ # Cloudflare only rolls back to the 100 most recently uploaded versions, and PR
+ # uploads onto the real script would push its deployed versions out of that
+ # window within a day.
node_modules/.bin/wrangler versions upload \
+ --name lobehub-share-preview \
--config build/server/wrangler.json "$@" | tee /tmp/upload.log
gzip_kib=$(grep -Eo 'gzip: [0-9.]+ KiB' /tmp/upload.log | grep -Eo '[0-9.]+' | head -1)
echo "worker gzip size: ${gzip_kib} KiB"
@@ -153,7 +160,7 @@ jobs:
exit 1
fi
if [ "$SAME_REPO" = 'true' ]; then
- echo "Preview: https://pr${PR}-lobehub-share.lobeobjects-tg.workers.dev" >> "$GITHUB_STEP_SUMMARY"
+ echo "Preview: https://pr${PR}-lobehub-share-preview.lobeobjects-tg.workers.dev" >> "$GITHUB_STEP_SUMMARY"
fi
working-directory: apps/share
@@ -177,7 +184,7 @@ jobs:
body="${marker}
### Share preview
- <https://pr${PR}-lobehub-share.lobeobjects-tg.workers.dev>
+ <https://pr${PR}-lobehub-share-preview.lobeobjects-tg.workers.dev>
A version, not a deployment: it takes no production traffic. ${build_note}"
id=$(gh api "repos/${REPO}/issues/${PR}/comments" --paginate \
diff --git a/.github/workflows/verify-workbench.yml b/.github/workflows/verify-workbench.yml
index 40e254681b5..6421bbcc3aa 100644
--- a/.github/workflows/verify-workbench.yml
+++ b/.github/workflows/verify-workbench.yml
@@ -77,7 +77,7 @@ jobs:
NODE_OPTIONS: --max-old-space-size=8192
VITE_CDN_BASE: >-
${{ github.event.pull_request.head.repo.full_name == github.repository
- && format('https://pr{0}-lobehub-workbench.lobeobjects-tg.workers.dev/', github.event.pull_request.number)
+ && format('https://pr{0}-lobehub-workbench-preview.lobeobjects-tg.workers.dev/', github.event.pull_request.number)
|| '' }}
run: |
bun run build:rr
@@ -91,15 +91,22 @@ jobs:
shell: bash
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_PREVIEW_API_TOKEN || secrets.CLOUDFLARE_API_TOKEN }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
SAME_REPO: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
PR: ${{ github.event.pull_request.number }}
run: |
if [ "$SAME_REPO" = 'true' ]; then
- set -- --preview-alias "pr${PR}" --message "PR-${PR}"
+ set -- --preview-alias "pr${PR}" --tag "${HEAD_SHA::7}" \
+ --message "PR-${PR} ${GITHUB_ACTOR} ${GITHUB_REPOSITORY}@${HEAD_SHA::7} run ${GITHUB_RUN_ID}"
else
set -- --dry-run
fi
+ # Previews go to a sibling `-preview` Worker, never to the production script:
+ # Cloudflare only rolls back to the 100 most recently uploaded versions, and PR
+ # uploads onto the real script would push its deployed versions out of that
+ # window within a day.
node_modules/.bin/wrangler versions upload \
+ --name lobehub-workbench-preview \
--config build/server/wrangler.json "$@" | tee /tmp/upload.log
gzip_kib=$(grep -Eo 'gzip: [0-9.]+ KiB' /tmp/upload.log | grep -Eo '[0-9.]+' | head -1)
echo "worker gzip size: ${gzip_kib} KiB"
@@ -108,7 +115,7 @@ jobs:
exit 1
fi
if [ "$SAME_REPO" = 'true' ]; then
- echo "Preview: https://pr${PR}-lobehub-workbench.lobeobjects-tg.workers.dev" >> "$GITHUB_STEP_SUMMARY"
+ echo "Preview: https://pr${PR}-lobehub-workbench-preview.lobeobjects-tg.workers.dev" >> "$GITHUB_STEP_SUMMARY"
fi
working-directory: apps/workbench
@@ -127,7 +134,7 @@ jobs:
body="${marker}
### Workbench preview
- <https://pr${PR}-lobehub-workbench.lobeobjects-tg.workers.dev>
+ <https://pr${PR}-lobehub-workbench-preview.lobeobjects-tg.workers.dev>
A version, not a deployment: it takes no production traffic. Assets are served
from that same origin, so the page also renders through the gateway β€” point
diff --git a/apps/share/scripts/deploy.ts b/apps/share/scripts/deploy.ts
index 9118be13162..1eec966b36f 100644
--- a/apps/share/scripts/deploy.ts
+++ b/apps/share/scripts/deploy.ts
@@ -1,10 +1,11 @@
-import { execSync } from 'node:child_process';
+import { execFileSync, execSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import dotenv from 'dotenv';
import { uploadAssets } from '../../../scripts/mobileSpaWorkflow/upload';
+import { localOperator, workerDeployAnnotationArgs } from '../../../scripts/workerDeployAnnotations';
const shareRoot = resolve(__dirname, '..');
const repoRoot = resolve(shareRoot, '../..');
@@ -64,10 +65,16 @@ async function main() {
});
console.log('\n=== Step 3: Deploy worker ===');
- execSync('node_modules/.bin/wrangler deploy --config build/server/wrangler.json', {
- cwd: shareRoot,
- stdio: 'inherit',
- });
+ execFileSync(
+ 'node_modules/.bin/wrangler',
+ [
+ 'deploy',
+ '--config',
+ 'build/server/wrangler.json',
+ ...workerDeployAnnotationArgs(process.env, localOperator(shareRoot)),
+ ],
+ { cwd: shareRoot, stdio: 'inherit' },
+ );
console.log('\n=== Deploy complete ===');
}
diff --git a/apps/workbench/scripts/deploy.ts b/apps/workbench/scripts/deploy.ts
index 7cc0c8eb230..720dfff445f 100644
--- a/apps/workbench/scripts/deploy.ts
+++ b/apps/workbench/scripts/deploy.ts
@@ -1,10 +1,11 @@
-import { execSync } from 'node:child_process';
+import { execFileSync, execSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import dotenv from 'dotenv';
import { uploadAssets } from '../../../scripts/mobileSpaWorkflow/upload';
+import { localOperator, workerDeployAnnotationArgs } from '../../../scripts/workerDeployAnnotations';
const workbenchRoot = resolve(__dirname, '..');
const repoRoot = resolve(workbenchRoot, '../..');
@@ -62,10 +63,16 @@ async function main() {
});
console.log('\n=== Step 3: Deploy worker ===');
- execSync('node_modules/.bin/wrangler deploy --config build/server/wrangler.json', {
- cwd: workbenchRoot,
- stdio: 'inherit',
- });
+ execFileSync(
+ 'node_modules/.bin/wrangler',
+ [
+ 'deploy',
+ '--config',
+ 'build/server/wrangler.json',
+ ...workerDeployAnnotationArgs(process.env, localOperator(workbenchRoot)),
+ ],
+ { cwd: workbenchRoot, stdio: 'inherit' },
+ );
console.log('\n=== Deploy complete ===');
}
diff --git a/scripts/workerDeployAnnotations.test.ts b/scripts/workerDeployAnnotations.test.ts
new file mode 100644
index 00000000000..2bb3b3ba283
--- /dev/null
+++ b/scripts/workerDeployAnnotations.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from 'vitest';
+
+import { workerDeployAnnotationArgs } from './workerDeployAnnotations';
+
+describe('workerDeployAnnotationArgs', () => {
+ it('names the Actions actor, repo, commit and run so the Cloudflare record is self-describing', () => {
+ expect(
+ workerDeployAnnotationArgs({
+ GITHUB_ACTIONS: 'true',
+ GITHUB_ACTOR: 'octocat',
+ GITHUB_REPOSITORY: 'lobehub/lobehub',
+ GITHUB_RUN_ID: '123456',
+ GITHUB_SHA: 'abcdef1234567890',
+ }),
+ ).toEqual([
+ '--tag',
+ 'abcdef1',
+ '--message',
+ 'octocat lobehub/lobehub@abcdef1 run 123456',
+ ]);
+ });
+
+ it('falls back to the local operator and commit outside Actions', () => {
+ expect(
+ workerDeployAnnotationArgs({}, { email: '[email protected]', sha: '0123456789abcdef' }),
+ ).toEqual(['--tag', '0123456', '--message', '[email protected] local@0123456']);
+ });
+
+ it('annotates nothing when neither source can name an operator', () => {
+ expect(workerDeployAnnotationArgs({}, undefined)).toEqual([]);
+ });
+});
diff --git a/scripts/workerDeployAnnotations.ts b/scripts/workerDeployAnnotations.ts
new file mode 100644
index 00000000000..33144260610
--- /dev/null
+++ b/scripts/workerDeployAnnotations.ts
@@ -0,0 +1,40 @@
+import { execSync } from 'node:child_process';
+
+export interface LocalOperator {
+ email: string;
+ sha: string;
+}
+
+// Cloudflare stamps every version with the API token's owner, never with the person or
+// pipeline behind it, so the operator has to travel in the version's own annotations.
+export const workerDeployAnnotationArgs = (
+ env: NodeJS.ProcessEnv,
+ local: LocalOperator | undefined,
+): string[] => {
+ if (env.GITHUB_ACTIONS === 'true' && env.GITHUB_SHA) {
+ const sha = env.GITHUB_SHA.slice(0, 7);
+ return [
+ '--tag',
+ sha,
+ '--message',
+ `${env.GITHUB_ACTOR ?? 'actions'} ${env.GITHUB_REPOSITORY ?? ''}@${sha} run ${env.GITHUB_RUN_ID ?? ''}`,
+ ];
+ }
+ if (!local) return [];
+ const sha = local.sha.slice(0, 7);
+ return ['--tag', sha, '--message', `${local.email} local@${sha}`];
+};
+
+const git = (cwd: string, args: string): string | undefined => {
+ try {
+ return execSync(`git ${args}`, { cwd, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() || undefined;
+ } catch {
+ return undefined;
+ }
+};
+
+export const localOperator = (cwd: string): LocalOperator | undefined => {
+ const email = git(cwd, 'config user.email');
+ const sha = git(cwd, 'rev-parse HEAD');
+ return email && sha ? { email, sha } : undefined;
+};