Skip to content

Commit cfad7f9

Browse files
committed
ci: Only run affected unit tests on PRs
1 parent e2668f8 commit cfad7f9

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,15 @@ jobs:
446446
uses: ./.github/actions/restore-cache
447447
env:
448448
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
449-
- name: Run tests
450-
run: yarn test-ci-browser
449+
450+
- name: Run affected tests
451+
run: yarn test:pr:browser
452+
if: github.event_name == 'pull_request'
453+
454+
- name: Run all tests
455+
run: yarn test:ci:browser
456+
if: github.event_name != 'pull_request'
457+
451458
- name: Compute test coverage
452459
uses: codecov/codecov-action@v4
453460
with:
@@ -478,7 +485,7 @@ jobs:
478485
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
479486
- name: Run tests
480487
run: |
481-
yarn test-ci-bun
488+
yarn test:ci:bun
482489
483490
job_deno_unit_tests:
484491
name: Deno Unit Tests
@@ -536,7 +543,7 @@ jobs:
536543
- name: Run tests
537544
env:
538545
NODE_VERSION: ${{ matrix.node }}
539-
run: yarn test-ci-node
546+
run: yarn test:ci:node
540547
- name: Compute test coverage
541548
uses: codecov/codecov-action@v4
542549
with:

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
"postpublish": "lerna run --stream --concurrency 1 postpublish",
3434
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test",
3535
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test:unit",
36-
"test-ci-browser": "lerna run test --ignore \"@sentry/{bun,deno,node,profiling-node,serverless,google-cloud,nextjs,remix,gatsby,sveltekit,vercel-edge}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
37-
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
38-
"test-ci-bun": "lerna run test --scope @sentry/bun",
3936
"test:update-snapshots": "lerna run test:update-snapshots",
37+
"test:pr": "nx affected -t test --exclude \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
38+
"test:pr:browser": "yarn test:pr --exclude \"@sentry/{bun,deno,node,profiling-node,aws-serverless,google-cloud-serverless,nextjs,nextjs,nuxt,remix,gatsby,sveltekit,vercel-edge}\"",
39+
"test:pr:node": "ts-node ./scripts/node-unit-tests.ts --affected",
40+
"test:ci:browser": "lerna run test --ignore \"@sentry/{bun,deno,node,profiling-node,aws-serverless,google-cloud-serverless,nextjs,nestjs,nuxt,remix,gatsby,sveltekit,vercel-edge}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
41+
"test:ci:node": "ts-node ./scripts/node-unit-tests.ts",
42+
"test:ci:bun": "lerna run test --scope @sentry/bun",
4043
"yalc:publish": "lerna run yalc:publish"
4144
},
4245
"volta": {

scripts/node-unit-tests.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface VersionConfig {
88

99
const CURRENT_NODE_VERSION = process.version.replace('v', '').split('.')[0] as NodeVersion;
1010

11+
const RUN_AFFECTED = process.argv.includes('--affected');
12+
1113
const DEFAULT_SKIP_TESTS_PACKAGES = [
1214
'@sentry-internal/eslint-plugin-sdk',
1315
'@sentry/ember',
@@ -70,6 +72,14 @@ function runWithIgnores(skipPackages: string[] = []): void {
7072
run(`yarn test ${ignoreFlags}`);
7173
}
7274

75+
/**
76+
* Run affected tests, ignoring the given packages
77+
*/
78+
function runAffectedWithIgnores(skipPackages: string[] = []): void {
79+
const ignoreFlags = skipPackages.map(dep => `--exclude="${dep}"`).join(' ');
80+
run(`yarn test:pr ${ignoreFlags}`);
81+
}
82+
7383
/**
7484
* Run the tests, accounting for compatibility problems in older versions of Node.
7585
*/
@@ -83,7 +93,11 @@ function runTests(): void {
8393
versionConfig.ignoredPackages.forEach(dep => ignores.add(dep));
8494
}
8595

86-
runWithIgnores(Array.from(ignores));
96+
if (RUN_AFFECTED) {
97+
runAffectedWithIgnores(Array.from(ignores));
98+
} else {
99+
runWithIgnores(Array.from(ignores));
100+
}
87101
}
88102

89103
runTests();

0 commit comments

Comments
 (0)