-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ci: Only run E2E test apps that are affected on PRs #14254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7992232
ci: Only run E2E test apps that are affected on PRs
mydea 45f9e67
fix checkout
mydea 83be5c6
add missing skip
mydea c92f5d8
mark optionals as optional
mydea 376b1a8
Generate E2E matrix programmatically
mydea 5023b05
WIP test browser change
mydea c895065
fix linting
mydea 62c1d68
handle non-PRs
mydea b424ba4
fix it
mydea 07c6735
fix remaining thing, oops
mydea 0d161a7
fix test apps without name
mydea 9324ade
fix linting
mydea 64165eb
Revert "WIP test browser change"
mydea 067bb11
better handling for pushes
mydea 20cd6ef
small fixes
mydea 9827c38
remove unneeded
mydea dc7dd91
skip when no tests ???
mydea 2ab5a78
fix check
mydea 6fdad14
remove unneeded
mydea ec2a1a7
PR feedback
mydea e68dc71
fix node types version
mydea 2ba6776
explicit add types
mydea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { execSync } from 'child_process'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { dirname } from 'path'; | ||
import { parseArgs } from 'util'; | ||
import { sync as globSync } from 'glob'; | ||
|
||
interface MatrixInclude { | ||
/** The test application (directory) name. */ | ||
'test-application': string; | ||
/** Optional override for the build command to run. */ | ||
'build-command'?: string; | ||
/** Optional override for the assert command to run. */ | ||
'assert-command'?: string; | ||
/** Optional label for the test run. If not set, defaults to value of `test-application`. */ | ||
label?: string; | ||
} | ||
|
||
interface PackageJsonSentryTestConfig { | ||
/** If this is true, the test app is optional. */ | ||
optional?: boolean; | ||
/** Variant configs that should be run in non-optional test runs. */ | ||
variants?: Partial<MatrixInclude>[]; | ||
/** Variant configs that should be run in optional test runs. */ | ||
optionalVariants?: Partial<MatrixInclude>[]; | ||
/** Skip this test app for matrix generation. */ | ||
skip?: boolean; | ||
} | ||
|
||
/** | ||
* This methods generates a matrix for the GitHub Actions workflow to run the E2E tests. | ||
* It checks which test applications are affected by the current changes in the PR and then generates a matrix | ||
* including all test apps that have at least one dependency that was changed in the PR. | ||
* If no `--base=xxx` is provided, it will output all test applications. | ||
* | ||
* If `--optional=true` is set, it will generate a matrix of optional test applications only. | ||
* Otherwise, these will be skipped. | ||
*/ | ||
function run(): void { | ||
const { values } = parseArgs({ | ||
args: process.argv.slice(2), | ||
options: { | ||
base: { type: 'string' }, | ||
head: { type: 'string' }, | ||
optional: { type: 'string', default: 'false' }, | ||
}, | ||
}); | ||
|
||
const { base, head, optional } = values; | ||
|
||
const testApplications = globSync('*/package.json', { | ||
cwd: `${__dirname}/../test-applications`, | ||
}).map(filePath => dirname(filePath)); | ||
|
||
// 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 | ||
? getAffectedTestApplications(testApplications, { base, head }) | ||
: testApplications; | ||
|
||
const optionalMode = optional === 'true'; | ||
const includes: MatrixInclude[] = []; | ||
|
||
includedTestApplications.forEach(testApp => { | ||
addIncludesForTestApp(testApp, includes, { optionalMode }); | ||
}); | ||
|
||
// We print this to the output, so the GHA can use it for the matrix | ||
// eslint-disable-next-line no-console | ||
console.log(`matrix=${JSON.stringify({ include: includes })}`); | ||
} | ||
|
||
function addIncludesForTestApp( | ||
testApp: string, | ||
includes: MatrixInclude[], | ||
{ optionalMode }: { optionalMode: boolean }, | ||
): void { | ||
const packageJson = getPackageJson(testApp); | ||
|
||
const shouldSkip = packageJson.sentryTest?.skip || false; | ||
const isOptional = packageJson.sentryTest?.optional || false; | ||
const variants = (optionalMode ? packageJson.sentryTest?.optionalVariants : packageJson.sentryTest?.variants) || []; | ||
|
||
if (shouldSkip) { | ||
return; | ||
} | ||
|
||
// Add the basic test-application itself, if it is in the current mode | ||
if (optionalMode === isOptional) { | ||
includes.push({ | ||
'test-application': testApp, | ||
}); | ||
} | ||
|
||
variants.forEach(variant => { | ||
includes.push({ | ||
'test-application': testApp, | ||
...variant, | ||
}); | ||
}); | ||
} | ||
|
||
function getSentryDependencies(appName: string): string[] { | ||
const packageJson = getPackageJson(appName) || {}; | ||
|
||
const dependencies = { | ||
...packageJson.devDependencies, | ||
...packageJson.dependencies, | ||
}; | ||
|
||
return Object.keys(dependencies).filter(key => key.startsWith('@sentry')); | ||
} | ||
|
||
function getPackageJson(appName: string): { | ||
dependencies?: { [key: string]: string }; | ||
devDependencies?: { [key: string]: string }; | ||
sentryTest?: PackageJsonSentryTestConfig; | ||
} { | ||
const fullPath = path.resolve(__dirname, '..', 'test-applications', appName, 'package.json'); | ||
|
||
if (!fs.existsSync(fullPath)) { | ||
throw new Error(`Could not find package.json for ${appName}`); | ||
} | ||
|
||
return JSON.parse(fs.readFileSync(fullPath, 'utf8')); | ||
} | ||
|
||
run(); | ||
|
||
function getAffectedTestApplications( | ||
testApplications: string[], | ||
{ base = 'develop', head }: { base?: string; head?: string }, | ||
): string[] { | ||
const additionalArgs = [`--base=${base}`]; | ||
|
||
if (head) { | ||
additionalArgs.push(`--head=${head}`); | ||
} | ||
|
||
const affectedProjects = execSync(`yarn --silent nx show projects --affected ${additionalArgs.join(' ')}`) | ||
.toString() | ||
.split('\n') | ||
.map(line => line.trim()) | ||
.filter(Boolean); | ||
chargome marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// If something in e2e tests themselves are changed, just run everything | ||
if (affectedProjects.includes('@sentry-internal/e2e-tests')) { | ||
return testApplications; | ||
} | ||
|
||
return testApplications.filter(testApp => { | ||
const sentryDependencies = getSentryDependencies(testApp); | ||
return sentryDependencies.some(dep => affectedProjects.includes(dep)); | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,8 @@ | |
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
}, | ||
"sentryTest": { | ||
"optional": true | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also filter
@sentry-internal
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like if some e2e test has a dependency on some internal package, we should also re-run it in this case? the classic thing would be
@sentry-internal/test-utils
, IMHO changes there should trigger all e2e tests that use this (which is all of them 😅 )