Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions dev-packages/e2e-tests/lib/getTestMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ function run(): void {

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

// For GitHub Action debugging
// eslint-disable-next-line no-console
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 (using stderr the 'matrix=...' output is not polluted)
// eslint-disable-next-line no-console
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)
const includedTestApplications = base
Expand Down Expand Up @@ -137,11 +145,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.error('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.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')) {
Expand All @@ -150,12 +169,19 @@ function getAffectedTestApplications(

// Shared code was changed, run all tests
if (changedTestApps === false) {
// eslint-disable-next-line no-console
console.error('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.error(
`Only changed test applications will run (${selected.length}): ${JSON.stringify(Array.from(changedTestApps))}`,
);
return selected;
}
} catch (error) {
// eslint-disable-next-line no-console
Expand All @@ -182,6 +208,10 @@ function getChangedTestApps(base: string, head?: string): false | Set<string> {
.map(line => line.trim())
.filter(Boolean);

// For GitHub Action debugging
// eslint-disable-next-line no-console
console.error(`Changed files since ${base}${head ? `..${head}` : ''}: ${JSON.stringify(changedFiles)}`);

const changedTestApps: Set<string> = new Set();
const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/';

Expand Down