Skip to content

Commit 98a1b3a

Browse files
committed
handle non-PRs
1 parent 90e4fe5 commit 98a1b3a

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,11 @@ jobs:
861861

862862
- name: Determine which E2E test applications should be run
863863
id: matrix
864-
if: github.event_name == 'pull_request'
865864
run: yarn --silent test:build-matrix --base=${{ github.event.pull_request.base.sha }} >> $GITHUB_OUTPUT
866865
working-directory: dev-packages/e2e-tests
867866

868867
- name: Determine which optional E2E test applications should be run
869868
id: matrix-optional
870-
if: github.event_name == 'pull_request'
871869
run: yarn --silent test:build-matrix-optional --base=${{ github.event.pull_request.base.sha }} >> $GITHUB_OUTPUT
872870
working-directory: dev-packages/e2e-tests
873871

@@ -966,7 +964,7 @@ jobs:
966964

967965
- name: Upload Playwright Traces
968966
uses: actions/upload-artifact@v4
969-
if: failure() && steps.should-skip.outputs.SKIP != 'true'
967+
if: failure()
970968
with:
971969
name: playwright-traces-job_e2e_playwright_tests-${{ matrix.test-application}}
972970
path: dev-packages/e2e-tests/test-applications/${{ matrix.test-application}}/test-results
@@ -1043,12 +1041,6 @@ jobs:
10431041
with:
10441042
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
10451043

1046-
- name: Determine if test app should be run
1047-
id: should-skip
1048-
if: github.event_name == 'pull_request'
1049-
run: yarn --silent test:should-skip ${{ matrix.test-application }} --base=${{ github.event.pull_request.base.sha }} >> $GITHUB_OUTPUT
1050-
working-directory: dev-packages/e2e-tests
1051-
10521044
- name: Restore tarball cache
10531045
uses: actions/cache/restore@v4
10541046
id: restore-tarball-cache
@@ -1057,7 +1049,7 @@ jobs:
10571049
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
10581050

10591051
- name: Build tarballs if not cached
1060-
if: steps.restore-tarball-cache.outputs.cache-hit != 'true' && steps.should-skip.outputs.SKIP != 'true'
1052+
if: steps.restore-tarball-cache.outputs.cache-hit != 'true'
10611053
run: yarn build:tarball
10621054

10631055
- name: Install Playwright

dev-packages/e2e-tests/lib/getTestMatrix.ts

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ interface MatrixInclude {
1010
label?: string;
1111
}
1212

13+
/**
14+
* This methods generates a matrix for the GitHub Actions workflow to run the E2E tests.
15+
* It checks which test applications are affected by the current changes in the PR and then generates a matrix
16+
* including all test apps that have at least one dependency that was changed in the PR.
17+
* If no `--base=xxx` is provided, it will output all test applications.
18+
*
19+
* If `--optional=true` is set, it will generate a matrix of optional test applications only.
20+
* Otherwise, these will be skipped.
21+
*/
1322
function run(): void {
1423
const args: Record<string, string> = {};
1524
process.argv
@@ -22,30 +31,15 @@ function run(): void {
2231
args[argName] = argValue;
2332
});
2433

25-
// We default to `develop` as base, if none is specified
26-
// head has a correct default value anyhow
27-
const { base = 'develop', head, optional = 'false' } = args;
34+
const { base, head, optional = 'false' } = args;
2835

2936
const testApplications = globSync('*', { cwd: `${__dirname}/../test-applications/` });
3037

31-
const additionalArgs = [];
32-
if (base) {
33-
additionalArgs.push(`--base=${base}`);
34-
}
35-
if (head) {
36-
additionalArgs.push(`--head=${head}`);
37-
}
38-
39-
const affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`)
40-
.toString()
41-
.split('\n')
42-
.map(line => line.trim())
43-
.filter(Boolean);
44-
45-
const includedTestApplications = testApplications.filter(testApp => {
46-
const sentryDependencies = getSentryDependencies(testApp);
47-
return sentryDependencies.some(dep => affectedProjects.includes(dep));
48-
});
38+
// If `--base=xxx` is defined, we only want to get test applications changed since that base
39+
// Else, we take all test applications (e.g. on push)
40+
const includedTestApplications = base
41+
? getAffectedTestApplications(testApplications, { base, head })
42+
: testApplications;
4943

5044
const optionalMode = optional === 'true';
5145
const includes: MatrixInclude[] = [];
@@ -121,3 +115,25 @@ function getPackageJson(appName: string): {
121115
}
122116

123117
run();
118+
119+
function getAffectedTestApplications(
120+
testApplications: string[],
121+
{ base = 'develop', head }: { base?: string; head?: string },
122+
): string[] {
123+
const additionalArgs = [`--base=${base}`];
124+
125+
if (head) {
126+
additionalArgs.push(`--head=${head}`);
127+
}
128+
129+
const affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`)
130+
.toString()
131+
.split('\n')
132+
.map(line => line.trim())
133+
.filter(Boolean);
134+
135+
return testApplications.filter(testApp => {
136+
const sentryDependencies = getSentryDependencies(testApp);
137+
return sentryDependencies.some(dep => affectedProjects.includes(dep));
138+
});
139+
}

0 commit comments

Comments
 (0)