From e01dca767030295f1474393c061834daa95336fb Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Tue, 16 Sep 2025 16:56:04 +0200 Subject: [PATCH 1/4] ci(test-matrix): Add logs for `getTestMatrix` --- dev-packages/e2e-tests/lib/getTestMatrix.ts | 48 ++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/dev-packages/e2e-tests/lib/getTestMatrix.ts b/dev-packages/e2e-tests/lib/getTestMatrix.ts index 1261e7d5b3ac..6f375d194c02 100644 --- a/dev-packages/e2e-tests/lib/getTestMatrix.ts +++ b/dev-packages/e2e-tests/lib/getTestMatrix.ts @@ -48,10 +48,24 @@ function run(): void { const { base, head = 'HEAD', optional } = values; + // For GitHub Action debugging + // eslint-disable-next-line no-console + console.log(`Parsed command line arguments: base=${base}, head=${head}, optional=${optional}`); + const testApplications = globSync('*/package.json', { cwd: `${__dirname}/../test-applications`, }).map(filePath => dirname(filePath)); + // For GitHub Action debugging + // eslint-disable-next-line no-console + console.log( + `Discovered ${testApplications.length} test applications${ + testApplications.length > 0 + ? ` (sample: ${JSON.stringify(testApplications.slice(0, 10))}${testApplications.length > 10 ? ' …' : ''})` + : '' + }`, + ); + // If `--base=xxx` is defined, we only want to get test applications changed since that base // Else, we take all test applications (e.g. on push) const includedTestApplications = base @@ -137,11 +151,22 @@ function getAffectedTestApplications( additionalArgs.push(`--head=${head}`); } - const affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`) - .toString() - .split('\n') - .map(line => line.trim()) - .filter(Boolean); + let affectedProjects: string[] = []; + try { + affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`) + .toString() + .split('\n') + .map(line => line.trim()) + .filter(Boolean); + } catch (error) { + // eslint-disable-next-line no-console + console.warn('Failed to compute affected projects via Nx. Running all tests instead.', error); + return testApplications; + } + + // For GitHub Action debugging + // eslint-disable-next-line no-console + console.log('Nx affected projects:', JSON.stringify(affectedProjects)); // If something in e2e tests themselves are changed, check if only test applications were changed if (affectedProjects.includes('@sentry-internal/e2e-tests')) { @@ -150,12 +175,19 @@ function getAffectedTestApplications( // Shared code was changed, run all tests if (changedTestApps === false) { + // eslint-disable-next-line no-console + console.log('Shared e2e code changed. Running all test applications.'); return testApplications; } // Only test applications that were changed, run selectively if (changedTestApps.size > 0) { - return testApplications.filter(testApp => changedTestApps.has(testApp)); + const selected = testApplications.filter(testApp => changedTestApps.has(testApp)); + // eslint-disable-next-line no-console + console.log( + `Only changed test applications will run (${selected.length}): ${JSON.stringify(Array.from(changedTestApps))}`, + ); + return selected; } } catch (error) { // eslint-disable-next-line no-console @@ -182,6 +214,10 @@ function getChangedTestApps(base: string, head?: string): false | Set { .map(line => line.trim()) .filter(Boolean); + // For GitHub Action debugging + // eslint-disable-next-line no-console + console.log(`Changed files since ${base}${head ? `..${head}` : ''}:`, JSON.stringify(changedFiles)); + const changedTestApps: Set = new Set(); const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/'; From 0ba4fd9294ba6e69547cc7a4064e75f042a51efa Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Tue, 16 Sep 2025 17:21:21 +0200 Subject: [PATCH 2/4] trying stderr - or is this erroring in CI --- dev-packages/e2e-tests/lib/getTestMatrix.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dev-packages/e2e-tests/lib/getTestMatrix.ts b/dev-packages/e2e-tests/lib/getTestMatrix.ts index 6f375d194c02..d425a4ac9493 100644 --- a/dev-packages/e2e-tests/lib/getTestMatrix.ts +++ b/dev-packages/e2e-tests/lib/getTestMatrix.ts @@ -50,15 +50,15 @@ function run(): void { // For GitHub Action debugging // eslint-disable-next-line no-console - console.log(`Parsed command line arguments: base=${base}, head=${head}, optional=${optional}`); + console.error(`Parsed command line arguments: base=${base}, head=${head}, optional=${optional}`); const testApplications = globSync('*/package.json', { cwd: `${__dirname}/../test-applications`, }).map(filePath => dirname(filePath)); - // For GitHub Action debugging + // For GitHub Action debugging (using stderr the 'matrix=...' output is not polluted) // eslint-disable-next-line no-console - console.log( + console.error( `Discovered ${testApplications.length} test applications${ testApplications.length > 0 ? ` (sample: ${JSON.stringify(testApplications.slice(0, 10))}${testApplications.length > 10 ? ' …' : ''})` @@ -166,7 +166,7 @@ function getAffectedTestApplications( // For GitHub Action debugging // eslint-disable-next-line no-console - console.log('Nx affected projects:', JSON.stringify(affectedProjects)); + console.error(`Nx affected projects: ${JSON.stringify(affectedProjects)}`); // If something in e2e tests themselves are changed, check if only test applications were changed if (affectedProjects.includes('@sentry-internal/e2e-tests')) { @@ -176,7 +176,7 @@ function getAffectedTestApplications( // Shared code was changed, run all tests if (changedTestApps === false) { // eslint-disable-next-line no-console - console.log('Shared e2e code changed. Running all test applications.'); + console.error('Shared e2e code changed. Running all test applications.'); return testApplications; } @@ -184,7 +184,7 @@ function getAffectedTestApplications( if (changedTestApps.size > 0) { const selected = testApplications.filter(testApp => changedTestApps.has(testApp)); // eslint-disable-next-line no-console - console.log( + console.error( `Only changed test applications will run (${selected.length}): ${JSON.stringify(Array.from(changedTestApps))}`, ); return selected; @@ -216,7 +216,7 @@ function getChangedTestApps(base: string, head?: string): false | Set { // For GitHub Action debugging // eslint-disable-next-line no-console - console.log(`Changed files since ${base}${head ? `..${head}` : ''}:`, JSON.stringify(changedFiles)); + console.error(`Changed files since ${base}${head ? `..${head}` : ''}: ${JSON.stringify(changedFiles)}`); const changedTestApps: Set = new Set(); const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/'; From 9bfc47c59daf8588a5909100f61fb4e251af92cc Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Wed, 17 Sep 2025 10:05:00 +0200 Subject: [PATCH 3/4] review comments --- dev-packages/e2e-tests/lib/getTestMatrix.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/dev-packages/e2e-tests/lib/getTestMatrix.ts b/dev-packages/e2e-tests/lib/getTestMatrix.ts index d425a4ac9493..c104407ff8c1 100644 --- a/dev-packages/e2e-tests/lib/getTestMatrix.ts +++ b/dev-packages/e2e-tests/lib/getTestMatrix.ts @@ -58,13 +58,7 @@ function run(): void { // For GitHub Action debugging (using stderr the 'matrix=...' output is not polluted) // eslint-disable-next-line no-console - console.error( - `Discovered ${testApplications.length} test applications${ - testApplications.length > 0 - ? ` (sample: ${JSON.stringify(testApplications.slice(0, 10))}${testApplications.length > 10 ? ' …' : ''})` - : '' - }`, - ); + console.error(`Discovered ${testApplications.length} test applications: ${testApplications.join(', ')}`); // If `--base=xxx` is defined, we only want to get test applications changed since that base // Else, we take all test applications (e.g. on push) @@ -160,7 +154,7 @@ function getAffectedTestApplications( .filter(Boolean); } catch (error) { // eslint-disable-next-line no-console - console.warn('Failed to compute affected projects via Nx. Running all tests instead.', error); + console.error('Failed to compute affected projects via Nx. Running all tests instead.', error); return testApplications; } From 87f42409847297b75d233c52cf77bbb78c72c161 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Wed, 17 Sep 2025 10:07:50 +0200 Subject: [PATCH 4/4] add count --- dev-packages/e2e-tests/lib/getTestMatrix.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/e2e-tests/lib/getTestMatrix.ts b/dev-packages/e2e-tests/lib/getTestMatrix.ts index c104407ff8c1..8d02e79310af 100644 --- a/dev-packages/e2e-tests/lib/getTestMatrix.ts +++ b/dev-packages/e2e-tests/lib/getTestMatrix.ts @@ -160,7 +160,7 @@ function getAffectedTestApplications( // For GitHub Action debugging // eslint-disable-next-line no-console - console.error(`Nx affected projects: ${JSON.stringify(affectedProjects)}`); + console.error(`Nx affected projects (${affectedProjects.length}): ${JSON.stringify(affectedProjects)}`); // If something in e2e tests themselves are changed, check if only test applications were changed if (affectedProjects.includes('@sentry-internal/e2e-tests')) {