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
21 changes: 15 additions & 6 deletions .github/actions/build-local-sdk/action.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
name: 'Build SDK packages locally'
description: 'Restore workspace dependencies and build the SDK outputs needed by this job.'
name: Build SDK packages locally
description: Restore workspace dependencies and build the SDK outputs needed by this job.
inputs:
setup:
description: 'Set up the build Node version and restore workspace dependencies.'
description: Set up the build Node version and restore workspace dependencies.
default: 'true'
package-path:
description: 'Comma-separated package paths whose SDK dependencies to build; use . only for repo-wide checks.'
description: Comma-separated package paths whose SDK dependencies to build; use . only for repo-wide checks.
default: ''
targets:
description: 'Nx targets to build for the selected packages and their dependencies.'
default: 'build:transpile build:types'
description: Nx targets to build for the selected packages and their dependencies.
default: build:transpile build:types
runs:
using: composite
steps:
- name: Set up repository-pinned Node.js for building
if: inputs.setup == 'true'
uses: ./.github/actions/setup-node
- name: Select dependency cache
id: dependencies
if: inputs.setup == 'true'
env:
PACKAGE_PATH: ${{ inputs.package-path }}
run: node .github/actions/install-dependencies/groups.mjs select "$PACKAGE_PATH" >> "$GITHUB_OUTPUT"
shell: bash
- name: Restore workspace dependencies
if: inputs.setup == 'true'
uses: ./.github/actions/install-dependencies
with:
group: ${{ steps.dependencies.outputs.group }}
- name: Select SDK packages
id: projects
env:
Expand Down
35 changes: 25 additions & 10 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
name: 'Install pnpm dependencies'
description: 'Installs pnpm dependencies and caches them.'

name: Install pnpm dependencies
description: Installs pnpm dependencies and caches them.
outputs:
cache_key:
description: 'The dependency cache key'
description: The dependency cache key
value: ${{ steps.compute_lockfile_hash.outputs.hash }}

runs:
using: 'composite'
using: composite
steps:
- name: Install pnpm
uses: ./.github/actions/install-pnpm

- name: Compute dependency cache key
id: compute_lockfile_hash
run: node ./scripts/dependency-hash-key.js >> "$GITHUB_OUTPUT"
shell: bash

- name: Compute selected dependency cache key
id: group
if: inputs.group != ''
env:
DEPENDENCY_GROUP: ${{ inputs.group }}
DEPENDENCY_HASH: ${{ steps.compute_lockfile_hash.outputs.hash }}
run: node "$GITHUB_ACTION_PATH/groups.mjs" key "$DEPENDENCY_GROUP" "$DEPENDENCY_HASH" >> "$GITHUB_OUTPUT"
shell: bash
- name: Restore selected workspace dependencies
id: selected
if: inputs.group != ''
uses: actions/cache/restore@v6.1.0
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.group.outputs.key }}
- name: Check dependency cache
uses: actions/cache@v6.1.0
id: cache_dependencies
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}-${{ runner.arch }}

if: inputs.group == '' || steps.selected.outputs.cache-hit != 'true'
- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit != 'true'
if: steps.selected.outputs.cache-hit != 'true' && steps.cache_dependencies.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
shell: bash
inputs:
group:
description: Optional dependency group; fall back to the full workspace cache on a miss.
default: ''
54 changes: 54 additions & 0 deletions .github/actions/install-dependencies/groups.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { createHash } from 'node:crypto';
import fs from 'node:fs';

const workspaces = JSON.parse(fs.readFileSync('package.json', 'utf8')).workspaces;
const sdk = workspaces.filter(directory => directory.startsWith('packages/'));
const serverTests = [
'dev-packages/node-integration-tests',
'dev-packages/bun-integration-tests',
'dev-packages/deno-integration-tests',
'dev-packages/bundler-plugin-integration-tests',
];
const browserTests = ['dev-packages/browser-integration-tests', 'dev-packages/browser-min-version-tests'];
const groups = {
sdk: [...sdk, 'dev-packages/test-utils', 'dev-packages/bundler-tests'],
server: [...sdk, 'dev-packages/test-utils', ...serverTests],
browser: [...browserTests, 'packages/browser'],
cloudflare: ['dev-packages/cloudflare-integration-tests'],
};

const [command, value, dependencyHash] = process.argv.slice(2);
if (command === 'select') {
const paths = value.split(',');
let group = '';
if (paths.every(directory => browserTests.includes(directory) || directory === 'packages/browser')) {
group = 'browser';
} else if (paths.every(directory => serverTests.includes(directory))) {
group = 'server';
} else if (paths.every(directory => groups.cloudflare.includes(directory))) {
group = 'cloudflare';
} else if (
paths.every(
directory =>
directory.startsWith('packages/') || directory.startsWith('dev-packages/e2e-tests/test-applications/'),
)
) {
group = 'sdk';
}
process.stdout.write(`group=${group}\n`);
} else {
const paths = groups[value];
if (!paths) throw new Error(`Unknown dependency group: ${value}`);
if (command === 'roots') {
process.stdout.write(`paths=${paths.join(',')}\n`);
} else if (command === 'key') {
if (!dependencyHash) throw new Error('Missing dependency hash');
// Changing a group's membership must invalidate its installation too.
const membership = createHash('sha256').update(JSON.stringify(paths)).digest('hex').slice(0, 12);
process.stdout.write(
`key=dependencies-selected-v1-${value}-${membership}-${dependencyHash}-${process.env.RUNNER_OS}-${process.env.RUNNER_ARCH}\n`,
);
} else {
throw new Error(`Unknown command: ${command}`);
}
}
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ jobs:
uses: ./.github/actions/setup-node
- name: Restore workspace dependencies
uses: ./.github/actions/install-dependencies
with:
group: sdk

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Selected caches trigger a full reinstall

High Severity

Jobs that restore a selected dependency cache never set pnpm_config_verify_deps_before_run. A filtered install does not satisfy the full lockfile, so the next pnpm exec or pnpm run installs the whole workspace. Seed and E2E already disable that check; unit-test and build-local-sdk consumers do not, so the smaller cache is discarded and 10-minute jobs can time out.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6b21452. Configure here.

- name: Build selected unit-test dependencies
env:
UNIT_TEST_ENV: browser
Expand Down Expand Up @@ -509,6 +511,8 @@ jobs:
uses: ./.github/actions/setup-node
- name: Restore workspace dependencies
uses: ./.github/actions/install-dependencies
with:
group: server
- name: Build selected unit-test dependencies
env:
UNIT_TEST_ENV: node
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/seed-workspace-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Seed workspace dependency caches
on:
push:
branches: [develop]
workflow_dispatch:
permissions:
contents: read
env:
CACHED_DEPENDENCY_PATHS: |
${{ github.workspace }}/node_modules
${{ github.workspace }}/packages/*/node_modules
${{ github.workspace }}/dev-packages/*/node_modules
~/.cache/mongodb-binaries/
SKIP_PLAYWRIGHT_BROWSER_INSTALL: '1'
pnpm_config_verify_deps_before_run: 'false'
jobs:
seed:
name: Seed ${{ matrix.group }} dependencies (${{ matrix.runner }})
runs-on: ${{ matrix.runner }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- { group: sdk, runner: ubuntu-24.04 }
- { group: sdk, runner: ubuntu-24.04-arm }
- { group: server, runner: ubuntu-24.04 }
- { group: server, runner: ubuntu-24.04-arm }
- { group: browser, runner: ubuntu-24.04 }
- { group: cloudflare, runner: ubuntu-24.04-arm }
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/install-pnpm
- name: Compute cache key
id: key
env:
GROUP: ${{ matrix.group }}
run: |
hash=$(node scripts/dependency-hash-key.js)
node .github/actions/install-dependencies/groups.mjs key "$GROUP" "${hash#hash=}" >> "$GITHUB_OUTPUT"
- name: Restore selected dependencies
id: cache
uses: actions/cache/restore@v6.1.0
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.key.outputs.key }}
- name: Select workspace roots
if: steps.cache.outputs.cache-hit != 'true'
id: roots
env:
GROUP: ${{ matrix.group }}
run: node .github/actions/install-dependencies/groups.mjs roots "$GROUP" >> "$GITHUB_OUTPUT"
- name: Expand workspace dependencies
if: steps.cache.outputs.cache-hit != 'true'
id: projects
env:
INPUT_PACKAGE_PATH: ${{ steps.roots.outputs.paths }}
run: node .github/actions/build-local-sdk/select-projects.mjs >> "$GITHUB_OUTPUT"
- name: Install selected dependencies
if: steps.cache.outputs.cache-hit != 'true'
env:
PROJECTS: ${{ steps.projects.outputs.projects }}
run: |
filters=(--filter sentry-javascript)
IFS=',' read -ra projects <<< "$PROJECTS"
for project in "${projects[@]}"; do
filters+=(--filter "$project")
done
pnpm "${filters[@]}" install --frozen-lockfile
git diff --exit-code -- pnpm-lock.yaml pnpm-workspace.yaml package.json
- name: Measure installation
run: |
du -sh node_modules
find node_modules/.pnpm -mindepth 1 -maxdepth 1 -type d | wc -l
- name: Save selected dependencies
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6.1.0
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.key.outputs.key }}
Loading