Skip to content

Commit db5cb06

Browse files
committed
ci: Only run E2E test apps that are affected on PRs
1 parent f4c5900 commit db5cb06

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

972967
steps:
973968
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
@@ -989,18 +984,26 @@ jobs:
989984
with:
990985
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
991986

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

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

10031005
- name: Install Playwright
1006+
if: steps.should-skip.outputs.SKIP != 'true'
10041007
uses: ./.github/actions/install-playwright
10051008
with:
10061009
browsers: chromium
@@ -1011,42 +1014,46 @@ jobs:
10111014
echo "echo node=$(jq -r '.volta.node' dev-packages/e2e-tests/package.json)" >> $GITHUB_OUTPUT
10121015
10131016
- name: Validate Verdaccio
1017+
if: steps.should-skip.outputs.SKIP != 'true'
10141018
run: yarn test:validate
10151019
working-directory: dev-packages/e2e-tests
10161020

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

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

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

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

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

10571064
- name: Upload test results to Codecov
1058-
if: cancelled() == false
1065+
if: cancelled() == false && steps.should-skip.outputs.SKIP != 'true'
10591066
continue-on-error: true
10601067
uses: codecov/test-results-action@v1
10611068
with:
@@ -1155,18 +1162,26 @@ jobs:
11551162
with:
11561163
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
11571164

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

11651179
- name: Build tarballs if not cached
1166-
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
1180+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true' && steps.should-skip.outputs.SKIP != 'true'
11671181
run: yarn build:tarball
11681182

11691183
- name: Install Playwright
1184+
if: steps.should-skip.outputs.SKIP != 'true'
11701185
uses: ./.github/actions/install-playwright
11711186
with:
11721187
browsers: chromium
@@ -1177,33 +1192,37 @@ jobs:
11771192
echo "echo node=$(jq -r '.volta.node' dev-packages/e2e-tests/package.json)" >> $GITHUB_OUTPUT
11781193
11791194
- name: Validate Verdaccio
1195+
if: steps.should-skip.outputs.SKIP != 'true'
11801196
run: yarn test:validate
11811197
working-directory: dev-packages/e2e-tests
11821198

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

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

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

11991218
- name: Pre-process E2E Test Dumps
1200-
if: always()
1219+
if: always() && steps.should-skip.outputs.SKIP != 'true'
12011220
run: |
12021221
node ./scripts/normalize-e2e-test-dump-transaction-events.js
12031222
12041223
- name: Upload E2E Test Event Dumps
12051224
uses: actions/upload-artifact@v4
1206-
if: always()
1225+
if: always() && steps.should-skip.outputs.SKIP != 'true'
12071226
with:
12081227
name: E2E Test Dump (${{ matrix.label || matrix.test-application }})
12091228
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/event-dumps
@@ -1213,7 +1232,7 @@ jobs:
12131232

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