WarpBuild LogoWarpBuild

Reducing GitHub Actions Costs

By Surya Oruganti · Published · Updated

Practical guide to reducing GitHub Actions costs with triggers, cancellation, caching, right-sizing, and more

Reducing GitHub Actions Costs cover

This guide focuses on practical ways to reduce costs while improving reliability and developer UX. It's vendor-neutral and cites primary docs throughout.

Note

Cost is largely a function of billed minutes, runner SKU, artifact/storage usage, and fan-out. Understanding billing and usage is the first step: see About billing for GitHub Actions and Viewing your Actions usage.

Cost Optimizations

Run less by default (event filters)

Only run workflows when it matters.

on:
  pull_request:
    branches: ["main", "release/*"]
    paths:
      - "app/**"
      - "lib/**"
      - "package.json"
      - "!**/*.md"
      - "!**/*.png"
      - "!**/*.svg"
  push:
    branches: ["main"]
  • See workflow syntax for paths/paths-ignore: docs
  • Skip runs with commit messages or workflow inputs: skipping runs

Tip

Use separate lightweight linters for every push and run heavy integration tests only for PRs targeting main.

Run only the tests a change affects

Most PRs touch a small part of the codebase, so most tests don't need to run.

- uses: actions/checkout@v4
  with:
    fetch-depth: 0       # needed to diff against the base branch
    filter: blob:none    # keeps the full-history checkout small
# github.base_ref is only set on pull_request events
- run: npx jest --changedSince=origin/${{ github.base_ref }}

Tip

If the tool can't tell what a change affects (lockfiles, config, shared fixtures), run everything. Keep a full run on main or a nightly schedule as a backstop.

Cancel superseded work

Stop old runs when new commits arrive.

concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
  • Concurrency groups and cancellation: docs

Move heavy checks off every PR

Run slow suites on main or on a schedule. Keep PR checks fast.

on:
  pull_request:
  push:
    branches: ["main"]
  schedule:
    - cron: "17 3 * * *"   # every night at 03:17 UTC

jobs:
  e2e:
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run test:e2e
  • Scheduled workflows: docs

Send scheduled failures somewhere the team will see them.

Add timeouts to jobs

Set hard ceilings on job time.

jobs:
  test:
    timeout-minutes: 20
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test
  • Timeouts via workflow syntax: docs

Cache smartly (dependencies and Docker)

Caching cuts both time and cost.

- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
    restore-keys: npm-${{ runner.os }}-
  • Dependency caching: docs

For Docker image builds, prefer BuildKit/Buildx with the GitHub cache backend:

- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
  with:
    push: false
    cache-from: type=gha
    cache-to: type=gha,mode=max

Cut repeated setup

On short jobs, checkout and install can take longer than the tests.

- uses: actions/cache@v4
  id: npm-cache
  with:
    path: ~/.npm
    key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- if: steps.npm-cache.outputs.cache-hit != 'true'
  run: echo "::warning::npm cache miss"

Store less, keep it shorter (artifacts)

Artifacts are billed for storage and egress. Upload only what you need, compress appropriately, and reduce retention.

Example savings: A team uploading 5GB of artifacts daily with default 90-day retention stores 450GB/month. Reducing retention to 7 days cuts this to 35GB-a 92% reduction. At GitHub's storage rates ($0.008/GB/day for Actions), this saves ~$100/month.

- uses: actions/upload-artifact@v4
  with:
    name: reports
    path: reports/**
    retention-days: 7  # default is 90 days
    compression-level: 6  # balance speed vs size

Quick wins:

  • Reduce retention from 90 to 7-14 days: ~85-90% storage cost reduction

  • Compress artifacts: typical 40-60% size reduction for logs and build outputs

  • Upload only test failures, not full test runs

  • Artifacts and retention: docs

Choose cheaper runners and architectures

Linux runners are cheaper than macOS/Windows. Where possible, move tasks to Linux, and isolate platform-specific steps. Use arm64 runners for builds that are not CPU bound.

GitHub-hosted pricing multipliers (standard runners, relative to Linux x64 at $0.006/min):

  • Linux x64: 1x baseline
  • Linux arm64: ~0.83x (~17% cheaper)
  • Windows: ~1.67x
  • macOS x64: ~10.33x
  • macOS arm64 (M1): ~10.33x

Example: A workflow running 1,000 minutes/month on macOS x64 costs ~10.33x more than the same workflow on Linux. Switching non-macOS-specific tasks to Linux can save $56/month per 1,000 minutes at the listed rates, after included usage is exhausted.

Note

Billing differences and entitlements vary by plan and OS: see About billing for GitHub Actions.

Parallelize thoughtfully

Matrix builds are powerful but can explode costs. Keep fan-out intentional and throttle when needed.

strategy:
  matrix:
    node: [18, 20, 22]
  max-parallel: 2
  • Matrix usage and limits (256 jobs): docs

Balance your shards

A sharded run is only as fast as its slowest shard.

strategy:
  matrix:
    shard: [1, 2, 3, 4]
steps:
  - uses: actions/checkout@v4
  - run: npm ci
  - run: npx jest --shard=${{ matrix.shard }}/4

For example, here are the same tests split two ways:

Shard 1Shard 2Shard 3Shard 4Run finishes at
Uneven2:002:306:402:106:40
Balanced3:203:203:203:203:20

If your tool can split tests by how long they take, use that instead of splitting by file count. And if one test file keeps making the same shard slow, break it into smaller files.

Note

Balancing saves wall-clock time more than money. Each shard repeats checkout and install, so if setup is a big part of the job, fewer shards cost less.

Observe and budget

Track performance and spend so you can right-size and de-fanout with confidence.

Right-size your runners

Use data to pick the smallest runner that meets SLOs.

Example: If a build takes 20 minutes on 2-core and 12 minutes on 8-core, at GitHub's listed Linux x64 rates ($0.006/min for 2-core and $0.022/min for 8-core), you're paying about 3.67x the rate for a 1.67x speedup-net result is 2.2x more expensive for that run. Right-sizing down from 8-core to 4-core (if 4-core completes in 15 minutes) cuts cost by about 31.8% at $0.012/min for 4-core while only adding 3 minutes. This optimizes for cost but developer experience may suffer.

  • Track job duration trends in the Actions UI and compare before/after changes: usage
  • Watch CPU/memory-bound steps: run smaller/larger machine experiments and choose the knee of the curve
  • Prefer improving IO (cache, network, disk) before simply scaling CPU

Mermaid decision helper:

Tip

To test right-sizing safely, cap max-parallel, then A/B compare durations and queue times before switching your default runner.

Flaky tests quietly tax your bill

Retries and re-runs multiply minutes. Treat flakiness as a cost center.

  • Prefer “retry failed tests only” where supported (keeps cost bounded)
  • Quarantine known-flaky suites and run them on schedule, not per-PR
  • Surface failure triage early; fail fast before long e2e suites

Framework knobs (examples):

See: jest.retryTimes

# Jest
run: npx jest --maxWorkers=50%  # consider also: jest.retryTimes()
  • Re-running jobs/workflows: docs

Delete tests that don't protect anything

Tests pile up. Remove the ones that no longer catch anything.

  • Before you delete a test, check what it was meant to cover. If it covers nothing, it can go.
  • Duplicates and tests for removed code are the easiest wins.
  • Review new tests the same way you review new code.

Self-hosted runners can save costs

Self-hosting can reduce per-minute costs (e.g., spot/preemptible instances) and unlock bespoke hardware and caching. It also introduces infra, security, and maintenance overhead.

Optimizing Self-Hosted GitHub Actions Runner Costs

Compared to GitHub hosted runners, self-hosted runners have the potential to save upto 90% on costs.

Cost-first execution flowchart


How WarpBuild can help

This guide is vendor-neutral; if you want managed building blocks that implement many of the above:


FAQ

Why did shorter workflows not reduce my invoice?

A shorter workflow may still use the same total runner minutes if more jobs run in parallel. Storage charges also accumulate separately, and compute savings within your included allowance may not reduce a cash payment. Compare billed usage and charges, not just completion time.

Can path filters leave a required check pending?

Yes, skipping a whole workflow with path filters can leave its required check pending and block merging. Keep the required workflow running and conditionally select expensive work inside it. For repositories with multiple packages, the monorepo CI guide explains affected-only execution.

Should I cancel an older deployment when a newer commit arrives?

Only if the deployment process can be interrupted safely. Cancellation can stop a job after it has already changed an external system, so use separate concurrency policies for replaceable test runs and state-changing deployments.

How should I compare runner providers when GitHub includes compute usage?

Compare the additional monthly amount you would actually pay after included usage, credits, and discounts. For a WarpBuild trial, measure representative job durations and include relevant storage and operation charges from the pricing breakdown, rather than comparing per-minute rates alone.

On this page