Skip to content

Commit 21acb7e

Browse files
committed
ci: Only run E2E test apps that are affected on PRs
1 parent e0282b6 commit 21acb7e

File tree

3 files changed

+106
-14
lines changed

3 files changed

+106
-14
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -961,11 +961,6 @@ jobs:
961961
- test-application: 'nextjs-app-dir'
962962
build-command: 'test:build-13'
963963
label: 'nextjs-app-dir (next@13)'
964-
exclude:
965-
- is_dependabot: true
966-
test-application: 'cloudflare-astro'
967-
- is_dependabot: true
968-
test-application: 'cloudflare-workers'
969964

970965
steps:
971966
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
@@ -987,18 +982,26 @@ jobs:
987982
with:
988983
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
989984

985+
- name: Determine if test app should be run
986+
id: should-skip
987+
if: github.event.pull_request.base.sha
988+
run: yarn test:should-skip ${{ matrix.test-application }} --base=${{ github.event.pull_request.base.sha }} >> $GITHUB_OUTPUT
989+
working-directory: dev-packages/e2e-tests
990+
990991
- name: Restore tarball cache
991992
uses: actions/cache/restore@v4
992993
id: restore-tarball-cache
994+
if: steps.should-skip.outputs.SKIP != 'true'
993995
with:
994996
path: ${{ github.workspace }}/packages/*/*.tgz
995997
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
996998

997999
- name: Build tarballs if not cached
998-
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1000+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true' && steps.should-skip.outputs.SKIP != 'true'
9991001
run: yarn build:tarball
10001002

10011003
- name: Install Playwright
1004+
if: steps.should-skip.outputs.SKIP != 'true'
10021005
uses: ./.github/actions/install-playwright
10031006
with:
10041007
browsers: chromium
@@ -1009,42 +1012,46 @@ jobs:
10091012
echo "echo node=$(jq -r '.volta.node' dev-packages/e2e-tests/package.json)" >> $GITHUB_OUTPUT
10101013
10111014
- name: Validate Verdaccio
1015+
if: steps.should-skip.outputs.SKIP != 'true'
10121016
run: yarn test:validate
10131017
working-directory: dev-packages/e2e-tests
10141018

10151019
- name: Prepare Verdaccio
1020+
if: steps.should-skip.outputs.SKIP != 'true'
10161021
run: yarn test:prepare
10171022
working-directory: dev-packages/e2e-tests
10181023
env:
10191024
E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION: ${{ steps.versions.outputs.node }}
10201025

10211026
- name: Build E2E app
1027+
if: steps.should-skip.outputs.SKIP != 'true'
10221028
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
10231029
timeout-minutes: 7
10241030
run: pnpm ${{ matrix.build-command || 'test:build' }}
10251031

10261032
- name: Run E2E test
1033+
if: steps.should-skip.outputs.SKIP != 'true'
10271034
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
10281035
timeout-minutes: 10
10291036
run: pnpm test:assert
10301037

10311038
- name: Upload Playwright Traces
10321039
uses: actions/upload-artifact@v4
1033-
if: failure()
1040+
if: failure() && steps.should-skip.outputs.SKIP != 'true'
10341041
with:
10351042
name: playwright-traces-job_e2e_playwright_tests-${{ matrix.test-application}}
10361043
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application}}/test-results
10371044
overwrite: true
10381045
retention-days: 7
10391046

10401047
- name: Pre-process E2E Test Dumps
1041-
if: always()
1048+
if: always() && steps.should-skip.outputs.SKIP != 'true'
10421049
run: |
10431050
node ./scripts/normalize-e2e-test-dump-transaction-events.js
10441051
10451052
- name: Upload E2E Test Event Dumps
10461053
uses: actions/upload-artifact@v4
1047-
if: always()
1054+
if: always() && steps.should-skip.outputs.SKIP != 'true'
10481055
with:
10491056
name: E2E Test Dump (${{ matrix.label || matrix.test-application }})
10501057
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/event-dumps
@@ -1053,7 +1060,7 @@ jobs:
10531060
if-no-files-found: ignore
10541061

10551062
- name: Upload test results to Codecov
1056-
if: cancelled() == false
1063+
if: cancelled() == false && steps.should-skip.outputs.SKIP != 'true'
10571064
continue-on-error: true
10581065
uses: codecov/test-results-action@v1
10591066
with:
@@ -1153,18 +1160,26 @@ jobs:
11531160
with:
11541161
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
11551162

1163+
- name: Determine if test app should be run
1164+
id: should-skip
1165+
if: github.event.pull_request.base.sha
1166+
run: yarn test:should-skip ${{ matrix.test-application }} --base=${{ github.event.pull_request.base.sha }} >> $GITHUB_OUTPUT
1167+
working-directory: dev-packages/e2e-tests
1168+
11561169
- name: Restore tarball cache
1170+
if: steps.should-skip.outputs.SKIP != 'true'
11571171
uses: actions/cache/restore@v4
11581172
id: restore-tarball-cache
11591173
with:
11601174
path: ${{ github.workspace }}/packages/*/*.tgz
11611175
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
11621176

11631177
- name: Build tarballs if not cached
1164-
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1178+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true' && steps.should-skip.outputs.SKIP != 'true'
11651179
run: yarn build:tarball
11661180

11671181
- name: Install Playwright
1182+
if: steps.should-skip.outputs.SKIP != 'true'
11681183
uses: ./.github/actions/install-playwright
11691184
with:
11701185
browsers: chromium
@@ -1175,33 +1190,37 @@ jobs:
11751190
echo "echo node=$(jq -r '.volta.node' dev-packages/e2e-tests/package.json)" >> $GITHUB_OUTPUT
11761191
11771192
- name: Validate Verdaccio
1193+
if: steps.should-skip.outputs.SKIP != 'true'
11781194
run: yarn test:validate
11791195
working-directory: dev-packages/e2e-tests
11801196

11811197
- name: Prepare Verdaccio
1198+
if: steps.should-skip.outputs.SKIP != 'true'
11821199
run: yarn test:prepare
11831200
working-directory: dev-packages/e2e-tests
11841201
env:
11851202
E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION: ${{ steps.versions.outputs.node }}
11861203

11871204
- name: Build E2E app
1205+
if: steps.should-skip.outputs.SKIP != 'true'
11881206
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
11891207
timeout-minutes: 7
11901208
run: pnpm ${{ matrix.build-command || 'test:build' }}
11911209

11921210
- name: Run E2E test
1211+
if: steps.should-skip.outputs.SKIP != 'true'
11931212
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
11941213
timeout-minutes: 10
11951214
run: pnpm ${{ matrix.assert-command || 'test:assert' }}
11961215

11971216
- name: Pre-process E2E Test Dumps
1198-
if: always()
1217+
if: always() && steps.should-skip.outputs.SKIP != 'true'
11991218
run: |
12001219
node ./scripts/normalize-e2e-test-dump-transaction-events.js
12011220
12021221
- name: Upload E2E Test Event Dumps
12031222
uses: actions/upload-artifact@v4
1204-
if: always()
1223+
if: always() && steps.should-skip.outputs.SKIP != 'true'
12051224
with:
12061225
name: E2E Test Dump (${{ matrix.label || matrix.test-application }})
12071226
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/event-dumps
@@ -1211,7 +1230,7 @@ jobs:
12111230

12121231
- name: Deploy Astro to Cloudflare
12131232
uses: cloudflare/pages-action@v1
1214-
if: matrix.test-application == 'cloudflare-astro'
1233+
if: matrix.test-application == 'cloudflare-astro' && steps.should-skip.outputs.SKIP != 'true'
12151234
with:
12161235
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
12171236
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { execSync } from 'child_process';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
5+
/**
6+
* This logs SKIP=true or SKIP=false,
7+
* which can be used by GHA to determine if the given test application should be skipped or not.
8+
* This uses nx to check if any of the sentry dependencies of the test-application have been affected.
9+
*/
10+
function ciShouldSkipTestApplication(): void {
11+
// Allow to run a single app only via `yarn test:run <app-name>`
12+
const appName = process.argv[2];
13+
14+
const args: Record<string, string> = {};
15+
process.argv
16+
.slice(2)
17+
.filter(arg => arg.startsWith('--') && arg.includes('='))
18+
.forEach(arg => {
19+
const [part1, part2] = arg.split('=') as [string, string];
20+
const argName = part1.replace('--', '');
21+
const argValue = part2;
22+
args[argName] = argValue;
23+
});
24+
25+
// We default to `develop` as base, if none is specified
26+
// head has a correct default value anyhow
27+
const { base = 'develop', head } = args;
28+
29+
if (!appName) {
30+
throw new Error('Please provide the app name as the first argument');
31+
}
32+
33+
const fullPath = path.resolve(__dirname, '..', 'test-applications', appName, 'package.json');
34+
35+
if (!fs.existsSync(fullPath)) {
36+
throw new Error(`The app ${appName} does not exist`);
37+
}
38+
39+
const packageJson = JSON.parse(fs.readFileSync(fullPath, 'utf8')) as {
40+
dependencies?: { [key: string]: string };
41+
devDependencies?: { [key: string]: string };
42+
};
43+
44+
const dependencies = {
45+
...packageJson.devDependencies,
46+
...packageJson.dependencies,
47+
};
48+
49+
const sentryDependencies = Object.keys(dependencies).filter(key => key.startsWith('@sentry/'));
50+
51+
const additionalArgs = [];
52+
if (base) {
53+
additionalArgs.push(`--base=${base}`);
54+
}
55+
if (head) {
56+
additionalArgs.push(`--head=${head}`);
57+
}
58+
59+
const affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`)
60+
.toString()
61+
.split('\n')
62+
.map(line => line.trim());
63+
64+
// If one of the sentry dependencies is affected, this test should be run
65+
const affected = sentryDependencies.some(dep => affectedProjects.includes(dep));
66+
67+
// This is used by CI to determine if steps should be skipped or not
68+
// eslint-disable-next-line no-console
69+
console.log(`SKIP=${affected ? 'false' : 'true'}`);
70+
}
71+
72+
ciShouldSkipTestApplication();

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"test:prepare": "ts-node prepare.ts",
1515
"test:validate": "run-s test:validate-configuration test:validate-test-app-setups",
1616
"clean": "rimraf tmp node_modules pnpm-lock.yaml && yarn clean:test-applications",
17+
"test:should-skip": "ts-node ./lib/ciShouldSkipTestApplication.ts",
1718
"clean:test-applications": "rimraf --glob test-applications/**/{node_modules,dist,build,.next,.sveltekit,pnpm-lock.yaml} .last-run.json && pnpm store prune"
1819
},
1920
"devDependencies": {

0 commit comments

Comments
 (0)