Skip to content

Commit 887f013

Browse files
committed
ci: Only run E2E test apps that are affected on PRs
1 parent a55e2b0 commit 887f013

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
@@ -962,11 +962,6 @@ jobs:
962962
- test-application: 'nextjs-app-dir'
963963
build-command: 'test:build-13'
964964
label: 'nextjs-app-dir (next@13)'
965-
exclude:
966-
- is_dependabot: true
967-
test-application: 'cloudflare-astro'
968-
- is_dependabot: true
969-
test-application: 'cloudflare-workers'
970965

971966
steps:
972967
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
@@ -988,18 +983,26 @@ jobs:
988983
with:
989984
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
990985

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

9981000
- name: Build tarballs if not cached
999-
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1001+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true' && steps.should-skip.outputs.SKIP != 'true'
10001002
run: yarn build:tarball
10011003

10021004
- name: Install Playwright
1005+
if: steps.should-skip.outputs.SKIP != 'true'
10031006
uses: ./.github/actions/install-playwright
10041007
with:
10051008
browsers: chromium
@@ -1010,42 +1013,46 @@ jobs:
10101013
echo "echo node=$(jq -r '.volta.node' dev-packages/e2e-tests/package.json)" >> $GITHUB_OUTPUT
10111014
10121015
- name: Validate Verdaccio
1016+
if: steps.should-skip.outputs.SKIP != 'true'
10131017
run: yarn test:validate
10141018
working-directory: dev-packages/e2e-tests
10151019

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

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

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

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

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

10561063
- name: Upload test results to Codecov
1057-
if: cancelled() == false
1064+
if: cancelled() == false && steps.should-skip.outputs.SKIP != 'true'
10581065
continue-on-error: true
10591066
uses: codecov/test-results-action@v1
10601067
with:
@@ -1154,18 +1161,26 @@ jobs:
11541161
with:
11551162
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
11561163

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

11641178
- name: Build tarballs if not cached
1165-
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1179+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true' && steps.should-skip.outputs.SKIP != 'true'
11661180
run: yarn build:tarball
11671181

11681182
- name: Install Playwright
1183+
if: steps.should-skip.outputs.SKIP != 'true'
11691184
uses: ./.github/actions/install-playwright
11701185
with:
11711186
browsers: chromium
@@ -1176,33 +1191,37 @@ jobs:
11761191
echo "echo node=$(jq -r '.volta.node' dev-packages/e2e-tests/package.json)" >> $GITHUB_OUTPUT
11771192
11781193
- name: Validate Verdaccio
1194+
if: steps.should-skip.outputs.SKIP != 'true'
11791195
run: yarn test:validate
11801196
working-directory: dev-packages/e2e-tests
11811197

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

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

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

11981217
- name: Pre-process E2E Test Dumps
1199-
if: always()
1218+
if: always() && steps.should-skip.outputs.SKIP != 'true'
12001219
run: |
12011220
node ./scripts/normalize-e2e-test-dump-transaction-events.js
12021221
12031222
- name: Upload E2E Test Event Dumps
12041223
uses: actions/upload-artifact@v4
1205-
if: always()
1224+
if: always() && steps.should-skip.outputs.SKIP != 'true'
12061225
with:
12071226
name: E2E Test Dump (${{ matrix.label || matrix.test-application }})
12081227
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/event-dumps
@@ -1212,7 +1231,7 @@ jobs:
12121231

12131232
- name: Deploy Astro to Cloudflare
12141233
uses: cloudflare/pages-action@v1
1215-
if: matrix.test-application == 'cloudflare-astro'
1234+
if: matrix.test-application == 'cloudflare-astro' && steps.should-skip.outputs.SKIP != 'true'
12161235
with:
12171236
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
12181237
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)