Files
AFFiNE/.github/workflows/native-playground.yml
T

862 lines
37 KiB
YAML

name: Native Playground CI
on:
push:
branches:
- 'darksky/native-playground'
- 'darksky/np/**'
concurrency:
group: native-playground-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_ENCODED_RUSTFLAGS: ''
CARGO_INCREMENTAL: '0'
CARGO_NET_GIT_FETCH_WITH_CLI: 'true'
CARGO_PROFILE_DEV_DEBUG: '0'
CARGO_PROFILE_TEST_DEBUG: '0'
CARGO_TERM_COLOR: always
jobs:
changes:
name: Changed Paths
runs-on: ubuntu-24.04
outputs:
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 }}
web-host-only: ${{ steps.classify.outputs.web_host_only }}
desktop-leaf-only: ${{ steps.classify.outputs.desktop_leaf_only }}
desktop-rs-only: ${{ steps.classify.outputs.desktop_rs_only }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 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 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
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
git fetch --no-tags --depth=50 origin darksky/np/mobile:refs/remotes/origin/darksky/np/mobile >/dev/null 2>&1 || true
fi
if git rev-parse --verify origin/darksky/np/mobile >/dev/null 2>&1; then
sha=$(git merge-base origin/darksky/np/mobile HEAD 2>/dev/null || true)
elif git rev-parse --verify origin/darksky/native-playground >/dev/null 2>&1; then
sha=$(git merge-base origin/darksky/native-playground HEAD 2>/dev/null || true)
else
sha=$(git merge-base origin/canary HEAD 2>/dev/null || true)
fi
;;
*)
if git rev-parse --verify origin/darksky/native-playground >/dev/null 2>&1; then
sha=$(git merge-base origin/darksky/native-playground HEAD 2>/dev/null || true)
else
sha=$(git merge-base origin/canary HEAD 2>/dev/null || true)
fi
;;
esac
if [ -z "$sha" ]; then
force_all=true
sha=$(git rev-parse HEAD~1 2>/dev/null || git rev-parse HEAD)
fi
echo "sha=$sha" >> "$GITHUB_OUTPUT"
echo "force_all=$force_all" >> "$GITHUB_OUTPUT"
- name: Classify web host and Desktop leaf changes
id: classify
env:
BASE: ${{ steps.base.outputs.sha }}
FORCE_ALL: ${{ steps.base.outputs.force_all }}
run: |
node scripts/ci/classify-web-host-only.mjs \
--base "$BASE" \
--force-all "$FORCE_ALL" \
--ref "$GITHUB_REF" \
--github-output "$GITHUB_OUTPUT"
- name: Detect changed paths
id: filter
uses: dorny/paths-filter@v3
with:
base: ${{ steps.base.outputs.sha }}
# JavaScript under scripts/oracle and tools/parity-harness also runs
# the web lane: its lint and format checks cover those files.
filters: |
web:
- '**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,css}'
- '**/package.json'
- '**/tsconfig*.json'
- 'yarn.lock'
- '.yarnrc.yml'
- '.yarn/**'
- '.oxlintrc.json'
- '.oxfmtrc.json'
- '.prettierignore'
- '.github/actions/setup-node/**'
- '.github/workflows/np-web-fast.yml'
web-build:
- 'packages/frontend/admin/**'
- 'packages/frontend/apps/**'
- 'packages/frontend/component/**'
- 'packages/frontend/core/**'
- 'packages/frontend/electron-api/**'
- 'packages/frontend/i18n/**'
- 'packages/frontend/mobile-native/**'
- 'packages/frontend/native/**'
- 'packages/frontend/routes/**'
- 'packages/frontend/templates/**'
- 'packages/frontend/track/**'
- 'packages/common/auth/**'
- 'packages/common/debug/**'
- 'packages/common/env/**'
- 'packages/common/error/**'
- 'packages/common/graphql/**'
- 'packages/common/infra/**'
- 'packages/common/native/**'
- 'packages/common/nbstore/**'
- 'packages/common/reader/**'
- 'packages/common/realtime/**'
- 'packages/common/s3-compat/**'
- 'packages/common/theme/**'
- 'blocksuite/affine/**'
- 'blocksuite/framework/**'
- 'blocksuite/playground/**'
- 'blocksuite/integration-test/**'
- 'blocksuite/docs/**'
- 'blocksuite/docs-site/**'
- 'blocksuite/tsconfig.json'
- 'tools/cli/**'
- '**/package.json'
- '**/tsconfig*.json'
- 'yarn.lock'
- '.yarnrc.yml'
- '.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/np-backend.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
needs: changes
if: needs.changes.outputs.web == 'true'
uses: ./.github/workflows/np-web-fast.yml
web-build:
name: Web Build
needs: changes
if: needs.changes.outputs.web-build == 'true'
uses: ./.github/workflows/np-web-build.yml
backend-checks:
name: Backend Checks
needs: changes
if: needs.changes.outputs.backend == 'true'
uses: ./.github/workflows/np-backend.yml
lint-and-wasm:
name: Lint, Invariants & Wasm Check
needs: changes
if: needs.changes.outputs.native-ui == 'true'
runs-on: ubuntu-24.04
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Linux fontconfig headers
run: |
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
sudo apt-get install -y libfontconfig1-dev libfreetype-dev
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: lint-wasm
- name: Format check
run: |
t0=$(date +%s)
cargo fmt --all -- --check
echo "Format check $(( $(date +%s) - t0 ))" >> /tmp/np-lint-timings.tsv
- name: Clippy check
run: |
t0=$(date +%s)
cargo clippy --locked --workspace --all-targets --features harness -- -D warnings
echo "Clippy check $(( $(date +%s) - t0 ))" >> /tmp/np-lint-timings.tsv
- name: Static invariants and link-flag check
run: |
t0=$(date +%s)
./scripts/check-invariants.sh
echo "Static invariants $(( $(date +%s) - t0 ))" >> /tmp/np-lint-timings.tsv
- name: Perf guardrail self-tests and generated token/icon unit tests
run: |
t0=$(date +%s)
node --test perf/compare-n3.test.mjs
rustc --edition 2024 --test -D warnings ../ui/tokens/tokens.rs -o /tmp/tokens_test && /tmp/tokens_test
rustc --edition 2024 --test -D warnings ../ui/tokens/icons.rs -o /tmp/icons_test && /tmp/icons_test
rm -f /tmp/tokens_test /tmp/icons_test
echo "Perf and token unit tests $(( $(date +%s) - t0 ))" >> /tmp/np-lint-timings.tsv
- name: Verify generated tokens, icons, and fonts.lock have zero drift
run: |
t0=$(date +%s)
THEME_VER=$(awk '/^"@toeverything\/theme@/{f=1} f && /version:/{print $2; exit}' ../../yarn.lock)
ICONS_VER=$(awk '/^"@blocksuite\/icons@/{f=1} f && /version:/{print $2; exit}' ../../yarn.lock)
rm -rf /tmp/np-token-deps
mkdir -p /tmp/np-token-deps/node_modules/@toeverything/theme /tmp/np-token-deps/node_modules/@blocksuite/icons
curl -fsSL "https://registry.npmjs.org/@toeverything/theme/-/theme-${THEME_VER}.tgz" \
| tar -xz --strip-components=1 -C /tmp/np-token-deps/node_modules/@toeverything/theme
curl -fsSL "https://registry.npmjs.org/@blocksuite/icons/-/icons-${ICONS_VER}.tgz" \
| tar -xz --strip-components=1 -C /tmp/np-token-deps/node_modules/@blocksuite/icons
node ../ui/tokens/extract-tokens.mjs --check --node-modules /tmp/np-token-deps/node_modules
rm -rf /tmp/np-token-deps
echo "Token and font drift check $(( $(date +%s) - t0 ))" >> /tmp/np-lint-timings.tsv
- name: Check WebAssembly target
run: |
t0=$(date +%s)
cargo check --locked -p ui-tokens -p ui -p ui-kit -p blocksuite-editor -p playground --target wasm32-unknown-unknown
cargo check --locked -p blocksuite-playground-doc --no-default-features --target wasm32-unknown-unknown
cargo check --locked -p affine-store --no-default-features --target wasm32-unknown-unknown
cargo check --locked -p blocksuite-preview --no-default-features --features mermaid,wasm-worker --target wasm32-unknown-unknown
cargo check --locked -p blocksuite-preview --no-default-features --features math,wasm-worker --target wasm32-unknown-unknown
cargo check --locked -p blocksuite-preview --no-default-features --features typst,wasm-worker --target wasm32-unknown-unknown
cargo check --locked -p blocksuite-preview --no-default-features --features pdf,wasm-worker --target wasm32-unknown-unknown
echo "Check WebAssembly target $(( $(date +%s) - t0 ))" >> /tmp/np-lint-timings.tsv
- name: Summarize step timings
if: always()
run: |
if [ -s /tmp/np-lint-timings.tsv ]; then
{
echo "### Lint, Invariants & Wasm Check Step Timings"
echo "| Step | Duration (s) |"
echo "|---|---:|"
awk -F'\t' '{ printf "| %s | %s |\n", $1, $2 }' /tmp/np-lint-timings.tsv
} >> "$GITHUB_STEP_SUMMARY"
fi
web-wasm-smoke:
name: WebAssembly Bundle & Chromium Smoke
needs: changes
if: needs.changes.outputs.native-ui == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
outputs:
wasm_raw: ${{ steps.wasm.outputs.raw }}
wasm_gzip: ${{ steps.wasm.outputs.gzip }}
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Mesa Lavapipe Vulkan driver, headers, and CJK/Emoji fallback fonts
run: |
t0=$(date +%s)
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends mesa-vulkan-drivers libvulkan1 libfontconfig1-dev libfreetype-dev lld fonts-wqy-zenhei fonts-noto-color-emoji
echo "Install system packages $(( $(date +%s) - t0 ))" >> /tmp/np-wasm-timings.tsv
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
with:
targets: wasm32-unknown-unknown
- name: Install wasm-bindgen CLI and Binaryen wasm-opt
run: |
t0=$(date +%s)
WBG_VERSION=$(awk '/^name = "wasm-bindgen"$/{getline; gsub(/"/, "", $3); print $3; exit}' Cargo.lock)
URL="https://github.com/wasm-bindgen/wasm-bindgen/releases/download/${WBG_VERSION}/wasm-bindgen-${WBG_VERSION}-x86_64-unknown-linux-musl.tar.gz"
if curl -fsSL "$URL" -o /tmp/wbg.tar.gz; then
tar -xzf /tmp/wbg.tar.gz -C /tmp
sudo install -m 0755 "/tmp/wasm-bindgen-${WBG_VERSION}-x86_64-unknown-linux-musl/wasm-bindgen" /usr/local/bin/wasm-bindgen
else
cargo install --locked wasm-bindgen-cli --version "$WBG_VERSION"
fi
wasm-bindgen --version
BINARYEN_VERSION="version_123"
BINARYEN_SHA256="e959f2170af4c20c552e9de3a0253704d6a9d2766e8fdb88e4d6ac4bae9388fe"
curl -fsSL "https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz" \
-o /tmp/binaryen.tar.gz
echo "${BINARYEN_SHA256} /tmp/binaryen.tar.gz" | sha256sum -c -
tar -xzf /tmp/binaryen.tar.gz -C /tmp
rm -f /tmp/binaryen.tar.gz
sudo install -m 0755 "/tmp/binaryen-${BINARYEN_VERSION}/bin/wasm-opt" /usr/local/bin/wasm-opt
wasm-opt --version
echo "Install Wasm tools $(( $(date +%s) - t0 ))" >> /tmp/np-wasm-timings.tsv
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: web-wasm-smoke
- name: Build production WebAssembly bundles and check snapshot prefixes
id: wasm
run: |
t0=$(date +%s)
playground_pkg=../../blocksuite/crates/playground/web/pkg
desktop_pkg=artifacts/desktop-pkg
wasm_target=target/wasm32-unknown-unknown/wasm-release-size
mkdir -p "$playground_pkg" "$desktop_pkg"
WASM_RUSTFLAGS="$(printf '%s\037%s\037%s' "--remap-path-prefix=$(cd ../.. && pwd)=/src" "--remap-path-prefix=${CARGO_HOME:-$HOME/.cargo}=/cargo" "-Ctarget-feature=+simd128")"
CARGO_ENCODED_RUSTFLAGS="$WASM_RUSTFLAGS" cargo build --locked --profile wasm-release-size -p playground --lib --target wasm32-unknown-unknown
CARGO_ENCODED_RUSTFLAGS="$WASM_RUSTFLAGS" cargo rustc --locked --profile wasm-release-size -p affine-desktop --lib --target wasm32-unknown-unknown --crate-type cdylib
optimize_bundle() {
local name="$1" pkg="$2"
wasm-bindgen --target web --out-dir "$pkg" "$wasm_target/$name.wasm"
wasm-opt -Oz --strip-debug --strip-producers \
--enable-bulk-memory \
--enable-nontrapping-float-to-int \
--enable-sign-ext \
--enable-mutable-globals \
--enable-simd \
"$pkg/${name}_bg.wasm" -o "$pkg/${name}_bg.opt.wasm"
}
optimize_bundle playground "$playground_pkg"
optimize_bundle affine_desktop "$desktop_pkg"
node scripts/check-snapshot-prefixes.mjs \
"$playground_pkg/playground_bg.opt.wasm" \
"$desktop_pkg/affine_desktop_bg.opt.wasm"
mv "$playground_pkg/playground_bg.opt.wasm" "$playground_pkg/playground_bg.wasm"
mv "$desktop_pkg/affine_desktop_bg.opt.wasm" "$desktop_pkg/affine_desktop_bg.wasm"
WASM_RAW=$(wc -c < "$playground_pkg/playground_bg.wasm" | tr -d ' ')
WASM_GZIP=$(gzip -9 -c "$playground_pkg/playground_bg.wasm" | wc -c | tr -d ' ')
echo "raw=$WASM_RAW" >> "$GITHUB_OUTPUT"
echo "gzip=$WASM_GZIP" >> "$GITHUB_OUTPUT"
echo "Build Wasm bundles $(( $(date +%s) - t0 ))" >> /tmp/np-wasm-timings.tsv
- name: Run headless Chromium Web smoke test
run: |
t0=$(date +%s)
mkdir -p artifacts
node scripts/web-smoke.mjs \
--out artifacts/wasm-chromium.png \
--out-edgeless artifacts/wasm-chromium-edgeless.png
test -s artifacts/wasm-chromium.png
test -s artifacts/wasm-chromium-edgeless.png
echo "Chromium Web smoke $(( $(date +%s) - t0 ))" >> /tmp/np-wasm-timings.tsv
- name: Run headless Chromium Desktop persistence smoke
run: |
t0=$(date +%s)
node hosts/web/scripts/verify-desktop-persistence.mjs \
--pkg artifacts/desktop-pkg \
--out artifacts/desktop-persistence
echo "Chromium Desktop persistence $(( $(date +%s) - t0 ))" >> /tmp/np-wasm-timings.tsv
- name: Upload Web smoke artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: web-wasm-smoke-artifacts
path: |
packages/frontend/artifacts/wasm-chromium.png
packages/frontend/artifacts/wasm-chromium-edgeless.png
packages/frontend/artifacts/desktop-persistence/*.png
if-no-files-found: ignore
- name: Summarize step timings
if: always()
run: |
if [ -s /tmp/np-wasm-timings.tsv ]; then
{
echo "### WebAssembly Bundle & Chromium Smoke Step Timings"
echo "| Step | Duration (s) |"
echo "|---|---:|"
awk -F'\t' '{ printf "| %s | %s |\n", $1, $2 }' /tmp/np-wasm-timings.tsv
} >> "$GITHUB_STEP_SUMMARY"
fi
headless-linux-and-perf:
name: Headless Linux, Web Smoke & Perf
needs: changes
if: needs.changes.outputs.native-ui == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 25
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Mesa Lavapipe Vulkan driver, headers, and CJK/Emoji fallback fonts
run: |
t0=$(date +%s)
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends mesa-vulkan-drivers libvulkan1 libfontconfig1-dev libfreetype-dev lld fonts-wqy-zenhei fonts-noto-color-emoji
echo "Install system packages $(( $(date +%s) - t0 ))" >> /tmp/np-headless-timings.tsv
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: headless-linux
- name: Test Desktop on Linux (default and harness)
if: needs.changes.outputs.desktop-leaf-only == 'true'
run: |
t0=$(date +%s)
cargo test --locked -p affine-desktop
cargo test --locked -p affine-desktop --features harness --bin desktop-harness
cargo check --locked -p affine-desktop --all-targets --features harness
echo "Desktop tests (default + harness) $(( $(date +%s) - t0 ))" >> /tmp/np-headless-timings.tsv
- name: Run workspace unit tests (default)
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
t0=$(date +%s)
cargo test --locked --workspace
echo "Workspace tests (default) $(( $(date +%s) - t0 ))" >> /tmp/np-headless-timings.tsv
- name: Run workspace unit tests (harness)
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
t0=$(date +%s)
cargo test --locked -p ui --features harness --test bidi_multiline_controls --test touch_dispatch
cargo test --locked --workspace --features harness --bin bs-harness --bin desktop-harness --bin mobile-harness
echo "Workspace tests (harness) $(( $(date +%s) - t0 ))" >> /tmp/np-headless-timings.tsv
- name: Deterministic headless render, audit, 4-fps check, and 30-frame bench
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
t0=$(date +%s)
CARGO_ENCODED_RUSTFLAGS="" cargo build --locked --workspace --features harness --bin bs-harness --tests
mkdir -p artifacts
./target/debug/bs-harness render \
--out artifacts/linux-run1.png \
--snapshot artifacts/linux-run1.json \
--width 1280 \
--height 800
./target/debug/bs-harness render \
--out artifacts/linux-run2.png \
--snapshot artifacts/linux-run2.json \
--width 1280 \
--height 800
test -s artifacts/linux-run1.png
test -s artifacts/linux-run1.json
sha1=$(sha256sum artifacts/linux-run1.png | awk '{print $1}')
sha2=$(sha256sum artifacts/linux-run2.png | awk '{print $1}')
echo "Run 1 SHA256: $sha1"
echo "Run 2 SHA256: $sha2"
test "$sha1" = "$sha2"
./target/debug/bs-harness audit --snapshot artifacts/linux-run1.json
./target/debug/bs-harness audit-states
./target/debug/bs-harness fps-check
./target/debug/bs-harness bench \
--json artifacts/perf-metrics.json \
--commit "${{ github.sha }}"
test -s artifacts/perf-metrics.json
echo "Render, audit, fps, and bench $(( $(date +%s) - t0 ))" >> /tmp/np-headless-timings.tsv
- name: Upload raw perf metrics artifact
if: needs.changes.outputs.desktop-leaf-only != 'true'
uses: actions/upload-artifact@v4
with:
name: headless-perf-raw
path: packages/frontend/artifacts/perf-metrics.json
if-no-files-found: error
- name: Upload Linux headless artifacts
if: always() && needs.changes.outputs.desktop-leaf-only != 'true'
uses: actions/upload-artifact@v4
with:
name: headless-linux-artifacts
path: |
packages/frontend/artifacts/linux-run1.png
packages/frontend/artifacts/linux-run1.json
if-no-files-found: ignore
- name: Summarize step timings
if: always()
run: |
if [ -s /tmp/np-headless-timings.tsv ]; then
{
echo "### Headless Linux Step Timings"
echo "| Step | Duration (s) |"
echo "|---|---:|"
awk -F'\t' '{ printf "| %s | %s |\n", $1, $2 }' /tmp/np-headless-timings.tsv
} >> "$GITHUB_STEP_SUMMARY"
fi
perf-guardrail:
name: Perf N-3 Guardrail
needs: [changes, headless-linux-and-perf, web-wasm-smoke]
if: needs.changes.outputs.native-ui == 'true' && needs.changes.outputs.desktop-leaf-only != 'true'
runs-on: ubuntu-24.04
timeout-minutes: 5
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download raw perf metrics
uses: actions/download-artifact@v4
with:
name: headless-perf-raw
path: packages/frontend/artifacts
- name: Merge Wasm sizes and compare against rolling N-3 baseline
env:
GH_TOKEN: ${{ github.token }}
NP_ALLOW_PERF_BOOTSTRAP: ${{ vars.NP_ALLOW_PERF_BOOTSTRAP }}
WASM_RAW: ${{ needs.web-wasm-smoke.outputs.wasm_raw }}
WASM_GZIP: ${{ needs.web-wasm-smoke.outputs.wasm_gzip }}
run: |
node -e '
const fs = require("node:fs");
const p = "artifacts/perf-metrics.json";
const m = JSON.parse(fs.readFileSync(p, "utf8"));
for (const [key, value] of [
["web_wasm_raw", process.env.WASM_RAW],
["web_wasm_gzip", process.env.WASM_GZIP],
]) {
const bytes = Number(value);
if (!Number.isSafeInteger(bytes) || bytes <= 0) {
throw new Error(`Invalid Wasm size for ${key}: ${value}`);
}
m.artifacts_bytes[key] = bytes;
}
fs.writeFileSync(p, JSON.stringify(m, null, 2) + "\n");
'
test -f perf/compare-n3.mjs
STRICT_PERF_FLAG="--require-n3"
if [ "${NP_ALLOW_PERF_BOOTSTRAP:-0}" = "1" ]; then
STRICT_PERF_FLAG=""
fi
node perf/compare-n3.mjs \
--fetch-github \
--repo "${{ github.repository }}" \
--branch darksky/native-playground \
--workflow native-playground.yml \
--run-id "${{ github.run_id }}" \
--current artifacts/perf-metrics.json \
--json-out artifacts/perf-verdict.json \
$STRICT_PERF_FLAG \
--fail-on-regression >> "$GITHUB_STEP_SUMMARY"
test -s artifacts/perf-verdict.json
node -e '
const fs = require("node:fs");
const v = JSON.parse(fs.readFileSync("artifacts/perf-verdict.json", "utf8"));
const allowBootstrap = process.env.NP_ALLOW_PERF_BOOTSTRAP === "1";
const shaRe = /^[0-9a-f]{40}$/;
if (
(!allowBootstrap && (v.baseline_depth !== "N-3" || !shaRe.test(v.baseline_commit || ""))) ||
(allowBootstrap && v.baseline_depth !== "bootstrap" && !shaRe.test(v.baseline_commit || "")) ||
!Array.isArray(v.metrics) ||
v.metrics.length === 0
) {
throw new Error(`Invalid perf-verdict.json: baseline_depth=${v.baseline_depth}, baseline_commit=${v.baseline_commit}, metrics=${v.metrics?.length}`);
}
const dropped = v.metrics.filter(m => m.status === "DROPPED");
if (dropped.length > 0) {
throw new Error(`Unacknowledged dropped baseline metrics: ${dropped.map(m => m.key).join(", ")}`);
}
const unacceptedBootstrap = v.metrics.filter(m => m.status === "BOOTSTRAP");
if (!allowBootstrap && unacceptedBootstrap.length > 0) {
throw new Error(`Unacknowledged BOOTSTRAP metrics against N-3 baseline: ${unacceptedBootstrap.map(m => m.key).join(", ")}`);
}
const compared = v.metrics.filter(m => m.baseline != null && m.current != null);
if (!allowBootstrap && compared.length === 0) {
throw new Error("No metrics were compared against prior N-3 baseline history");
}
console.log(`perf-verdict.json verified: ${v.baseline_depth} (${(v.baseline_commit || "none").slice(0, 10)}), ${v.metrics.length} metrics, ${unacceptedBootstrap.length} unacknowledged bootstrap, 0 dropped`);
'
- name: Upload perf metrics artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: perf-metrics
path: |
packages/frontend/artifacts/perf-metrics.json
packages/frontend/artifacts/perf-verdict.json
if-no-files-found: ignore
macos-headless:
name: macOS Metal + CoreText Headless
needs: changes
if: needs.changes.outputs.native-ui == 'true' && needs.changes.outputs.web-host-only != 'true'
runs-on: macos-15
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: macos-headless
- name: Check workspace all targets
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: cargo check --locked --workspace --all-targets --features harness
- name: Check iOS device and simulator targets
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
rustup target add aarch64-apple-ios aarch64-apple-ios-sim
CARGO_ENCODED_RUSTFLAGS="" cargo check --locked -p ui-tokens -p ui -p ui-kit --target aarch64-apple-ios
CARGO_ENCODED_RUSTFLAGS="" cargo check --locked -p ui-tokens -p ui -p ui-kit --target aarch64-apple-ios-sim
- name: Run UI, doc, editor, and playground tests (default and harness)
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
cargo test --locked -p ui-tokens -p ui -p ui-kit -p blocksuite-playground-doc -p blocksuite-editor -p playground
cargo test --locked -p ui --features harness --test bidi_multiline_controls --test touch_dispatch --test metal_atlas_fence
cargo test --locked -p playground --features harness --bin bs-harness
cargo check --locked -p ui-tokens -p ui -p ui-kit -p blocksuite-playground-doc -p blocksuite-editor -p playground --all-targets --features harness
- name: Test Desktop on macOS
if: needs.changes.outputs.desktop-leaf-only == 'true'
run: |
cargo test --locked -p affine-desktop
cargo check --locked -p affine-desktop --all-targets --features harness
- name: Deterministic Metal headless render and audit
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
mkdir -p artifacts
cargo run --locked --bin bs-harness --features harness -- render \
--out artifacts/macos-run1.png \
--snapshot artifacts/macos-run1.json \
--width 1280 \
--height 800
cargo run --locked --bin bs-harness --features harness -- render \
--out artifacts/macos-run2.png \
--snapshot artifacts/macos-run2.json \
--width 1280 \
--height 800
test -s artifacts/macos-run1.png
test -s artifacts/macos-run1.json
sha1=$(shasum -a 256 artifacts/macos-run1.png | awk '{print $1}')
sha2=$(shasum -a 256 artifacts/macos-run2.png | awk '{print $1}')
echo "Run 1 SHA256: $sha1"
echo "Run 2 SHA256: $sha2"
test "$sha1" = "$sha2"
cargo run --locked --bin bs-harness --features harness -- audit --snapshot artifacts/macos-run1.json
- name: Upload macOS headless artifacts
if: needs.changes.outputs.desktop-leaf-only != 'true'
uses: actions/upload-artifact@v4
with:
name: headless-macos-artifacts
path: |
packages/frontend/artifacts/macos-run1.png
packages/frontend/artifacts/macos-run1.json
if-no-files-found: error
js-room-coop:
name: JS Room Coop & Rust-JS E2E
needs: changes
if: needs.changes.outputs.native-ui == 'true' && needs.changes.outputs.desktop-rs-only != 'true'
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Enable Corepack and cache Yarn
run: corepack enable
- name: Cache Yarn
uses: actions/cache@v4
with:
path: |
.yarn/cache
node_modules
key: ${{ runner.os }}-yarn-np-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-np-
- name: Install JS dependencies
run: yarn install --immutable
- name: Warm Chromium binary into OS page cache
run: |
CHROME_WARM_BIN=${CHROME_PATH:-${CHROME_BIN:-}}
if [ -z "$CHROME_WARM_BIN" ]; then
wrapper=
for bin in /usr/bin/google-chrome-stable /usr/bin/google-chrome /usr/bin/chromium /usr/bin/chromium-browser; do
[ -e "$bin" ] || continue
if [ "$(head -c 2 "$bin" 2>/dev/null)" = '#!' ]; then
wrapper=${wrapper:-$bin}
else
CHROME_WARM_BIN=$bin
break
fi
done
if [ -z "$CHROME_WARM_BIN" ] && [ -d "$HOME/.cache/ms-playwright" ]; then
CHROME_WARM_BIN=$(find "$HOME/.cache/ms-playwright" -name chrome -type f -print -quit)
fi
CHROME_WARM_BIN=${CHROME_WARM_BIN:-$wrapper}
fi
if [ -z "$CHROME_WARM_BIN" ] || [ ! -e "$CHROME_WARM_BIN" ]; then
echo "warning: skipping Chromium warm-up (no binary found)" >&2
exit 0
fi
WARM_PROFILE=$(mktemp -d "${TMPDIR:-/tmp}/np-chrome-warm.XXXXXX")
trap 'rm -rf "$WARM_PROFILE"' EXIT
status=0
timeout --kill-after=2s 20s "$CHROME_WARM_BIN" --headless=new --no-sandbox --disable-gpu --disable-dbus --disable-dev-shm-usage --user-data-dir="$WARM_PROFILE" --dump-dom about:blank >/dev/null || status=$?
rm -rf "$WARM_PROFILE"
trap - EXIT
if [ "$status" -ne 0 ]; then
echo "warning: Chromium warm-up exited with status $status; continuing to test harness" >&2
fi
- name: Test Web host behavior in Chromium
run: node --test --test-concurrency=1 packages/frontend/hosts/web/tests/*.browser.mjs
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: js-room-coop
- name: Build bs-relay and bs_doc_driver
working-directory: packages/frontend
run: cargo build --locked -p blocksuite-playground-doc --bin bs-relay --example bs_doc_driver
- name: Verify JS-authored surface snapshots without writeback
working-directory: packages/frontend
run: cargo test --locked -p blocksuite-playground-doc --example bs_doc_driver js_authored_surface
- name: Lint, format, and typecheck JS room sync
run: |
yarn oxlint --deny-warnings \
blocksuite/framework/sync/src/doc/source.ts \
blocksuite/framework/sync/src/doc/peer.ts \
blocksuite/framework/sync/src/__tests__/peer.unit.spec.ts \
blocksuite/playground/apps/_common/sync/blob/mock-server.ts \
blocksuite/playground/apps/_common/sync/room/index.ts \
blocksuite/playground/apps/_common/sync/room/__tests__/room-sync.spec.ts \
blocksuite/playground/apps/starter/utils/collection.ts \
blocksuite/playground/vite.config.ts \
blocksuite/playground/vitest.config.ts
yarn oxfmt --check \
blocksuite/framework/sync/src/doc/source.ts \
blocksuite/framework/sync/src/doc/peer.ts \
blocksuite/framework/sync/src/__tests__/peer.unit.spec.ts \
blocksuite/playground/apps/_common/sync/blob/mock-server.ts \
blocksuite/playground/apps/_common/sync/room/index.ts \
blocksuite/playground/apps/_common/sync/room/__tests__/room-sync.spec.ts \
blocksuite/playground/apps/starter/utils/collection.ts \
blocksuite/playground/vite.config.ts \
blocksuite/playground/vitest.config.ts
./node_modules/.bin/tsc -b \
blocksuite/framework/sync/tsconfig.json \
blocksuite/playground/tsconfig.json
- name: Verify surface geometry oracle and live Rust-JS room sync
env:
BS_RELAY_BIN: ${{ github.workspace }}/packages/frontend/target/debug/bs-relay
BS_DOC_DRIVER_BIN: ${{ github.workspace }}/packages/frontend/target/debug/examples/bs_doc_driver
run: |
(cd blocksuite/framework/sync && ../../../node_modules/.bin/vitest run)
(cd blocksuite/playground && ../../node_modules/.bin/vitest run)