GitHub Actions matrix build takes 40 minutes. How do I cut it down without losing coverage?
Our agency maintains a TypeScript monorepo for a client and the CI workflow has crept up to about 40 minutes on every pull request. It is one job with a matrix of 3 Node versions across 3 operating systems, plus a test step that runs unit and integration tests together. Everyone is starting to merge without waiting, which is the opposite of what CI is for.
Cite
GitShowcase Forum, "GitHub Actions matrix build takes 40 minutes. How do I cut it down without losing coverage?", https://gitshowcase.com/forum/discuss/github-actions-matrix-build-takes-40-minutes-how-do-i-cut-it-down/, accessed 2026-11-28.The relevant part of the workflow:
jobs: test: strategy: matrix: node: [18, 20, 22] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} cache: npm - run: npm ci - run: npm testThe client insists we keep the coverage, so deleting entries is a hard sell. What is the realistic way to make this faster? Should I split the jobs, reduce the matrix, cache more, or something I have not thought of? I would like to understand where the time goes before I change things.
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.
2 answers
- Anand R.Member ·
Before changing anything, look at the per job durations in the run summary. The wall time of a matrix is the slowest single entry, not the sum, as long as runners are available. If macOS or Windows is the slow one, that is where to look. Also check how long
npm citakes versusnpm test. I have seen "tests are slow" turn out to be "install is slow".