Skip to content

Commit 660d533

Browse files
authored
ci(test-matrix): Add logs for getTestMatrix (#17673)
Adds some test for generating the test matrix to be able to easily debug it.
1 parent 6e8e561 commit 660d533

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@ function run(): void {
4848

4949
const { base, head = 'HEAD', optional } = values;
5050

51+
// For GitHub Action debugging
52+
// eslint-disable-next-line no-console
53+
console.error(`Parsed command line arguments: base=${base}, head=${head}, optional=${optional}`);
54+
5155
const testApplications = globSync('*/package.json', {
5256
cwd: `${__dirname}/../test-applications`,
5357
}).map(filePath => dirname(filePath));
5458

59+
// For GitHub Action debugging (using stderr the 'matrix=...' output is not polluted)
60+
// eslint-disable-next-line no-console
61+
console.error(`Discovered ${testApplications.length} test applications: ${testApplications.join(', ')}`);
62+
5563
// If `--base=xxx` is defined, we only want to get test applications changed since that base
5664
// Else, we take all test applications (e.g. on push)
5765
const includedTestApplications = base
@@ -137,11 +145,22 @@ function getAffectedTestApplications(
137145
additionalArgs.push(`--head=${head}`);
138146
}
139147

140-
const affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`)
141-
.toString()
142-
.split('\n')
143-
.map(line => line.trim())
144-
.filter(Boolean);
148+
let affectedProjects: string[] = [];
149+
try {
150+
affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`)
151+
.toString()
152+
.split('\n')
153+
.map(line => line.trim())
154+
.filter(Boolean);
155+
} catch (error) {
156+
// eslint-disable-next-line no-console
157+
console.error('Failed to compute affected projects via Nx. Running all tests instead.', error);
158+
return testApplications;
159+
}
160+
161+
// For GitHub Action debugging
162+
// eslint-disable-next-line no-console
163+
console.error(`Nx affected projects (${affectedProjects.length}): ${JSON.stringify(affectedProjects)}`);
145164

146165
// If something in e2e tests themselves are changed, check if only test applications were changed
147166
if (affectedProjects.includes('@sentry-internal/e2e-tests')) {
@@ -150,12 +169,19 @@ function getAffectedTestApplications(
150169

151170
// Shared code was changed, run all tests
152171
if (changedTestApps === false) {
172+
// eslint-disable-next-line no-console
173+
console.error('Shared e2e code changed. Running all test applications.');
153174
return testApplications;
154175
}
155176

156177
// Only test applications that were changed, run selectively
157178
if (changedTestApps.size > 0) {
158-
return testApplications.filter(testApp => changedTestApps.has(testApp));
179+
const selected = testApplications.filter(testApp => changedTestApps.has(testApp));
180+
// eslint-disable-next-line no-console
181+
console.error(
182+
`Only changed test applications will run (${selected.length}): ${JSON.stringify(Array.from(changedTestApps))}`,
183+
);
184+
return selected;
159185
}
160186
} catch (error) {
161187
// eslint-disable-next-line no-console
@@ -182,6 +208,10 @@ function getChangedTestApps(base: string, head?: string): false | Set<string> {
182208
.map(line => line.trim())
183209
.filter(Boolean);
184210

211+
// For GitHub Action debugging
212+
// eslint-disable-next-line no-console
213+
console.error(`Changed files since ${base}${head ? `..${head}` : ''}: ${JSON.stringify(changedFiles)}`);
214+
185215
const changedTestApps: Set<string> = new Set();
186216
const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/';
187217

0 commit comments

Comments
 (0)