Skip to content
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

chore: CircleCI performance improvements on PRs #9993

Merged

Conversation

olerichter00
Copy link
Contributor

@olerichter00 olerichter00 commented Mar 21, 2024

Description

This PR aims to improve CircleCI performance by running only relevant Jest tests on PR commits.

With this change, CircleCI only runs a subset of relevant Jest tests when:

  • the branch does not include release, build-me, or hotfix
  • the PR does not update any global ts(x) files outside of src/app/Scenes/,
  • the PR does not include a build-me tag.

If a PR only updates ts(x) within a scene, CircleCI will from now on only run a subset of relevant tests (within the same scene or with a similar name).

To Do

  • Add a label condition to trigger a full test run by adding a label to the pull request.
  • Add beta- branches to ignored branches
  • yarn.lock and package.json updates need to trigger test suite
Github Action idea to trigger when adding a tag

# Because we don't run all tests on every PR, adding the label "build-me" to a PR will trigger all tests to run on CircleCI. name: Run all js tests on "build-me" label on: pull_request: types: - labeled

jobs:
trigger:
permissions:
contents: none
runs-on: ubuntu-latest
steps:
- name: Trigger all js tests
run: |
curl
-X POST
--header "Content-Type: application/json"
-d "{"branch": "$GITHUB_HEAD_REF"}"
https://circleci.com/api/v1.1/project/github/artsy/eigen/build?circle-token=${{ secrets.CircleToken }}

Tests


Ideas

git diff --name-only origin/main...$CIRCLE_SHA1 | xargs -n 1 basename | grep -E '^.+\.(ts|tsx)$' | sed 's/\.[^.]*$//'

# Run all tests related to file names

yarn jest $(git diff --name-only origin/main...$CIRCLE_SHA1 | xargs -n 1 basename | grep -E '^.+\.(ts|tsx)$' | sed 's/\.tests//g' | sed 's/\.[^.]*$//')



# Get all updated ts* files

 git diff --name-only origin/main...$CIRCLE_SHA1 | xargs -n 1 basename | grep -E '^.+\.(ts|tsx)$'


# Get all updated scenes

git diff --name-only origin/main...$CIRCLE_SHA1 | grep -E '^.+\.(ts|tsx)$' | sed -n 's#^src/app/Scenes/\([^/]*\)/.*#src/app/Scenes/\1#p' | sort | uniq


# test all updated scenes and files

yarn jest $(git diff --name-only origin/main...$CIRCLE_SHA1 | xargs -n 1 basename | grep -E '^.+\.(ts|tsx)$') $(git diff --name-only origin/main...$CIRCLE_SHA1 | grep -E '^.+\.(ts|tsx)$' | sed -n 's#^src/app/Scenes/\([^/]*\)/.*#src/app/Scenes/\1#p' | uniq)



git diff --dirstat=files,0 HEAD main -- src/app/Scenes/ | grep -E '^[0-9.]+\s+src/app/Scenes/([^/]+)/$' -o | sed 's/src\/app\/Scenes\///'

PR Checklist

  • I have tested my changes on iOS and Android.
  • I hid my changes behind a feature flag, or they don't need one.
  • I have included screenshots or videos, or I have not changed the UI.
  • I have added tests, or my changes don't require any.
  • I added an app state migration, or my changes do not require one.
  • I have documented any follow-up work that this PR will require, or it does not require any.
  • I have added a changelog entry below, or my changes do not require one.

To the reviewers 👀

  • I would like at least one of the reviewers to run this PR on the simulator or device.
Changelog updates

Changelog updates

Cross-platform user-facing changes

iOS user-facing changes

Android user-facing changes

Dev changes

  • CircleCI test performance improvements for PR commits - ole

Need help with something? Have a look at our docs, or get in touch with us.

@ArtsyOpenSource
Copy link
Contributor

ArtsyOpenSource commented Mar 21, 2024

This PR contains the following changes:

  • Dev changes (CircleCI test performance improvements for PR commits - ole)

Generated by 🚫 dangerJS against 61d21cd

@olerichter00 olerichter00 self-assigned this Mar 21, 2024
@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch from 07fe19f to c48288b Compare March 21, 2024 16:59
@olerichter00 olerichter00 marked this pull request as draft March 21, 2024 17:01
@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch 3 times, most recently from a1070ee to 3d68cdd Compare March 21, 2024 17:13
@olerichter00 olerichter00 marked this pull request as ready for review March 21, 2024 17:40
@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch from 36186a2 to fe65bbc Compare March 21, 2024 17:40
@olerichter00 olerichter00 changed the title chore: CircleCI test performance improvements chore: CircleCI performance improvements on PRs Apr 16, 2024
@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch from 63f7de6 to 3c9a435 Compare April 16, 2024 08:04
MounirDhahri
MounirDhahri previously approved these changes Apr 16, 2024
Copy link
Member

@MounirDhahri MounirDhahri left a comment

Choose a reason for hiding this comment

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

Nice addition! I think this can have a big impact on how fast our tests run.

Something came to my mind when reviewing this, if a user updates a method within a file that is not under /Scenes, we can run all tests. Ideally, we would run tests only in files that are importing that method but that might not be trivial. What do you think about it?

@olerichter00
Copy link
Contributor Author

Ideally, we would run tests only in files that are importing that method but that might not be trivial. What do you think about it?

Yes, that would be ideal. There might even be tools that calculate an import tree to run all tests that import files (importing files) which import the updated file. I remember reading an article about someone doing this for Ruby projects. This could be a next step to avoid running non-related tests and, at the same time, to make sure all tests that could potentially fail run in CircleCI.

ignore:
- main
- /.*release$/
- /.*build-me$/
Copy link
Contributor

Choose a reason for hiding this comment

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

thought, non-blocking: Always running all tests for main, release and hot fixes makes a lot of sense, for build-me I wonder if forcing a run based on something like a label would be better than having to rename the branch: https://github.com/marketplace/actions/run-circle-ci-on-label

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea! 👍 It might be good to keep both because this is how to force all tests to run in Gravity. I'll try to make this version with the label work as well and then add it here and to Gravity's CircleCI config.

Copy link
Member

Choose a reason for hiding this comment

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

Let's also add the beta-ios and beta-android branches here ❤️

echo "No ts|tsx files are updated. Skipping tests."
then
yarn jest $JEST_OPTIONS
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

brainbicycle
brainbicycle previously approved these changes Apr 16, 2024
Copy link
Contributor

@brainbicycle brainbicycle left a comment

Choose a reason for hiding this comment

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

great addition! minor comment about how we force a build

@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch 3 times, most recently from 5c4bff7 to 80e4bec Compare April 22, 2024 14:39
@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch 2 times, most recently from 609406d to 8da1183 Compare April 26, 2024 11:09
@@ -0,0 +1,20 @@
# Because we don't run all tests on every PR, adding the label "build-me" to a PR will trigger all tests to run on CircleCI.
name: Run all js tests on "build-me" label
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should trigger all tests when adding the label build-me to the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brainbicycle well, this does not work as expected.... Do you have an idea how this could work? I've tried a bit but couldn't find out how to correctly trigger the tests when adding the build-me label with GitHub actions.

Copy link
Contributor

Choose a reason for hiding this comment

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

it def doesn't have to block anything, I might mess with it one of these future fridays

brainbicycle
brainbicycle previously approved these changes May 3, 2024
Copy link
Contributor

@brainbicycle brainbicycle left a comment

Choose a reason for hiding this comment

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

awesome!

MrSltun
MrSltun previously approved these changes May 6, 2024
Copy link
Member

@MrSltun MrSltun left a comment

Choose a reason for hiding this comment

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

Looks great!! ⚡

@olerichter00 olerichter00 added Squash On Green A label to indicate that Peril should squash-merge this PR when all statuses are green build-me and removed build-me labels May 13, 2024
@olerichter00 olerichter00 dismissed stale reviews from MrSltun and brainbicycle via 61d21cd May 15, 2024 14:43
@olerichter00 olerichter00 force-pushed the olerichter00/circleci-test-performance-improvements branch from 8da1183 to 61d21cd Compare May 15, 2024 14:43
@olerichter00 olerichter00 merged commit 231bb4d into main May 15, 2024
7 checks passed
@olerichter00 olerichter00 deleted the olerichter00/circleci-test-performance-improvements branch May 15, 2024 18:53
olerichter00 added a commit that referenced this pull request May 16, 2024
olerichter00 added a commit that referenced this pull request May 16, 2024
Revert "chore: CircleCI performance improvements on PRs (#9993)"

This reverts commit 231bb4d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-me Squash On Green A label to indicate that Peril should squash-merge this PR when all statuses are green
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants