From 6eb02b835bddc4be7c1ab505ba8d216bfb7de4db Mon Sep 17 00:00:00 2001 From: DarkSky Date: Sat, 28 Nov 2026 04:27:25 +0900 Subject: [PATCH] ci(native-playground): add backend and native-ui path filters and mobile merge-base --- .github/workflows/native-playground.yml | 107 +++++++++++++++++---- AGENTS.md | 2 +- packages/frontend/perf/compare-n3.mjs | 99 +++++++++---------- packages/frontend/perf/compare-n3.test.mjs | 38 +++++++- 4 files changed, 176 insertions(+), 70 deletions(-) diff --git a/.github/workflows/native-playground.yml b/.github/workflows/native-playground.yml index 14fa65a08e..586cc3214f 100644 --- a/.github/workflows/native-playground.yml +++ b/.github/workflows/native-playground.yml @@ -22,8 +22,10 @@ jobs: name: Changed Paths runs-on: ubuntu-24.04 outputs: - web: ${{ steps.filter.outputs.web }} - web-build: ${{ steps.filter.outputs.web-build }} + web: ${{ steps.base.outputs.force_all == 'true' && 'true' || steps.filter.outputs.web }} + web-build: ${{ steps.base.outputs.force_all == 'true' && 'true' || steps.filter.outputs.web-build }} + backend: ${{ steps.base.outputs.force_all == 'true' && 'true' || steps.filter.outputs.backend }} + native-ui: ${{ steps.base.outputs.force_all == 'true' && 'true' || steps.filter.outputs.native-ui }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -31,26 +33,43 @@ jobs: # Full history so the merge base and the previous push are present. fetch-depth: 0 + - name: L0 Tier A static gates + run: node scripts/ci/check-l0-tier-a.mjs + - name: Resolve the base commit id: base env: BEFORE: ${{ github.event.before }} - # Topic branches compare with their merge base on the integration - # branch; the integration branch compares with the commit before this - # push, or its parent when that commit is unknown (new branch, force - # push). Always a commit SHA, never a branch name. + # Topic branches compare with their merge base on the parent integration + # branch (`darksky/np/mobile` for `darksky/np/mobile-*`, otherwise + # `darksky/native-playground`); integration branches compare with the + # commit before this push, or conservatively force all lanes when that + # commit is unknown (branch creation or force-push). run: | set -euo pipefail - if [ "$GITHUB_REF_NAME" = darksky/native-playground ]; then - if [ -n "${BEFORE//0/}" ] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then - sha=$BEFORE - else - sha=$(git rev-parse HEAD~1) - fi - else - sha=$(git merge-base origin/darksky/native-playground HEAD) - fi + force_all=false + case "$GITHUB_REF_NAME" in + darksky/native-playground|darksky/np/mobile) + if [ -n "${BEFORE//0/}" ] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then + sha=$BEFORE + else + force_all=true + sha=$(git rev-parse HEAD~1 2>/dev/null || git rev-parse HEAD) + fi + ;; + darksky/np/mobile-*) + if git rev-parse --verify origin/darksky/np/mobile >/dev/null 2>&1; then + sha=$(git merge-base origin/darksky/np/mobile HEAD) + else + sha=$(git merge-base origin/darksky/native-playground HEAD) + fi + ;; + *) + sha=$(git merge-base origin/darksky/native-playground HEAD) + ;; + esac echo "sha=$sha" >> "$GITHUB_OUTPUT" + echo "force_all=$force_all" >> "$GITHUB_OUTPUT" - name: Detect changed paths id: filter @@ -111,6 +130,47 @@ jobs: - '.yarn/**' - '.github/actions/setup-node/**' - '.github/workflows/np-web-build.yml' + backend: + - 'packages/backend/**' + - 'packages/common/graphql/**' + - 'packages/common/realtime/**' + - 'packages/frontend/component/**' + - 'scripts/oracle/**' + - 'scripts/ci/check-csf-frame-audit.mjs' + - 'tools/parity-harness/**' + - 'tools/frame-audit/**' + - 'tests/oracle-contracts/**' + - 'tests/affine-cloud/**' + - 'tests/kit/**' + - 'Cargo.toml' + - 'Cargo.lock' + - 'rust-toolchain.toml' + - '.cargo/**' + - 'package.json' + - 'yarn.lock' + - '.yarnrc.yml' + - '.yarn/**' + - '.github/actions/setup-node/**' + - '.github/workflows/native-playground.yml' + native-ui: + - 'blocksuite/**' + - 'packages/ui/**' + - 'packages/frontend/**' + - 'packages/common/store/**' + - 'tools/frame-audit/**' + - 'Cargo.toml' + - 'Cargo.lock' + - 'rust-toolchain.toml' + - '.cargo/**' + - 'package.json' + - 'yarn.lock' + - '.yarnrc.yml' + - '.yarn/**' + - '.oxlintrc.json' + - '.oxfmtrc.json' + - '**/tsconfig*.json' + - '.github/workflows/build-test.yml' + - '.github/workflows/native-playground.yml' web-fast: name: Web Fast Checks @@ -125,7 +185,9 @@ jobs: uses: ./.github/workflows/np-web-build.yml server-harness-check: - name: L0 Tier A, Server Contracts & Test Harness + name: Server Contracts & Test Harness + needs: changes + if: needs.changes.outputs.backend == 'true' runs-on: ubuntu-24.04 env: # One installed toolchain for packages/backend/ and tools/parity-harness alike. @@ -141,9 +203,6 @@ jobs: playwright-install: false full-cache: true - - name: L0 Tier A static gates - run: node scripts/ci/check-l0-tier-a.mjs - - name: Frozen v0.27.5 server contracts run: | node scripts/oracle/extract-v0275-contracts.mjs --check @@ -219,6 +278,8 @@ jobs: lint-and-wasm: name: Lint, Invariants & Wasm Check + needs: changes + if: needs.changes.outputs.native-ui == 'true' runs-on: ubuntu-24.04 defaults: run: @@ -286,6 +347,8 @@ jobs: headless-linux-and-perf: name: Headless Linux, Web Smoke & Perf + needs: changes + if: needs.changes.outputs.native-ui == 'true' runs-on: ubuntu-24.04 defaults: run: @@ -463,6 +526,8 @@ jobs: macos-headless: name: macOS Metal + CoreText Headless + needs: changes + if: needs.changes.outputs.native-ui == 'true' runs-on: macos-15 defaults: run: @@ -527,6 +592,8 @@ jobs: js-room-coop: name: JS Room Coop & Rust-JS E2E + needs: changes + if: needs.changes.outputs.native-ui == 'true' runs-on: ubuntu-24.04 steps: - name: Checkout repository @@ -606,6 +673,8 @@ jobs: cloud-e2e-rust-server: name: Cloud E2E (Rust affine-server) + needs: changes + if: needs.changes.outputs.backend == 'true' runs-on: ubuntu-24.04 timeout-minutes: 25 env: diff --git a/AGENTS.md b/AGENTS.md index 3a7dbed4c5..11050ce490 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,7 +16,7 @@ These rules apply at the repository root on the `darksky/native-playground` bran - **Static gates:** `node scripts/ci/check-l0-tier-a.mjs` has no dependencies and runs in under a second. It guards the `packages/backend/` layering and hygiene. It also guards workflow references and the `waitForTimeout` / `.skip` ratchet in `scripts/ci/l0-ratchet.json`. The ratchet counts can only go down. To lower the ceiling, run the script with `--update-baseline`. -- **Fast lanes:** `native-playground.yml` always runs the L0 Tier-A check and the zero-backend CSF geometry audit (`scripts/ci/check-csf-frame-audit.mjs`). It also always runs the frozen server contract checks (`scripts/oracle`), the `packages/backend/` checks and the `tools/parity-harness` checks. +- **Fast lanes:** `native-playground.yml` always runs the zero-dependency L0 Tier-A check (`scripts/ci/check-l0-tier-a.mjs`) in `changes`. It runs the frozen server contract checks (`scripts/oracle`), `packages/backend/`, `tools/parity-harness`, zero-backend CSF geometry audit (`scripts/ci/check-csf-frame-audit.mjs`), and `cloud-e2e-rust-server` lanes only when backend, contract, harness, or cloud test sources change (`backend`), and it runs the Rust UI and editor lanes (`lint-and-wasm`, `headless-linux-and-perf`, `macos-headless`, and `js-room-coop`) only when client, UI, or BlockSuite sources change (`native-ui`). Topic branches under `darksky/np/mobile-*` compute changed paths against `origin/darksky/np/mobile`. - **Web lanes:** `native-playground.yml` calls `np-web-fast.yml` only when web sources change. That lane runs lint, typecheck and the Node-only Vitest projects. It calls `np-web-build.yml` only when frontend sources change. That lane builds the production bundles of `@affine/web`, `@affine/mobile` and `@affine/admin`. It downloads no Electron or Playwright binaries, and each bundle has eight minutes. diff --git a/packages/frontend/perf/compare-n3.mjs b/packages/frontend/perf/compare-n3.mjs index e2faeb6509..4598b254bb 100644 --- a/packages/frontend/perf/compare-n3.mjs +++ b/packages/frontend/perf/compare-n3.mjs @@ -331,6 +331,12 @@ export function selectBaselineRun(runs, options = null) { typeof options === 'object' && options?.currentCreatedAt ? options.currentCreatedAt : null; + const maxCandidates = + typeof options === 'object' && + Number.isInteger(options?.maxCandidates) && + options.maxCandidates > 0 + ? options.maxCandidates + : 3; const validRuns = runs.filter( run => @@ -384,7 +390,7 @@ export function selectBaselineRun(runs, options = null) { seen.add(sha); distinctPrior.push(run); - if (distinctPrior.length === 3) break; + if (distinctPrior.length === maxCandidates) break; } if (distinctPrior.length === 0) { @@ -1057,29 +1063,26 @@ function downloadArtifactMetricsJson(repo, runId, artifactName) { } /** - * Walk eligible prior runs from oldest (`N-3`) down to newest (`N-1`) and - * choose the oldest run whose artifact loader returns a valid perf-metrics - * payload, plus load intermediate `N-1`/`N-2` payloads for trend & acceptance. + * Walk eligible prior runs from newest to oldest, skipping runs that produced + * no valid perf-metrics artifact (e.g. backend-only or docs-only pushes whose + * native-ui lane was path-filtered), and collect up to 3 valid prior commits + * (`N-1`, `N-2`, `N-3`), using the 3rd valid commit as the `N-3` baseline. */ export function resolveWindowFromEligibleRuns(eligibleRuns, loadRun) { - const loaded = new Array(eligibleRuns.length).fill(null); - - let baselineIdx = -1; - for (let i = eligibleRuns.length - 1; i >= 0; i -= 1) { + const validPayloads = []; + for (let i = 0; i < eligibleRuns.length; i += 1) { const payload = loadRun(eligibleRuns[i]); - if (payload) { - try { - validatePerfMetrics(payload, `run:${eligibleRuns[i].id ?? i}`); - loaded[i] = payload; - baselineIdx = i; - break; - } catch { - // invalid artifact payload; fall back toward newer commit - } + if (!payload) continue; + try { + validatePerfMetrics(payload, `run:${eligibleRuns[i].id ?? i}`); + validPayloads.push(payload); + if (validPayloads.length === 3) break; + } catch { + // invalid artifact payload; skip and continue searching older runs } } - if (baselineIdx === -1) { + if (validPayloads.length === 0) { return { baseline: null, n1: null, @@ -1088,23 +1091,11 @@ export function resolveWindowFromEligibleRuns(eligibleRuns, loadRun) { }; } - // Load newer intermediate runs in the window (for N-1 / N-2 trends & accepted.json checks) - for (let i = 0; i < baselineIdx; i += 1) { - const payload = loadRun(eligibleRuns[i]); - if (payload) { - try { - validatePerfMetrics(payload, `run:${eligibleRuns[i].id ?? i}`); - loaded[i] = payload; - } catch { - loaded[i] = null; - } - } - } - - const baseline = loaded[baselineIdx]; + const baselineIdx = validPayloads.length - 1; + const baseline = validPayloads[baselineIdx]; const baselineDepth = `N-${baselineIdx + 1}`; - const n1 = baselineIdx > 0 ? loaded[0] : null; - const n2 = baselineIdx > 1 ? loaded[1] : null; + const n1 = baselineIdx > 0 ? validPayloads[0] : null; + const n2 = baselineIdx > 1 ? validPayloads[1] : null; return { baseline, n1, n2, baselineDepth }; } @@ -1151,33 +1142,43 @@ function fetchGithubHistory({ : ''; const baseEndpoint = `repos/${repo}/actions/workflows/${encodedWorkflow}/runs?branch=${encodedBranch}&event=push&status=completed&per_page=30${createdFilter}`; + const artifactCache = new Map(); + const loadCachedRun = run => { + if (!artifactCache.has(run.id)) { + artifactCache.set( + run.id, + downloadArtifactMetricsJson(repo, run.id, artifactName) + ); + } + return artifactCache.get(run.id); + }; + const collectedRuns = []; - let selection = { eligibleRuns: [] }; + let resolved = { + baseline: null, + n1: null, + n2: null, + baselineDepth: 'bootstrap', + }; for (let page = 1; page <= 3; page += 1) { const resp = runGhApiJson(`${baseEndpoint}&page=${page}`); const pageRuns = resp.workflow_runs ?? []; collectedRuns.push(...pageRuns); - selection = selectBaselineRun(collectedRuns, { + const selection = selectBaselineRun(collectedRuns, { currentCommit, currentCreatedAt: anchorCreatedAt, + maxCandidates: 90, }); - if (selection.eligibleRuns.length >= 3 || pageRuns.length < 30) { + resolved = resolveWindowFromEligibleRuns( + selection.eligibleRuns, + loadCachedRun + ); + if (resolved.baselineDepth === 'N-3' || pageRuns.length < 30) { break; } } - if (selection.eligibleRuns.length === 0) { - return { - baseline: null, - n1: null, - n2: null, - baselineDepth: 'bootstrap', - }; - } - - return resolveWindowFromEligibleRuns(selection.eligibleRuns, run => - downloadArtifactMetricsJson(repo, run.id, artifactName) - ); + return resolved; } export function parseArgs(argv) { diff --git a/packages/frontend/perf/compare-n3.test.mjs b/packages/frontend/perf/compare-n3.test.mjs index d9130ffeae..d4a2852e34 100644 --- a/packages/frontend/perf/compare-n3.test.mjs +++ b/packages/frontend/perf/compare-n3.test.mjs @@ -198,7 +198,9 @@ test('selectBaselineRun handles bootstrap, rerun deduplication, and strict older assert.equal(empty.baselineDepth, 'bootstrap'); }); -test('resolveWindowFromEligibleRuns falls back from missing N-3 artifact to N-2', () => { +test( + 'resolveWindowFromEligibleRuns falls back to N-2 and skips artifact-less runs', + () => { const s = n => String(n).repeat(40); const eligible = [ { id: 30, head_sha: s(3) }, // N-1 @@ -218,6 +220,40 @@ test('resolveWindowFromEligibleRuns falls back from missing N-3 artifact to N-2' assert.equal(resolved.baseline?.commit, s(2)); assert.equal(resolved.n1?.commit, s(3)); assert.equal(resolved.n2, null); + + // Path-filtered backend/docs runs with no perf-metrics artifact must not + // push valid UI runs out of the N-3 window. + const mkRun = n => ({ + id: n * 10, + head_sha: s(n), + status: 'completed', + conclusion: 'success', + created_at: `2026-11-21T0${n}:00:00Z`, + }); + const mixedRuns = [8, 7, 6, 5, 4, 3, 2, 1].map(mkRun); + const sel = selectBaselineRun(mixedRuns, { + currentCommit: s(8), + maxCandidates: 90, + }); + const mixedPayloads = new Map([ + [70, null], + [60, null], + [50, null], + [40, makeMetrics(s(4))], + [30, makeMetrics(s(3))], + [20, makeMetrics(s(2))], + [10, makeMetrics(s(1))], + ]); + const visited = []; + const mixedResolved = resolveWindowFromEligibleRuns(sel.eligibleRuns, r => { + visited.push(r.id); + return mixedPayloads.get(r.id); + }); + assert.equal(mixedResolved.baselineDepth, 'N-3'); + assert.equal(mixedResolved.baseline?.commit, s(2)); + assert.equal(mixedResolved.n1?.commit, s(4)); + assert.equal(mixedResolved.n2?.commit, s(3)); + assert.deepEqual(visited, [70, 60, 50, 40, 30, 20]); }); test('selectPerfMetricsZipEntry rejects verdict-only zips and never falls back to arbitrary json', () => {