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): add PR-time verify workflow for the share micro app (#18757)

Innei9e750585fcbe
diff --git a/.agents/skills/split-micro-app/SKILL.md b/.agents/skills/split-micro-app/SKILL.md
index 9dc4d9c198d..7dd991b4671 100644
--- a/.agents/skills/split-micro-app/SKILL.md
+++ b/.agents/skills/split-micro-app/SKILL.md
@@ -106,6 +106,18 @@ 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).
+**PR-time verify is a separate workflow per repo that can change the artifact** β€” deploy
+ownership (Β§1b) does not decide verify ownership. Each verify builds the worker, uploads a
+non-deployed preview **version** (`wrangler versions upload --preview-alias`, dry-run when
+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
+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).
+
## 1b. When the surface renders Cloud-only code
`lobehub-cloud` includes this repo as a submodule at `lobehub/` and shadows it path-by-path
@@ -138,6 +150,24 @@ Cloud-only file.
lobehub-cloud (`.github/workflows/deploy-share.yml`), not OSS. Never add a deploy workflow to a
repo that can only produce the fallback.
+**OSS PRs can still verify with the real overlay.** Same-repo OSS PRs clone the overlay repo @
+HEAD via `.github/actions/business-overlay` (the clone+overlay step extracted from
+`desktop-build-setup`: overlay files land in `$GITHUB_WORKSPACE/..`, which works because the
+repo is named `lobehub` so the checkout already sits at the submodule path), then
+`cd .. && pnpm install` and run the overlay repo's own `bun run build:share` β€” the tsconfig /
+stub knowledge stays over there. **The OSS workflow never hardcodes the private repo
+name**: it comes from the Actions repository variable `OVERLAY_REPOSITORY`; the token reuses
+the pre-existing `LOBEHUB_CLOUD_TOKEN` secret (deliberately not renamed β€” the desktop release
+workflows already reference it, and a rename would mean reconfiguring the org secret). When
+either is unset (fork PRs always), the workflow falls back to the
+OSS-stub build + wrangler dry-run as a pure compile/size guard. Keep new public-facing CI
+wording on the neutral "business overlay" vocabulary β€” the older desktop release workflows
+still leak the internal naming and are the known remaining exception. One trap: an overlay
+build's `build-inputs.txt` is overlay-root-relative (`repoRoot =
+dirname(SHARE_TSCONFIG_PROJECT)`), so OSS files appear as `lobehub/src/...` β€” strip that
+prefix before exact-matching against the OSS repo's own diff (`sed 's#^lobehub/##'` in the
+verify workflow); the meta triggers already match both spellings.
+
**Cloud affected-detection needs submodule history**: a bump is a single `lobehub` entry in the
host diff, so the workflow runs `git -C lobehub fetch --unshallow` and compares the previous
submodule SHA (carried in the state artifact) before diffing against `build-inputs.txt`.
@@ -187,8 +217,16 @@ gateway routes API to `app` instead), and redirect `/` + unknown paths to `WORKB
- **Time-dependent output must be client-gated**: relative timestamps and anything else the
server and client compute differently belong behind a `useHydrated()`
(`useSyncExternalStore`) check, not in the SSR pass.
-- **Skeletons must not swallow SSR'd chrome**: a list that flips to a skeleton on mount blanks
- the server-rendered header with it. Render the header slot in the skeleton branch too.
+- **Skeletons must not swallow SSR'd chrome β€” and must hold its position.** A list that flips
+ to a skeleton on mount blanks the server-rendered header with it: render the header slot in
+ the skeleton branch too. Presence is not enough β€” every phase (no-JS SSR fallback,
+ post-hydration skeleton, settled list) must put that chrome in the **same layout container**
+ as the final render, or the page jumps sideways when JS lands. Share's hero shipped left-flush
+ while the settled list centered it in a `min(960px, 100%)` column, twice: the SSR fallback
+ rendered `ShareHero` bare, and ChatList's `showSkeleton` branch rendered `headerSlot` outside
+ `WideScreenContainer`. Verify by measuring the element's `getBoundingClientRect().x` across
+ all three phases (stall the messages request to pin the skeleton phase), not by eyeballing
+ one screenshot.
- **Preload the `error` namespace**, not just the render ones. The boundary shows exactly when a
chunk failed to load β€” precisely when the client can no longer fetch a dictionary β€” and an
untranslated boundary prints raw keys (`error.title`…). Cost for share: +6.3KB gzip/document.
@@ -247,7 +285,9 @@ protocol affinity for the landing pair; it consults `resolveRule` and lets other
2. Scaffold `apps/<name>` (copy workbench/share shapes); routes + root + entry.server + worker.
3. Build, run the module trace, cut SSR weight (gate/stub/slot/deep-import) until gzip sane β€”
in the overlay repo too, if there is one.
-4. Wire CDN deploy (`deploy.ts`, stable `_<name>/` prefix) + wrangler vars + redirects.
+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).
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/actions/business-overlay/action.yml b/.github/actions/business-overlay/action.yml
new file mode 100644
index 00000000000..59a6b4ee3bb
--- /dev/null
+++ b/.github/actions/business-overlay/action.yml
@@ -0,0 +1,94 @@
+name: Business Overlay
+description: >-
+ Clone the private business-overlay repository and overlay it around this
+ checkout so the workspace parent becomes the overlay root with this repo as
+ its `lobehub/` submodule. Same layout as desktop-build-setup's overlay,
+ extracted so non-desktop workflows (share verify) can build with the business
+ overlay without desktop's install steps.
+
+inputs:
+ overlay-repository:
+ description: Overlay repository to clone (owner/name)
+ required: true
+ overlay-ref:
+ description: Optional overlay repository ref (defaults to its default branch)
+ required: false
+ default: ''
+ overlay-token:
+ description: GitHub token with permission to read the overlay repository
+ required: true
+
+outputs:
+ overlay-ref:
+ description: The resolved overlay commit that was applied
+ value: ${{ steps.overlay.outputs.overlay_ref }}
+
+runs:
+ using: composite
+ steps:
+ - name: Overlay business repository
+ id: overlay
+ shell: bash
+ env:
+ OVERLAY_CHECKOUT: ${{ runner.temp }}/business-overlay
+ OVERLAY_REF_INPUT: ${{ inputs.overlay-ref }}
+ OVERLAY_REPOSITORY: ${{ inputs.overlay-repository }}
+ OVERLAY_ROOT: ${{ github.workspace }}/..
+ OVERLAY_TOKEN: ${{ inputs.overlay-token }}
+ run: |
+ set -euo pipefail
+
+ overlay_root="$(cd "$GITHUB_WORKSPACE/.." && pwd)"
+ overlay_checkout="$RUNNER_TEMP/business-overlay"
+
+ rm -rf "$overlay_checkout"
+
+ git clone --depth 1 --no-checkout "https://x-access-token:${OVERLAY_TOKEN}@github.com/${OVERLAY_REPOSITORY}.git" "$overlay_checkout"
+ if [ -n "$OVERLAY_REF_INPUT" ]; then
+ git -C "$overlay_checkout" fetch --depth 1 origin "$OVERLAY_REF_INPUT"
+ git -C "$overlay_checkout" checkout --detach FETCH_HEAD
+ else
+ git -C "$overlay_checkout" checkout --detach
+ fi
+
+ resolved_overlay_ref="$(git -C "$overlay_checkout" rev-parse HEAD)"
+ echo "overlay_ref=$resolved_overlay_ref" >> "$GITHUB_OUTPUT"
+ echo "OVERLAY_REF=$resolved_overlay_ref" >> "$GITHUB_ENV"
+
+ node <<'NODE'
+ const fs = require('node:fs');
+ const path = require('node:path');
+
+ const source = process.env.OVERLAY_CHECKOUT;
+ const target = process.env.OVERLAY_ROOT;
+ const skip = new Set(['.git', 'lobehub', 'node_modules']);
+
+ const copy = (from, to) => {
+ const stat = fs.lstatSync(from);
+ if (stat.isSymbolicLink()) {
+ const link = fs.readlinkSync(from);
+ fs.rmSync(to, { force: true, recursive: true });
+ fs.symlinkSync(link, to);
+ return;
+ }
+
+ if (stat.isDirectory()) {
+ fs.mkdirSync(to, { recursive: true });
+ for (const entry of fs.readdirSync(from)) {
+ if (skip.has(entry)) continue;
+ copy(path.join(from, entry), path.join(to, entry));
+ }
+ return;
+ }
+
+ fs.mkdirSync(path.dirname(to), { recursive: true });
+ fs.copyFileSync(from, to);
+ };
+
+ for (const entry of fs.readdirSync(source)) {
+ if (skip.has(entry)) continue;
+ copy(path.join(source, entry), path.join(target, entry));
+ }
+ NODE
+
+ echo "βœ… Overlay repository $resolved_overlay_ref applied at $overlay_root"
diff --git a/.github/workflows/verify-share.yml b/.github/workflows/verify-share.yml
new file mode 100644
index 00000000000..65f83596d1b
--- /dev/null
+++ b/.github/workflows/verify-share.yml
@@ -0,0 +1,189 @@
+# PR-time guard for the share micro app (apps/share). The deployed worker is
+# built with the private business overlay, so same-repo PRs overlay it (repo
+# name and token come from the OVERLAY_REPOSITORY variable and
+# OVERLAY_REPO_TOKEN secret β€” never hardcoded) and upload a preview version.
+# Without that configuration β€” fork PRs included β€” the workflow builds with the
+# open-source business stubs and dry-runs the worker upload as a pure
+# compile/size guard. The production deploy lives in the overlay repository,
+# which carries its own verify-share workflow for PRs on its side.
+name: Verify Share
+
+on:
+ pull_request: {}
+
+permissions:
+ actions: read
+ contents: read
+ pull-requests: write
+
+concurrency:
+ group: verify-share-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+jobs:
+ verify:
+ runs-on: ubuntu-latest
+ env:
+ SAME_REPO: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
+ USE_OVERLAY: ${{ github.event.pull_request.head.repo.full_name == github.repository && vars.OVERLAY_REPOSITORY != '' && secrets.LOBEHUB_CLOUD_TOKEN != '' }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ # The share deploy runs in the overlay repository, whose artifacts this
+ # repo cannot read β€” so the manifest comes from the last successful run
+ # of THIS workflow instead. First run: no manifest, build.
+ - name: Resolve last successful verify
+ id: base
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ run_id=$(gh run list --repo "${{ github.repository }}" \
+ --workflow verify-share.yml --status success --limit 1 \
+ --json databaseId --jq '.[0].databaseId' || true)
+ echo "run_id=$run_id" >> "$GITHUB_OUTPUT"
+
+ - name: Download last build-inputs manifest
+ id: manifest
+ if: steps.base.outputs.run_id != ''
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ if gh run download "${{ steps.base.outputs.run_id }}" --repo "${{ github.repository }}" \
+ -n share-build-inputs -D /tmp/share-manifest; then
+ # An overlay build records this repo's files under the submodule
+ # prefix (`lobehub/src/...`); strip it so the manifest exact-matches
+ # this repo's own diff paths. Overlay-only entries survive
+ # unprefixed and simply never match here.
+ sed -i 's#^lobehub/##' /tmp/share-manifest/build-inputs.txt
+ echo "path=/tmp/share-manifest/build-inputs.txt" >> "$GITHUB_OUTPUT"
+ else
+ echo "no manifest artifact on last successful run"
+ fi
+
+ - name: Detect share input changes
+ id: detect
+ env:
+ SHARE_MANIFEST: ${{ steps.manifest.outputs.path }}
+ run: |
+ if [ -z "$SHARE_MANIFEST" ]; then
+ echo "no previous verify manifest β€” building"
+ echo "should_build=true" >> "$GITHUB_OUTPUT"
+ else
+ node apps/share/scripts/should-build.mjs \
+ "origin/${{ github.base_ref }}" HEAD
+ fi
+
+ - name: Overlay business repository
+ if: steps.detect.outputs.should_build == 'true' && env.USE_OVERLAY == 'true'
+ uses: ./.github/actions/business-overlay
+ with:
+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}
+ overlay-token: ${{ secrets.LOBEHUB_CLOUD_TOKEN }}
+
+ - name: Setup environment
+ if: steps.detect.outputs.should_build == 'true'
+ uses: ./.github/actions/setup-env
+
+ - name: Install deps (overlay workspace)
+ if: steps.detect.outputs.should_build == 'true' && env.USE_OVERLAY == 'true'
+ # pnpm, not bun: the overlay root's `pnpm.overrides` is what redirects
+ # `@lobechat/business-*` onto the overlay packages, and its workspace
+ # list is the only one that includes `lobehub/apps/share`.
+ run: cd .. && pnpm install
+
+ - name: Install deps (open-source workspace)
+ if: steps.detect.outputs.should_build == 'true' && env.USE_OVERLAY != 'true'
+ run: pnpm install
+
+ - name: Build share (business overlay)
+ if: steps.detect.outputs.should_build == 'true' && env.USE_OVERLAY == 'true'
+ env:
+ # NODE_ENV is load-bearing: vite.config.rr.mts takes its dev branch otherwise and
+ # discards VITE_CDN_BASE without failing. A preview serves its own assets from its
+ # 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/
+ # `build:share` is the overlay repo's own build entry (tsconfig project,
+ # SSR stub list) β€” invoking it keeps that knowledge over there.
+ run: |
+ cd ..
+ bun run build:share
+ printf '/*\n Access-Control-Allow-Origin: *\n' > lobehub/apps/share/build/client/_headers
+
+ - name: Build share (open-source stubs)
+ if: steps.detect.outputs.should_build == 'true' && env.USE_OVERLAY != 'true'
+ env:
+ NODE_ENV: production
+ NODE_OPTIONS: --max-old-space-size=8192
+ run: bun run build:rr
+ working-directory: apps/share
+
+ - name: Upload build-inputs manifest
+ if: steps.detect.outputs.should_build == 'true'
+ uses: actions/upload-artifact@v4
+ with:
+ name: share-build-inputs
+ path: apps/share/build-inputs.txt
+ retention-days: 90
+
+ - name: Upload preview version and validate worker bundle
+ if: steps.detect.outputs.should_build == 'true'
+ # Explicit `bash` rather than the default shell, whose lack of pipefail would let a
+ # wrangler failure pass as a green step through the `tee`.
+ shell: bash
+ env:
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_PREVIEW_API_TOKEN || secrets.CLOUDFLARE_API_TOKEN }}
+ PR: ${{ github.event.pull_request.number }}
+ run: |
+ if [ "$SAME_REPO" = 'true' ]; then
+ set -- --preview-alias "pr${PR}" --message "PR-${PR}"
+ else
+ set -- --dry-run
+ fi
+ node_modules/.bin/wrangler versions upload \
+ --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"
+ if [ -n "$gzip_kib" ] && [ "$(printf '%.0f' "$gzip_kib")" -gt 8192 ]; then
+ echo "::error::worker bundle ${gzip_kib} KiB gzip exceeds the 8 MiB guard (plan limit is 10 MiB)"
+ exit 1
+ fi
+ if [ "$SAME_REPO" = 'true' ]; then
+ echo "Preview: https://pr${PR}-lobehub-share.lobeobjects-tg.workers.dev" >> "$GITHUB_STEP_SUMMARY"
+ fi
+ working-directory: apps/share
+
+ - name: Comment the preview URL
+ if: steps.detect.outputs.should_build == 'true' && env.SAME_REPO == 'true'
+ shell: bash
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PR: ${{ github.event.pull_request.number }}
+ REPO: ${{ github.repository }}
+ run: |
+ # Matched on a marker rather than `gh pr comment --edit-last`, which edits the
+ # last comment by this actor β€” and other workflows in this repo comment as the
+ # same bot, so it would rewrite one of theirs.
+ marker='<!-- share-preview -->'
+ if [ -n "${OVERLAY_REF:-}" ]; then
+ build_note="Built with the business overlay @ ${OVERLAY_REF} β€” the same surfaces the deployed worker renders."
+ else
+ build_note="Built with the open-source business stubs β€” overlay surfaces render their fallback here."
+ fi
+ body="${marker}
+ ### Share preview
+
+ <https://pr${PR}-lobehub-share.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 \
+ --jq "map(select(.body | startswith(\"${marker}\"))) | .[0].id // empty")
+ if [ -n "$id" ]; then
+ gh api -X PATCH "repos/${REPO}/issues/comments/${id}" -f body="$body" > /dev/null
+ else
+ gh api -X POST "repos/${REPO}/issues/${PR}/comments" -f body="$body" > /dev/null
+ fi