Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ outputs:
runs:
using: 'composite'
steps:
- name: Install dependencies from Namespace volume
if: env.CI_BENCHMARK_PROVIDER == 'namespace'
uses: ./.github/actions/install-namespace-dependencies

- name: Install pnpm
if: env.CI_BENCHMARK_PROVIDER != 'namespace'
uses: ./.github/actions/install-pnpm

- name: Compute dependency cache key
Expand All @@ -20,11 +25,19 @@ runs:
- name: Check dependency cache
uses: actions/cache@v6.1.0
id: cache_dependencies
if: env.CI_BENCHMARK_PROVIDER != 'namespace'
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}-${{ runner.arch }}
key: ${{ env.CI_BENCHMARK_CACHE_PREFIX }}${{ steps.compute_lockfile_hash.outputs.hash }}-${{ runner.arch }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit != 'true'
if: env.CI_BENCHMARK_PROVIDER != 'namespace' && steps.cache_dependencies.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
shell: bash

- name: Report benchmark dependency cache
if: env.CI_BENCHMARK_CACHE_PREFIX != '' && env.CI_BENCHMARK_PROVIDER != 'namespace'
run:
echo "BENCHMARK_CACHE provider=github kind=workspace-node-modules hit=${{
steps.cache_dependencies.outputs.cache-hit }}"
shell: bash
64 changes: 64 additions & 0 deletions .github/actions/install-namespace-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Install pnpm dependencies'
description: 'Installs pnpm dependencies into node_modules folders on the Namespace cache volume.'

runs:
using: 'composite'
steps:
- name: List dependency paths
id: paths
run: |
{
echo 'paths<<EOF'
node -e 'const { workspaces } = require("./package.json"); for (const dir of [".", ...workspaces]) console.log(require("path").resolve(dir, "node_modules"))'
echo '~/.cache/mongodb-binaries'
echo '~/.cache/prisma'
echo 'EOF'
} >> "$GITHUB_OUTPUT"
shell: bash

- name: Mount dependency cache
uses: ./.github/actions/mount-pnpm-store
with:
path: ${{ steps.paths.outputs.paths }}

- name: Install pnpm
uses: ./.github/actions/install-pnpm

# When the node_modules layout changes, `pnpm install` keeps the `.bin` scripts of the workspace packages, which
# then point into a folder that the new layout does not have. Branches that change `nodeLinker` share this cache
# volume, so start from empty node_modules folders when the layout on the volume differs, or when an earlier
# install already left such broken `.bin` scripts behind.
- name: Remove node_modules of another layout
run: |
mapfile -t dirs < <(grep '/node_modules$' <<< "$DEPENDENCY_PATHS")
expected=$(pnpm config get node-linker)
if [[ "$expected" == undefined ]]; then
expected=isolated
fi
actual=$(sed -n 's/^nodeLinker: //p' node_modules/.modules.yaml 2>/dev/null || true)
if [[ -n "$actual" && "$actual" != "$expected" ]]; then
reason="The node_modules folders use the $actual layout, but nodeLinker is $expected."
else
broken=$(node "$GITHUB_ACTION_PATH/find-broken-bin.mjs" "${dirs[@]}")
if [[ -n "$broken" ]]; then
reason="The target of $broken does not exist."
fi
fi
if [[ -n "$reason" ]]; then
echo "$reason Removing the node_modules folders."
for dir in "${dirs[@]}"; do
if [[ -d "$dir" ]]; then
# The folders are mounted from the cache volume, so empty them instead of removing them
find "$dir/" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
fi
done
fi
env:
DEPENDENCY_PATHS: ${{ steps.paths.outputs.paths }}
shell: bash

# The cache volume can hold node_modules of another commit or branch. This is a no-op when they match
# pnpm-lock.yaml.
- name: Install dependencies
run: pnpm install --frozen-lockfile
shell: bash
34 changes: 34 additions & 0 deletions .github/actions/install-namespace-dependencies/find-broken-bin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Prints the first `.bin` entry in the given node_modules folders whose target does not exist.
import { existsSync, lstatSync, readdirSync, readFileSync } from 'node:fs';
import { join, resolve } from 'node:path';

// The pnpm shell shim runs the target with `exec <node> "$basedir_abs/<path>"` (`$basedir` in older versions)
const SHIM_TARGET = /^\s*exec \S+\s+"\$basedir(?:_abs)?\/([^"]+)"/m;

for (const dir of process.argv.slice(2)) {
const binDir = join(dir, '.bin');
let names;
try {
names = readdirSync(binDir);
} catch {
continue;
}

for (const name of names) {
const bin = join(binDir, name);
const stat = lstatSync(bin);
let target;
if (stat.isSymbolicLink()) {
target = bin;
} else if (stat.isFile() && stat.size < 64 * 1024) {
const match = readFileSync(bin, 'utf8').match(SHIM_TARGET);
target = match && resolve(binDir, match[1]);
}

if (target && !existsSync(target)) {
// eslint-disable-next-line no-console
console.log(bin);
process.exit(0);
}
}
}
63 changes: 51 additions & 12 deletions .github/actions/install-playwright/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,32 @@ runs:
shell: bash
working-directory: ${{ inputs.cwd }}

- name: Mount Playwright browser cache
id: playwright-volume
if: steps.playwright-version.outputs.version != '' && env.CI_BENCHMARK_PROVIDER == 'namespace'
uses: namespacelabs/nscloud-cache-action@1124a6f3ce44e5cf84cc22111530961f4d2a15f9 # v1.7.0
with:
path: ~/.cache/ms-playwright

- name: Restore cached playwright binaries
uses: actions/cache/restore@v6.1.0
id: playwright-cache
if: steps.playwright-version.outputs.version != ''
if: steps.playwright-version.outputs.version != '' && env.CI_BENCHMARK_PROVIDER != 'namespace'
with:
path: |
~/.cache/ms-playwright
# Bump the iteration when bumping runner images to use a new cache
key: playwright-${{ runner.os }}-iteration-1-${{ steps.playwright-version.outputs.version }}
key:
${{ env.CI_BENCHMARK_CACHE_PREFIX }}playwright-${{ runner.os }}-${{ runner.arch }}-iteration-1-${{
steps.playwright-version.outputs.version }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playwright always reinstalls on Namespace

Medium Severity

On Namespace the Playwright restore step is skipped, so cache-hit is never true and npx playwright install always runs. Warm volume hits still fetch the Playwright package from the registry, so warm runs stay network-dependent and the cold/warm comparison is skewed.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 22e8ffe. Configure here.


- name: Report benchmark browser cache
if: env.CI_BENCHMARK_CACHE_PREFIX != '' && steps.playwright-version.outputs.version != ''
run:
echo "BENCHMARK_CACHE provider=${{ env.CI_BENCHMARK_PROVIDER }} kind=playwright hit=${{
env.CI_BENCHMARK_PROVIDER == 'namespace' && steps.playwright-volume.outputs.cache-hit ||
steps.playwright-cache.outputs.cache-hit }}"
shell: bash

# We always install all browsers, if uncached
# `npx` runs outside the repo, so it can't pick up a `playwright` that a parallel `pnpm install` is still linking.
Expand Down Expand Up @@ -66,6 +83,7 @@ runs:
libopus0
libwayland-server0
)
packages+=(libgtk-4-1 libgraphene-1.0-0 libsecret-1-0 libx264-164)
# Resolve now and install after restoring the cache; share the package list across both steps.
printf '%s\n' "${packages[@]}" > "$RUNNER_TEMP/webkit-apt-packages"
# runner.temp is private, so keep installers where apt's sandbox user can access them.
Expand All @@ -83,21 +101,36 @@ runs:

# Separate Ubuntu versions and architectures, while allowing older package sets as fallbacks.
. /etc/os-release
prefix="webkit-apt-$ID-$VERSION_ID-${{ runner.arch }}-v1-"
prefix="${CI_BENCHMARK_CACHE_PREFIX:-}webkit-apt-$ID-$VERSION_ID-${{ runner.arch }}-v1-"
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
echo "key=$prefix$hash" >> "$GITHUB_OUTPUT"
shell: bash

- name: Mount WebKit package archives
id: webkit-volume
if: steps.webkit-dependencies.outputs.key != '' && env.CI_BENCHMARK_PROVIDER == 'namespace'
uses: namespacelabs/nscloud-cache-action@1124a6f3ce44e5cf84cc22111530961f4d2a15f9 # v1.7.0
with:
path: /var/tmp/webkit-apt-cache

- name: Restore cached WebKit system packages
id: webkit-apt-cache
if: steps.webkit-dependencies.outputs.key != ''
if: steps.webkit-dependencies.outputs.key != '' && env.CI_BENCHMARK_PROVIDER != 'namespace'
uses: actions/cache/restore@v6.1.0
with:
path: /var/tmp/webkit-apt-cache/*.deb
key: ${{ steps.webkit-dependencies.outputs.key }}
# If this exact package set isn't cached, reuse an older set; apt downloads only what's missing.
restore-keys: ${{ steps.webkit-dependencies.outputs.prefix }}

- name: Report benchmark WebKit cache
if: env.CI_BENCHMARK_CACHE_PREFIX != '' && steps.webkit-dependencies.outputs.key != ''
run:
echo "BENCHMARK_CACHE provider=${{ env.CI_BENCHMARK_PROVIDER }} kind=webkit-apt hit=${{
env.CI_BENCHMARK_PROVIDER == 'namespace' && steps.webkit-volume.outputs.cache-hit ||
steps.webkit-apt-cache.outputs.cache-hit }}"
shell: bash

- name: Install headless WebKit system dependencies
if: steps.webkit-dependencies.outputs.key != ''
run: |
Expand All @@ -111,8 +144,9 @@ runs:

- name: Remove obsolete cached WebKit packages
if:
steps.webkit-dependencies.outputs.key != '' && steps.webkit-apt-cache.outputs.cache-hit != 'true' &&
github.event_name == 'push' && github.ref == 'refs/heads/develop'
steps.webkit-dependencies.outputs.key != '' && steps.webkit-apt-cache.outputs.cache-hit != 'true' && (github.ref
== 'refs/heads/develop' || (env.CI_BENCHMARK_CACHE_PREFIX != '' && (github.head_ref == 'feat/namespace-ci-smoke'
|| github.ref == 'refs/heads/feat/namespace-ci-smoke')))
# Fallback restores can carry obsolete installers into newer cache entries.
run: sudo apt-get -o Dir::Cache::archives=/var/tmp/webkit-apt-cache autoclean
shell: bash
Expand All @@ -121,21 +155,26 @@ runs:
# which may have downloaded packages absent from the restored cache.
- name: Store cached WebKit system packages
if:
steps.webkit-dependencies.outputs.key != '' && steps.webkit-apt-cache.outputs.cache-hit != 'true' &&
github.event_name == 'push' && github.ref == 'refs/heads/develop'
env.CI_BENCHMARK_PROVIDER != 'namespace' && steps.webkit-dependencies.outputs.key != '' &&
steps.webkit-apt-cache.outputs.cache-hit != 'true' && (github.ref == 'refs/heads/develop' ||
(env.CI_BENCHMARK_CACHE_PREFIX != '' && (github.head_ref == 'feat/namespace-ci-smoke' || github.ref ==
'refs/heads/feat/namespace-ci-smoke')))
uses: actions/cache/save@v6.1.0
with:
path: /var/tmp/webkit-apt-cache/*.deb
key: ${{ steps.webkit-dependencies.outputs.key }}

# Only store cache on develop branch
# The benchmark branch also saves isolated entries so warm runs can be verified.
- name: Store cached playwright binaries
uses: actions/cache/save@v6.1.0
if:
steps.playwright-version.outputs.version != '' && github.event_name == 'push' && github.ref ==
'refs/heads/develop'
steps.playwright-version.outputs.version != '' && env.CI_BENCHMARK_PROVIDER != 'namespace' && (github.ref ==
'refs/heads/develop' || (env.CI_BENCHMARK_CACHE_PREFIX != '' && (github.head_ref == 'feat/namespace-ci-smoke' ||
github.ref == 'refs/heads/feat/namespace-ci-smoke')))
with:
path: |
~/.cache/ms-playwright
# Bump the iteration when bumping runner images to use a new cache
key: playwright-${{ runner.os }}-iteration-1-${{ steps.playwright-version.outputs.version }}
key:
${{ env.CI_BENCHMARK_CACHE_PREFIX }}playwright-${{ runner.os }}-${{ runner.arch }}-iteration-1-${{
steps.playwright-version.outputs.version }}
43 changes: 43 additions & 0 deletions .github/actions/mount-pnpm-store/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'Mount pnpm store'
description:
'Mounts the pnpm store, the pnpm and npm caches and the given paths from the Namespace cache volume. Use it before
`install-pnpm`, so `install-pnpm` takes pnpm from the cache volume.'

inputs:
path:
description: 'Paths to mount from the cache volume in addition to the pnpm store and caches, one per line.'
required: false
default: ''

runs:
using: 'composite'
steps:
# Replaces the `pnpm` mode of nscloud-cache-action until it works without pnpm on PATH. The mode runs `pnpm store
# path`, so it only works after `install-pnpm`, when `pnpm self-update` has already downloaded pnpm.
# The cache directory holds `lockfile-verified.jsonl`. With it, `pnpm install` skips the supply-chain check of a
# lockfile that was already verified, which otherwise fetches the metadata of every package from the registry.
- name: Set pnpm store and cache directories
run: |
echo "PNPM_CONFIG_STORE_DIR=$HOME/.cache/pnpm-store" >> "$GITHUB_ENV"
echo "PNPM_CONFIG_CACHE_DIR=$HOME/.cache/pnpm" >> "$GITHUB_ENV"
shell: bash

# The `npm` mode keeps the npm cache of the `npm ci` in `pnpm/action-setup`, which installs the bootstrap pnpm
- name: Mount cache paths
id: volume
uses: namespacelabs/nscloud-cache-action@1124a6f3ce44e5cf84cc22111530961f4d2a15f9 # v1.7.0
with:
cache: npm
path: |
~/.cache/pnpm-store
~/.cache/pnpm
${{ inputs.path }}

- name: Report benchmark package cache
if: env.CI_BENCHMARK_CACHE_PREFIX != ''
run: |
echo "BENCHMARK_CACHE provider=namespace kind=package-store hit=${{ steps.volume.outputs.cache-hit }}"
if test -f "$GITHUB_WORKSPACE/node_modules/.modules.yaml"; then
echo 'BENCHMARK_CACHE provider=namespace kind=workspace-node-modules present=true'
fi
shell: bash
4 changes: 4 additions & 0 deletions .github/actions/prepare-e2e-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ runs:
uses: denoland/setup-deno@v2.0.5
with:
deno-version: ${{ inputs.deno-version || 'v2.8.3' }}
- name: Mount E2E package stores
if: env.CI_BENCHMARK_PROVIDER == 'namespace'
uses: ./.github/actions/mount-pnpm-store

- name: Install pnpm
uses: ./.github/actions/install-pnpm

Expand Down
16 changes: 14 additions & 2 deletions .github/actions/restore-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,33 @@ runs:
using: 'composite'
steps:
- name: Install pnpm
if: env.CI_BENCHMARK_PROVIDER != 'namespace'
uses: ./.github/actions/install-pnpm

- name: Check dependency cache
id: dep-cache
if: env.CI_BENCHMARK_PROVIDER != 'namespace'
uses: actions/cache/restore@v6.1.0
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ inputs.dependency_cache_key }}-${{ runner.arch }}
key: ${{ env.CI_BENCHMARK_CACHE_PREFIX }}${{ inputs.dependency_cache_key }}-${{ runner.arch }}

- name: Restore build artifacts
uses: actions/download-artifact@v7
with:
name: build-output

- name: Install dependencies
if: steps.dep-cache.outputs.cache-hit != 'true'
if: env.CI_BENCHMARK_PROVIDER != 'namespace' && steps.dep-cache.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
shell: bash

- name: Install dependencies from Namespace volume
if: env.CI_BENCHMARK_PROVIDER == 'namespace'
uses: ./.github/actions/install-namespace-dependencies

- name: Report benchmark dependency cache
if: env.CI_BENCHMARK_CACHE_PREFIX != '' && env.CI_BENCHMARK_PROVIDER != 'namespace'
run:
echo "BENCHMARK_CACHE provider=github kind=workspace-node-modules hit=${{ steps.dep-cache.outputs.cache-hit }}"
shell: bash
14 changes: 12 additions & 2 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ runs:
with:
node-version: ${{ steps.node.outputs.version }}

# Only `develop` saves, so PRs share one entry per architecture instead of each creating their own.
# The benchmark branch also saves isolated entries so warm runs can be verified.
- name: Save Node.js install
if: steps.node-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/develop'
if:
steps.node-cache.outputs.cache-hit != 'true' && (github.ref == 'refs/heads/develop' ||
(env.CI_BENCHMARK_CACHE_PREFIX != '' && (github.head_ref == 'feat/namespace-ci-smoke' || github.ref ==
'refs/heads/feat/namespace-ci-smoke')))
uses: actions/cache/save@v6.1.0
with:
path: ${{ steps.node.outputs.cache-path }}
key: ${{ steps.node.outputs.cache-key }}

- name: Report benchmark Node cache
if: env.CI_BENCHMARK_CACHE_PREFIX != ''
run:
echo "BENCHMARK_CACHE provider=${{ env.CI_BENCHMARK_PROVIDER }} kind=node-toolcache hit=${{
steps.node-cache.outputs.cache-hit }}"
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/setup-node/resolve-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set -eu

version=$(jq -e -r '.devEngines.runtime.version' package.json)
cache_path="$RUNNER_TOOL_CACHE/node/$version"
cache_key="node-toolcache-$RUNNER_OS-$RUNNER_ARCH-$version"
cache_key="${CI_BENCHMARK_CACHE_PREFIX:-}node-toolcache-$RUNNER_OS-$RUNNER_ARCH-$version"

printf 'version=%s\ncache-path=%s\ncache-key=%s\n' "$version" "$cache_path" "$cache_key" >> "$GITHUB_OUTPUT"
Loading
Loading