I've been working on a project at work recently which is seeing us migrate from CircleCI to GitHub Actions. We use jest to test our frontend code, and to match the speed of our CircleCI setup, we needed to parallelize our tests.
For this, we're using a combination of GitHub's Larger Runners (Specifically an 8-core runner, using Ubuntu 20.04) and Jest's built-in sharding capabilities. In this post, I'll show you how you can do the same, but using GitHub's standard runners.
Note: You'll see that I use ${{ github.event.pull_request.head.sha || github.sha }} here - this is because the github.sha works in a way you probably don't expect.
The github.sha is the sha of the most recent merge commit to the branch, not the HEAD of the PR branch. This means that if you're running on a PR, you'll need to use the PR's head SHA to get the correct results.
The setup
Firstly, you'll need to configure your GitHub Actions workflow to use a matrix strategy. This will allow you to run multiple jobs in parallel, and will be the basis for the sharding.
After we run the tests, we'll want to report their status. For this example, I'm using dorny/test-reporter to report the test results back to GitHub Actions.
It's worth going and reading the docs for this action, as it has a tonne of options for different test reporters, reporting modes, etc.