Skip to content

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 22 commits into from
Nov 15, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Nov 13, 2024

This PR aims to solve two things:

  1. Do not require us to keep a list of test-applications to run on CI. This is prone to be forgotten, and then certain tests do not run on CI and we may not notice (this has happened more than once in the past 😬 )
  2. Do not run E2E test applications that are unrelated to anything that was changed.

With this PR, instead of keeping a list of E2E test jobs we want to run manually in the build.yml file, this is now inferred (on CI) by a script based on the nx dependency graph and some config in the test apps package.json. This is how it works:

  1. Pick all folders in test-applications, by default all of them should run. --> This will "fix" the problem we had sometimes that we forgot to add test apps to the build.yml so they don't actually run on CI 😬
  2. For each test app, look at it's dependencies (and devDependencies), and see if any of them has changed in the current PR (based on nx affected projects). So e.g. if you change something in browser, only E2E test apps that have any dependency that uses browser will run, so e.g. node-express will be skipped.
  3. Additionally, you can configure variants in the test apps package.json - instead of defining this in the workflow file, it has to be defined in the test app itself now.
  4. Finally, a test app can be marked as optional in the package.json, and can also have optional variants to run.
  5. The E2E test builds the required & optional matrix on the fly based on these things.
  6. In pushes (=on develop/release branches) we just run everything.
  7. If anything inside of the e2e-tests package changed, run everything. --> This could be further optimized to only run changed test apps, but this was the easy solution for now.

Example test runs

Copy link
Contributor

github-actions bot commented Nov 13, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.77 KB - -
@sentry/browser - with treeshaking flags 21.53 KB - -
@sentry/browser (incl. Tracing) 35.27 KB - -
@sentry/browser (incl. Tracing, Replay) 71.99 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.37 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.3 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 89.15 KB - -
@sentry/browser (incl. Feedback) 39.93 KB - -
@sentry/browser (incl. sendFeedback) 27.42 KB - -
@sentry/browser (incl. FeedbackAsync) 32.23 KB - -
@sentry/react 25.52 KB - -
@sentry/react (incl. Tracing) 38.23 KB - -
@sentry/vue 26.92 KB - -
@sentry/vue (incl. Tracing) 37.1 KB - -
@sentry/svelte 22.91 KB - -
CDN Bundle 24.13 KB - -
CDN Bundle (incl. Tracing) 37.05 KB - -
CDN Bundle (incl. Tracing, Replay) 71.71 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.06 KB - -
CDN Bundle - uncompressed 70.73 KB - -
CDN Bundle (incl. Tracing) - uncompressed 109.93 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 222.45 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 235.67 KB - -
@sentry/nextjs (client) 38.35 KB - -
@sentry/sveltekit (client) 35.85 KB - -
@sentry/node 134.05 KB - -
@sentry/node - without tracing 96.24 KB - -
@sentry/aws-serverless 106.49 KB - -

View base workflow run

@mydea mydea force-pushed the fn/only-run-changed-e2e-tests branch from ae3d63c to fcd6b78 Compare November 13, 2024 15:19
@mydea mydea self-assigned this Nov 13, 2024
@mydea mydea force-pushed the fn/only-run-changed-e2e-tests branch 3 times, most recently from 927af9e to c7df3bf Compare November 14, 2024 11:54
@mydea mydea marked this pull request as ready for review November 14, 2024 14:00
Comment on lines 23 to 32
const args: Record<string, string> = {};
process.argv
.slice(2)
.filter(arg => arg.startsWith('--') && arg.includes('='))
.forEach(arg => {
const [part1, part2] = arg.split('=') as [string, string];
const argName = part1.replace('--', '');
const argValue = part2;
args[argName] = argValue;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I was looking for this (remembered that something like this exists, but was not sure anymore how/where) - that's much better!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also required bumping the node types in the e2e-tests package, but that should be OK i'd say (as we use node 18 anyhow).

...packageJson.dependencies,
};

return Object.keys(dependencies).filter(key => key.startsWith('@sentry'));
Copy link
Member

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?

Copy link
Member Author

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 😅 )

@mydea mydea force-pushed the fn/only-run-changed-e2e-tests branch from 2f61b7f to e68dc71 Compare November 15, 2024 08:41
@mydea mydea merged commit a5a214c into develop Nov 15, 2024
178 checks passed
@mydea mydea deleted the fn/only-run-changed-e2e-tests branch November 15, 2024 11:54
onurtemizkan pushed a commit that referenced this pull request Nov 22, 2024
This PR aims to solve two things:

1. Do not require us to keep a list of test-applications to run on CI.
This is prone to be forgotten, and then certain tests do not run on CI
and we may not notice (this has happened more than once in the past 😬 )
2. Do not run E2E test applications that are unrelated to anything that
was changed.

With this PR, instead of keeping a list of E2E test jobs we want to run
manually in the build.yml file, this is now inferred (on CI) by a script
based on the nx dependency graph and some config in the test apps
package.json. This is how it works:

1. Pick all folders in test-applications, by default all of them should
run. --> This will "fix" the problem we had sometimes that we forgot to
add test apps to the build.yml so they don't actually run on CI
:grimacing:
3. For each test app, look at it's dependencies (and devDependencies),
and see if any of them has changed in the current PR (based on nx
affected projects). So e.g. if you change something in browser, only E2E
test apps that have any dependency that uses browser will run, so e.g.
node-express will be skipped.
4. Additionally, you can configure variants in the test apps
package.json - instead of defining this in the workflow file, it has to
be defined in the test app itself now.
5. Finally, a test app can be marked as optional in the package.json,
and can also have optional variants to run.
6. The E2E test builds the required & optional matrix on the fly based
on these things.
7. In pushes (=on develop/release branches) we just run everything.
8. If anything inside of the e2e-tests package changed, run everything.
--> This could be further optimized to only run changed test apps, but
this was the easy solution for now.

## Example test runs

* In a PR with no changes related to the E2E tests, nothing is run:
https://github.com/getsentry/sentry-javascript/actions/runs/11838604965
* In a CI run for a push, all E2E tests are run:
https://github.com/getsentry/sentry-javascript/actions/runs/11835834748
* In a PR with a change in e2e-tests itself, all E2E tests are run:
https://github.com/getsentry/sentry-javascript/actions/runs/11836668035
* In a PR with a change in the node package, only related E2E tests are
run:
https://github.com/getsentry/sentry-javascript/actions/runs/11838274483
s1gr1d added a commit that referenced this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants