Full Byte Developer.

Save GitHub Actions minutes with three workflow fixes

Save GitHub Actions minutes: cancel replaced runs, skip docs-only pushes, cap jobs below the 6-hour default.

Published here , updated · 3 sources

Five pushes on one pull request can mean five full CI runs when only the last result matters. Private GitHub Actions minutes still bill for cancelled work if you stop too late. Cancel replaced PR runs, skip docs-only pushes, and set timeout-minutes under the six-hour default [1][2][3].

Fix 1: Cancel the run you just replaced

Put a concurrency block at workflow level so only one run in the group is active. On pull requests, cancel the in-progress twin when a newer push arrives. On the default branch, leave in-progress deploys alone [2].

yaml
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

github.workflow keeps this workflow from cancelling a differently named workflow that happens to share a branch ref [2]. Without that prefix, two workflows on refs/pull/12/merge can knock each other out.

concurrency group push 1 to PR run A in progress push 2 (same ref) run B queued cancel-in-progress A cancelled B runs alone group: ${{ github.workflow }}-${{ github.ref }} PR: cancel replaces; main deploys: cancel-in-progress false

One shared concurrency group per workflow plus ref; on pull requests, the newer push cancels the older run.

Fix 2: Skip CI when only docs changed

If Markdown edits never affect the build artifact your required check validates, ignore those paths on the pull_request trigger [1]:

yaml
on:
  pull_request:
    paths-ignore:
      - '**.md'
      - 'docs/**'

Trap: a required check that never runs stays Pending, and branch protection will not let the PR merge [1]. Either keep a tiny required workflow that always runs, or do not mark the skipped workflow as required. Docs-only ignores belong on optional lint or preview jobs more often than on the one gate that allows merge.

Fix 3: Cap every job under six hours

Unset jobs inherit a 360-minute timeout [1]. A hung integration test can burn a full billable window. Set a ceiling above your slowest healthy run:

yaml
jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v4

Find workflows that never mention a timeout at all:

bash
grep -L "timeout-minutes" .github/workflows/*.y*ml

On this website repo that command printed:

text
indexnow.yml

Open each listed file and set a per-job ceiling. grep -L only catches files with zero matches, so a workflow that caps one job and forgets another still needs a manual read.

Money on the napkin

GitHub's Actions billing docs price a standard Linux runner at $0.006 per minute for private repositories [3]. Public repos on standard GitHub-hosted runners do not burn that meter the same way; the cost there is queue time and feedback lag.

Example for a private repo: 20 PRs a week, four replaced runs each, 10-minute suite.

text
20 * 4 * 10 = 800 minutes/week
800 * 4 weeks ~= 3200 minutes/month
3200 * 0.006 ~= $19.20/month

One uncapped hung job at 360 minutes is $2.16 by itself. Capped at 15 minutes it is $0.09. Concurrency does not remove the need for timeouts; it only stops you paying for obsolete PR heads.

Where teams get this wrong

Cancelling deploys on main with cancel-in-progress: true and no event guard. A second push then kills a half-finished production job.

Using one global concurrency group string across every workflow. Unrelated jobs serialize or cancel each other [2].

paths-ignore on the only required check, then wondering why green merges never appear.

Setting timeout-minutes on the workflow when you meant the job (or the reverse). Those two scopes are not the same; prefer an explicit job-level ceiling you can read next to runs-on [1].

Rollout order that does not surprise night shifts

  1. Add timeout-minutes everywhere. Lowest risk.
  2. Add concurrency with PR-only cancel.
  3. Add paths-ignore only on non-required workflows, or after branch protection is updated.

Watch the Actions bill and the "cancelled" run count for a week. If cancelled runs never appear, the concurrency group string is probably unique per run when you meant it shared per PR.

Prove concurrency locally before you trust billing

You cannot fully simulate GitHub's concurrency manager on a laptop, but you can validate the YAML and the group expression. Push a throwaway branch, open a PR, push twice within a minute, and confirm the first run flips to cancelled while the second stays yellow then green [2]. If both runs finish, the group string is not shared the way you think (often a typo in github.workflow vs a hard-coded name).

Also watch deploy workflows on main. Trigger two harmless no-op deploys only in a non-production environment first. With cancel-in-progress gated to pull_request, both main runs should complete. If the second cancels the first, the expression is wrong.

Paths-ignore versus paths

paths and paths-ignore are easy to invert under stress [1]. Prefer one style per workflow. A workflow that lists both can become hard to reason about when a file matches neither mental model. For docs-only skips, paths-ignore on Markdown is enough. For "only run when Go files change", use paths with **/*.go instead of ignoring everything else.

When a monorepo has packages A and B, put package filters in separate workflows or use path filters so a docs edit in A does not rebuild B. That is the same minute-saving idea at package scale.

Matrix jobs and parallel waste

A strategy.matrix with four OS values times three Node versions is twelve jobs. Each one bills its own minutes on private runners [3]. Concurrency cancel still helps when the PR head moves, but it cancels the whole matrix group only if your group string is shared across those jobs the way you intend. If every matrix cell gets a unique group (for example by baking matrix.os into the group key), you can still burn twelve obsolete cells on every push.

Prefer a smaller default matrix on pull requests (one Linux, one Node) and expand to the full grid on push to main or on a nightly schedule. That pattern keeps feedback fast on PRs and keeps the expensive grid for the branch that ships.

Billing footnotes worth reading once

Minute multipliers differ by OS and larger runners [3]. The $0.006 Linux figure is the common private-repo baseline, not a universal constant. macOS and larger machines cost more per minute, so a hung job without timeout-minutes hurts harder there. Free allowances and included minutes for public repositories change over time; read the current billing page when you quote a dollar number in a budget meeting [3].

For a Python type check that fails CI only on new errors, see ty vs mypy, and how to switch without fixing old errors. Before you merge a new workflow that spends those minutes, run Check GitHub Actions before merging workflows. For the single-line job ceiling pattern alone, see one line caps a hung GitHub Actions job.

Send this to the friend who pushes five times before breakfast then wonders where Actions minutes went.

Dark isometric CI floor with teal job cubes on a pipe, orange cancel wedges, a docs packet on a bypass rail, and a time cap ring closing over a long job, with no typography or logos.
Cancel replaced runs, skip docs-only pushes, and cap jobs so they cannot run for hours.

Keep this guide

By Full Byte Developer

Filed under Dev tools

Questions about this guide

Why not skip CI on required checks?

A skipped workflow's checks stay Pending, and a PR that requires them is blocked from merging.

What is the default timeout for a job?

360 minutes (6 hours). One hung job bills that long if you do not set a cap.

Should cancel-in-progress run on main?

Usually no for deploys. Cancel replaced PR test runs; keep production deploys running to completion.

Sources

Next in this stack