Skip to content
GitShowcase Forum

GitHub Actions matrix build takes 40 minutes. How do I cut it down without losing coverage?

Asked by Fitz O. · CI/CD and GitHub Actions2 repliesupdated

Short answer

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.

Written by Fitz O. ·
CiteGitShowcase 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.
  1. Member ·

    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 test
    

    The 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.

    1
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. 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 ci takes versus npm test. I have seen "tests are slow" turn out to be "install is slow".

  2. Fitz O.Member ·

    @Anand R. good point, I had not looked at install versus test. Install turns out to be a large part of the Windows entry, so the cache fix should help there first.

GitShowcase Forum. Questions and answers on shipping developer projects: dev tools, APIs, infrastructure and portfolios.