Parallel Test Execution Patterns in GitHub Actions
Shard, fan out, and cache to cut CI time without losing verdicts.
Sponsored by Graphide

Parallel test execution in GitHub Actions shortens CI waits through matrix sharding, concurrent steps, and test-type fan-out, each trading speed against isolation and compute cost. Selective testing can preserve the verdict of a full run when omissions rest on evidence that a change cannot reach those tests. When reachability is uncertain, the affected tests must run.
Why parallel test execution is a workflow architecture decision, not just a speed tweak
With a serial test job, every test added to the suite makes developers wait longer before they can act. Slow feedback also means developers pay a context-switching cost when they move to other work while CI runs. Breaking the relationship between suite size and elapsed time requires decomposing the work into concurrent units.
That decomposition changes the resource budget as well. Three parallel three-minute jobs use nine job-minutes even though they finish in three minutes. Doing setup again for each job can use even more compute. Matrix sharding distributes a suite across jobs, step-level parallelism shares a runner, and test-type fan-out separates categories with different infrastructure needs. The architecture must divide work into independent units without introducing disproportionate overhead.
Matrix-based job sharding: splitting one test job into many runners
Oh Dear’s PHP workflow split a Pest suite into twelve equal shards, cutting runtime from sixteen minutes to four. Its custom runner script receives TOTAL_SHARD_COUNT and SHARD_NUMBER as environment variables. Each runner executes its assigned slice of the suite. GitHub Actions supplies the replication through strategy.matrix, which expands one job definition into multiple jobs with different matrix values.
With a static configuration, the shard indices are hard-coded, and each index is passed to the test runner. Jest and Vitest accept an index-of-total sharding flag, while pytest-split uses --splits and --group, and Pest uses --shard. PHPUnit has no native shard flag, so workarounds use --filter with a generated regular expression. Failure handling needs an explicit choice here. Setting fail-fast to false lets the remaining shards report after one fails instead of cancelling them before their results arrive.
Static shards suit stable suites because they require no setup job and are easy to reason about. Growth makes the fixed count less useful. A dynamic setup job instead counts test files, calculates a shard count targeting roughly twenty tests per shard, caps the result, and emits a JSON matrix. Downstream jobs consume that output through fromJson. This avoids over-partitioning small suites and under-partitioning large ones, but adds a dependency and shell arithmetic that must be maintained.
File counts alone cannot balance uneven test durations. Timing-based splitting uses per-test measurements from prior runs, stored in the Actions cache, to distribute work by duration. The slowest shard still determines completion time. The max-parallel setting caps how many matrix jobs run at once, and exclude cuts out combinations that are not needed when operating systems and Node versions multiply the job count. The include key adds special cases with extra variables, such as an experimental entry that can fail without blocking the workflow.
Step-level parallelism: running concurrent work inside a single job
GitHub added first-class parallel step controls on June 25, 2026, making within-job concurrency a supported primitive. The parallel control groups steps that run simultaneously, while background starts work that continues with subsequent steps. The wait and wait-all controls block until one or all parallel branches finish, and cancel stops a named background step by its ID, optionally under an if condition.
This pattern fits independent tasks that are lightweight enough to share a runner, such as a linter and a type-checker. Separate jobs can add more startup latency than such tasks justify. A service can also start while dependencies install. However, large compute-heavy suites are a poor fit because concurrent steps share CPU and memory. Step-level parallelism therefore complements matrix sharding where runner capacity is available rather than replacing the isolation that separate runners provide.
Test-type fan-out: running unit, integration, and end-to-end tests as independent jobs
Test-type fan-out starts with three independent jobs for unit, integration, and end-to-end tests. Their boundaries follow infrastructure needs. Unit tests need no services and can use a high shard count, such as a matrix containing shards one, two, and three. Integration tests can declare Postgres and Redis under job-level services, with health checks and fewer shards. Database setup can dominate their runtime, so multiplying runners also multiplies a substantial setup cost.
A job-level database container lets tests share that service across test runs for the job. An end-to-end matrix over chromium, firefox, and webkit runs tests against different browser environments rather than simply dividing one suite into disjoint slices. Each browser job can still use Playwright’s --shard flag when its suite is big enough to be worth splitting further.
These independent jobs also need a unified result. Shards can upload JUnit XML or Playwright blob reports as artifacts, but those files must be collected before the workflow presents a combined result to branch protection. For Playwright, a downstream merge-reports job assembles the reports.
Warm caches as the prerequisite that makes all three patterns work
Every cold matrix runner installs the same dependencies unless the workflow provides a reusable cache. Passing the cache option with npm, or pip for Python, to the setup action enables built-in dependency caching with little configuration. A cache hit can cut a typical installation from over a minute to seconds. But frequent lockfile changes, large cached directories, or a package manager download faster than cache restoration can erase that advantage.
Build outputs need sharing as well as dependencies. A one-time build can upload compiled assets or generated code through actions/upload-artifact, with downstream jobs retrieving them through actions/download-artifact. Oh Dear shares its Composer vendor directory across shards this way. How fast a cache restores still depends on the runner and provider, and persistent local disks on third-party or self-hosted runners can keep caches warmer than GitHub-hosted runners do by default.
Selective testing: how can it preserve the result of a full CI test run?
Selective testing preserves a full-run verdict only when skipped work is outside the change’s reach. The evidence must cover both indirect dependencies and the directory that holds the edited file. When that evidence is incomplete, the conservative fallback is to run the affected tests. This distinction separates correctness-preserving test selection from an optimistic shortcut.
An initial filter job can use dorny/paths-filter to inspect changed files and publish boolean outputs that control downstream jobs. Native paths-ignore also supports path-based filtering. Paths alone cannot show all the indirect effects of a change. Turborepo and Nx provide affected-build detection through the dependency graph, while shared libraries, build scripts, and GitHub Actions files must trigger all jobs when they change. A filter limited to product directories can otherwise skip tests after a change to CI itself.
If a required status check never runs because filtering skips it, GitHub can leave the PR at “Expected — Waiting for status to be reported”. A ci-gate sentinel resolves this by declaring dependencies on jobs such as lint-and-typecheck, unit-tests, and e2e, and always running. Branch protection then uses the sentinel as the required check for the conditional jobs.
The sentinel must distinguish an intentional skip from a failure. It can report success when unnecessary upstream jobs are skipped, but must not turn failed required work into a passing verdict. This gives branch protection one stable decision point. The selection policy determines what must run, and the gate reports whether that work passed.
Keeping the CI verdict trustworthy when agents write most of the code
When Claude Code or Codex authors most pull requests, passing tests remain necessary but insufficient evidence of safety. An agent can satisfy narrow assertions while introducing behavior the suite does not cover. Faster authorship also increases demand for CI feedback. A two-minute verdict has limited value if its checks leave the central behavioral questions unanswered.
Behavioral comparison addresses that gap by running old and new versions against the same inputs and comparing outputs. Review is a separate layer: Graphide review, for example, reports findings on a pull request and says for each how it is known, including when it could not be verified. The evidence complements CI. Pilot-consistency validation offers another approach by checking out the candidate commit and base SHA into separate paths and comparing actual file content and command output for that specific commit.
Microsoft Threat Intelligence reported a prompt injection vulnerability in Claude Code that was mitigated in version 2.1.128 on May 4, 2026. Agent workflows that process untrusted issue bodies, PR descriptions, or comments must keep secrets out of the execution context where that content is handled. Speed does not reduce this exposure to untrusted content. Behavioral gates should also run on both pull_request and merge_group so that verification covers review and the merge queue.
Faster runners and Graphide CI: reducing the time between push and verdict
Once the workflow exposes independent work, hardware and cache throughput set the remaining runtime floor. Standard GitHub-hosted ubuntu-latest runners provide two cores for private repositories and four for public repositories. Private-repository minutes count against included minutes, while public-repository minutes are not billed. Both still have finite CPU throughput. GitHub’s larger runners offer up to 96 vCPU, 384 GB RAM, and 2040 GiB SSD, with higher per-minute pricing and availability limited to organizations on GitHub Team or Enterprise Cloud.
GitHub’s February 2026 Actions roundup added custom autoscaling and broader action allowlisting, expanding the options for dynamic runner fleets. Third-party providers are another way to get different hardware and cache infrastructure. Graphide CI runs existing Actions jobs on its own runners with warm caches, splitting long test steps only where a check shows every result stays the same. Its pricing page says it bills per vCPU-minute for the time a job would take without its speed-ups. A failing test still fails the job. Its runner migration can retain an existing sharded workflow.
Timing-based sharding and evidence-based selection use measurements for different decisions. The former balances work, while the latter determines which work a change can reach. Graphide CI does the first and not the second: it splits tests across runners where a check shows every result stays the same, and every test the job runs today still runs. Any improvement should be evaluated per workflow against a stated baseline, because it depends on workload, cache hit rate, and whether compute, network, or I/O dominates.
Choosing the right combination of patterns for a given team and codebase
The practical sequence starts with caching, so repeated setup does not distort the value of later changes. Fan-out comes next when test categories need different services or runner configurations. Sharding then splits up the job types that still have heavy workloads. Static shards provide the simplest starting point, with dynamic sizing or timing-based splitting justified when suite growth or imbalance becomes a measured problem. Lightweight tasks that can run on their own can then use step-level parallelism without the cost of starting separate runners.
Selection is most useful when changes are genuinely scoped. In a monorepo or large codebase, path filters need shared-infrastructure coverage and a ci-gate sentinel, while dependency-aware selection needs evidence and conservative fallback behavior. Compute budgets also constrain how much concurrency is useful. Teams with limited minutes should use max-parallel and exclude to control spend and measure actual consumption before and after changes. Where agents write most PRs, evidence-backed review or pilot-consistency validation can help answer questions that a passing suite alone cannot settle.
The target is the same verdict, less waiting, with inspectable evidence behind both the tests that ran and the work left out.


