Skip to main content
Back to Blog
Automation TutorialsCI and Test Infrastructure · Part 1

Place CI Tests by Feedback Time, Cost and Solo Catches

The test pyramid says how many tests to write, not which CI stage should run them. Measure each layer's job time, billed minutes and the defects it caught alone, then move layers between pull request, merge queue and nightly in one GitHub Actions workflow.

Shashank Rawlani

Engineering Leader | Builder | Problem Solver | AI Engineer

Published Nov 13, 202621 min read
View AI-ready Markdown
Dark technical illustration: three dashed columns side by side, each holding stacked rounded pills of different lengths. Four orange tracks dotted with orange markers enter from the left edge; three end at green ringed nodes beside short pills in the first column, and the fourth passes a dashed empty outline of a long pill to end at a bright pill in the middle column. A dashed grey curve carries the long outline to a dim long pill in the third column, and a green curve links a dashed outline in the third column back to the bright pill in the middle.
Quick answer: Decide where each test layer runs from three measured numbers, not from the pyramid diagram: its wall-clock time per job, its billed minutes per month at that stage, and how many real defects it caught that no faster layer in the same run also caught. Pull requests get the fast layers that catch defects alone, because the slowest required job sets every author's wait. The merge queue gets checks that need the merged result or a heavier environment. Nightly gets what catches little alone and costs a lot. In GitHub Actions, put all stages in one workflow and switch layers with job-level if conditions, never with path filters on a required check.

A pull request in a typical web service waits about 19 minutes for green, because the full browser suite runs on every push. Over 20 days that suite used 3,216 of the repository's 4,579 billed CI minutes, about 70% of the bill. It caught 12 real defects. Unit or contract tests in the same run caught 8 of them first, minutes earlier. Meanwhile five database migration defects reached main, because the integration suite only ran at night, and each red nightly run left three merges to search through.

Those numbers come from the lab later in this article, for a pipeline that follows the test pyramid faithfully. The pyramid says how many tests of each kind to write. It says nothing about which CI stage should run them, and that is where the time and money go.

This is part 1 of an eight-part series on CI test infrastructure, written for GitHub Actions with notes where other systems change the answer. The series moves from where tests run, to test data that collides between parallel jobs, failures that only happen in CI, caches that hide dependency drift, sizing parallelism to shared dependencies, artifacts that explain a failure, OIDC and least-privilege tokens, and finally measuring the pipeline's own reliability. This part covers placement only: which layer runs at which stage, decided by measurement.

Versions checked on 2026-11-09: actions/checkout v7.0.1, actions/setup-node v7.1.0, Playwright 1.65.0 (released 2026-11-05), pytest 9.2.0. The GitHub-hosted Linux 2-core x64 runner rate used for cost was $0.006 per minute on that date. The lab ran on Node.js 26.12.1 on macOS arm64. It reads and writes local files only and opens no network connection.

What each stage charges for the same failure

The same failing test costs a different amount depending on when it fails. Four stages matter, and each has its own price.

Pull request. The author is waiting, and the price is paid on every push, not once per change. Jobs in a workflow run in parallel by default, so the author's feedback time is the slowest required job, while the bill is the sum of all of them. A 19-minute job beside two one-minute jobs makes every push a 19-minute wait. For pull_request, GITHUB_SHA is the last merge commit on the pull request's merge branch, so the tests already see the change merged onto its base, but only as the base was at that moment.

Merge queue. GitHub's merge queue builds a temporary branch that holds the latest base branch, the pull requests ahead in the queue, and this one, then runs the required checks against that combination. It catches what a pull request run cannot: two changes that pass alone and break together. The price is paid once per queued change, plus rebuilds when an entry ahead fails, and a slow check here throttles everybody's merges, not one author's. GitLab's equivalent is merge trains, a Premium and Ultimate feature; its plain merged results pipeline tests one merge request against the target and does not account for others merging at the same time.

Push to main. Without a queue, a post-merge run on main is where combination failures surface. It blocks no one, and that is its cost: main is already red when it reports, so treat that red as an incident, not a nightly finding.

Nightly. A schedule run is the cheapest per change, because one run covers every merge since the last one. It also has the worst diagnosis. A nightly failure points at a range of merges, so the real price is the bisect, plus the hours the defect sat on main. GitHub runs scheduled workflows only on the default branch, on its latest commit, and its docs warn that runs can be delayed at high load, especially at the start of every hour, and that some queued jobs may be dropped.

Three numbers to record for every layer

Treat each layer as one CI job, so that a layer's time and its bill are the same thing. Then record, per stage:

  • Job wall-clock time, as p50 and p90. The p90 is what an unlucky author waits.
  • Billed minutes. GitHub rounds the minutes and partial minutes of each job up to the nearest whole minute, re-runs included. A 10-second lint job bills a full minute, so splitting one layer into ten tiny jobs multiplies its bill by ten without changing its runtime. On public repositories, standard hosted runners are free, but runner time and author waiting are not.
  • Held catches, and catches made alone. A held catch is a test failure that fails again when the job is re-run, which separates it from a flaky failure. A catch made alone is a held catch where no faster layer in the same run also held a failure. That second count is the layer's real contribution at that stage: the defects you would lose if you moved it.

The failure data is already in the JUnit XML your test runner writes. Two runner details decide whether you read it correctly. Playwright's JUnit reporter, at v1.65.0, sets the root <testsuites time> to the whole run's duration and each <testsuite time> to the sum of its tests' durations, so adding up suite times overcounts whenever workers ran in parallel. And pytest names its suite pytest unless junit_suite_name is set, so one file per job, named by layer, is the dependable key. For the time a job spent waiting for a runner, which JUnit cannot see, the REST endpoint that lists a run's jobs returns created_at, started_at and completed_at for each one.

If you already deduplicate flaky failures across runs, the guide to finding flaky tests across JUnit XML runs covers that side; here a flake is only something to exclude from the catch count.

A lab with a known answer

A placement report is only worth trusting if you have seen it recover a known answer. The generator below writes 20 days of CI history for a service merging three changes a day, as one JUnit file per job. The current placement runs unit, contract and the full 40-test browser suite on every pull request push, re-runs unit and contract in the merge queue, and leaves integration and the full browser suite to a nightly run. It plants defects of five kinds, each caught by a different layer: logic bugs (unit, sometimes also a browser test), contract breaks (contract, sometimes browser), UI-only bugs (only specific browser tests), migration bugs (only integration), and one queue-only conflict between two changes. Browser tests also flake at random and pass on re-run.

// Writes a synthetic CI history as JUnit XML, with planted defects, so
// layer-report.mjs can be checked against a known answer. Local files only.
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";

const OUT = process.argv[2] ?? "history";
let seed = Number(process.env.SEED ?? 7);
const rand = () => {
  seed = (seed + 0x6d2b79f5) | 0;
  let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
  t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
  return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
const around = (mean, spread) => Math.round(mean + (rand() * 2 - 1) * spread);

const DURATION = { unit: [62, 10], contract: [88, 12], integration: [410, 45], "browser-full": [1130, 110] };
const STAGES = {
  pr: ["unit", "contract", "browser-full"],
  queue: ["unit", "contract"],
  nightly: ["integration", "browser-full"],
};

const UI_ONLY = ["checkout.spec.ts › coupon field keeps focus", "nav.spec.ts › mobile menu opens", "search.spec.ts › empty query shows hint"];
const LOGIC_E2E = "checkout.spec.ts › totals include tax";
const CONTRACT_E2E = "orders.spec.ts › order history lists last order";
const BROWSER = [...UI_ONLY, LOGIC_E2E, CONTRACT_E2E];
for (let i = BROWSER.length; i < 40; i += 1) BROWSER.push(`catalog.spec.ts › listing case ${i}`);

const caseNames = (layer) =>
  layer === "browser-full" ? BROWSER : Array.from({ length: 25 }, (_, i) => `${layer} case ${i}`);

// One file per job. The root time is the job's wall clock, as Playwright's
// JUnit reporter writes it. Playwright puts the spec file in classname and
// the title path in name; the other layers use the layer as classname.
function jobXml(layer, failing, extra) {
  const cases = caseNames(layer)
    .map((id) => {
      const [file, title] = id.includes(" › ") ? id.split(" › ") : [layer, id];
      const open = `<testcase classname="${file}" name="${title}"`;
      return failing.has(id) ? `${open}><failure message="assertion failed"/></testcase>` : `${open}/>`;
    })
    .join("");
  const [mean, spread] = DURATION[layer];
  const n = caseNames(layer).length;
  return `<testsuites tests="${n}" failures="${failing.size}" time="${around(mean, spread)}"><testsuite name="${layer}" tests="${n}" failures="${failing.size}">${extra}${cases}</testsuite></testsuites>\n`;
}

function writeRun(stage, key, attempt, layers, failuresFor, extra = "") {
  for (const l of layers) writeFileSync(join(OUT, stage, `${key}.a${attempt}.${l}.xml`), jobXml(l, failuresFor(l), extra));
}

// One run: attempt 1, then a re-run of only the failed jobs. A defect fails
// again on the re-run; a flake does not.
function run(stage, key, defects, extra) {
  const flakes = new Map();
  const real = (layer) => new Set(defects.filter((d) => d.layer === layer).map((d) => d.test));
  const first = (layer) => {
    const set = real(layer);
    if (layer === "browser-full") {
      for (const t of BROWSER) if (rand() < 0.002) { set.add(t); flakes.set(t, true); }
    }
    return set;
  };
  const a1 = Object.fromEntries(STAGES[stage].map((l) => [l, first(l)]));
  writeRun(stage, key, 1, STAGES[stage], (l) => a1[l], extra);
  const failed = STAGES[stage].filter((l) => a1[l].size);
  if (failed.length) writeRun(stage, key, 2, failed, real, extra);
  return failed.some((l) => real(l).size);
}

rmSync(OUT, { recursive: true, force: true });
for (const s of Object.keys(STAGES)) mkdirSync(join(OUT, s), { recursive: true });

const planted = { logic: 0, contract: 0, ui: 0, migration: 0, conflict: 0 };
const pendingMigration = [];
let change = 0;
for (let day = 1; day <= 20; day += 1) {
  const merged = [];
  for (let k = 0; k < 3; k += 1) {
    change += 1;
    const id = `c${String(change).padStart(3, "0")}`;
    const roll = rand();
    const defects = [];
    if (roll < 0.12) {
      planted.logic += 1;
      defects.push({ layer: "unit", test: "unit case 7" });
      if (rand() < 0.6) defects.push({ layer: "browser-full", test: LOGIC_E2E });
    } else if (roll < 0.19) {
      planted.contract += 1;
      defects.push({ layer: "contract", test: "contract case 3" });
      if (rand() < 0.5) defects.push({ layer: "browser-full", test: CONTRACT_E2E });
    } else if (roll < 0.25) {
      planted.ui += 1;
      defects.push({ layer: "browser-full", test: UI_ONLY[Math.floor(rand() * UI_ONLY.length)] });
    } else if (roll < 0.30) {
      planted.migration += 1;
      pendingMigration.push(id);
    }
    let push = 1;
    if (defects.length) { run("pr", `${id}-p${push}`, defects); push += 1; }
    const extraPushes = Math.floor(rand() * 3);
    for (let p = 0; p <= extraPushes; p += 1) { run("pr", `${id}-p${push}`, []); push += 1; }
    const conflict = rand() < 0.035;
    if (conflict) {
      planted.conflict += 1;
      run("queue", `${id}-q1`, [{ layer: "unit", test: "unit case 12" }]);
      run("pr", `${id}-p${push}`, []);
      run("queue", `${id}-q2`, []);
    } else {
      run("queue", `${id}-q1`, []);
    }
    merged.push(id);
  }
  const broken = pendingMigration.splice(0);
  const defects = broken.map(() => ({ layer: "integration", test: "integration case 4" }));
  run("nightly", `d${String(day).padStart(2, "0")}`, defects,
    `<properties><property name="changes" value="${merged.join(",")}"/></properties>`);
}
console.log("planted", JSON.stringify(planted), "changes", change);

The report reads that layout and computes the three numbers per stage and layer. Point it at your own history by saving each job's JUnit file under the same naming scheme: stage directory, then run key, attempt and layer in the file name.

// layer-report.mjs: which layer catches what, at what price, in which stage.
// Input: <dir>/<stage>/<run>.a<attempt>.<layer>.xml, one JUnit file per job.
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";

const dir = process.argv[2] ?? "history";
const RATE = 0.006; // USD per billed minute, GitHub-hosted Linux 2-core x64
const attr = (tag, name) => tag?.match(new RegExp(`\\b${name}="([^"]*)"`))?.[1];

function parseJob(xml) {
  const failed = [];
  for (const c of xml.matchAll(/<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g)) {
    // <flakyFailure> (Playwright retries) does not match: it passed in the end.
    if (/<(failure|error)\b/.test(c[2] ?? "")) failed.push(`${attr(c[1], "classname")} › ${attr(c[1], "name")}`);
  }
  // Root time is wall clock in Playwright's report. Summing <testsuite time>
  // overcounts whenever workers ran in parallel, so use it only as a fallback.
  let time = Number(attr(xml.match(/<testsuites\b[^>]*>/)?.[0], "time"));
  if (!time) time = [...xml.matchAll(/<testsuite\b[^>]*>/g)].reduce((t, m) => t + Number(attr(m[0], "time") ?? 0), 0);
  const changes = attr(xml.match(/<property name="changes"[^>]*>/)?.[0], "value");
  return { time, failed, changes: changes ? changes.split(",") : [] };
}

const pct = (xs, p) => [...xs].sort((a, b) => a - b)[Math.min(xs.length - 1, Math.floor(p * xs.length))];
const stats = {};
const soloTests = new Set();

for (const stage of readdirSync(dir)) {
  const runs = {};
  for (const f of readdirSync(join(dir, stage))) {
    const [, key, attempt, layer] = f.match(/^(.+)\.a(\d+)\.(.+)\.xml$/);
    ((runs[key] ??= {})[attempt] ??= {})[layer] = parseJob(readFileSync(join(dir, stage, f), "utf8"));
  }
  for (const { 1: first, 2: rerun = {} } of Object.values(runs)) {
    // A failure holds when the re-run of the same job failed the same test.
    const held = {};
    for (const [layer, job] of Object.entries(first)) {
      held[layer] = job.failed.filter((t) => rerun[layer]?.failed.includes(t));
    }
    for (const [layer, job] of Object.entries(first)) {
      const s = (stats[`${stage}|${layer}`] ??= { stage, layer, times: [], billed: 0, held: 0, alone: 0, flaky: 0, range: [] });
      s.times.push(job.time);
      // Billing rounds each job up to a whole minute, re-runs included.
      s.billed += Math.ceil(job.time / 60) + (rerun[layer] ? Math.ceil(rerun[layer].time / 60) : 0);
      if (job.failed.length && !held[layer].length) s.flaky += 1;
      if (!held[layer].length) continue;
      s.held += 1;
      if (job.changes.length) s.range.push(job.changes.length);
      const faster = Object.keys(first).filter((l) => first[l].time < job.time);
      if (faster.every((l) => !held[l].length)) {
        s.alone += 1;
        if (layer.startsWith("browser")) held[layer].forEach((t) => soloTests.add(t));
      }
    }
  }
}

const rows = Object.values(stats).sort((a, b) => a.stage.localeCompare(b.stage) || pct(a.times, 0.5) - pct(b.times, 0.5));
console.log("stage    layer          runs   p50    p90  billed-min    usd  held  alone  flaky  merges/catch");
for (const s of rows) {
  const range = s.range.length ? (s.range.reduce((a, b) => a + b, 0) / s.range.length).toFixed(1) : "-";
  console.log(
    s.stage.padEnd(8), s.layer.padEnd(14), String(s.times.length).padStart(4),
    `${pct(s.times, 0.5)}s`.padStart(6), `${pct(s.times, 0.9)}s`.padStart(6),
    String(s.billed).padStart(11), (s.billed * RATE).toFixed(2).padStart(6),
    String(s.held).padStart(5), String(s.alone).padStart(6), String(s.flaky).padStart(6), range.padStart(13),
  );
}
writeFileSync("pr-browser.txt", [...soloTests].sort().join("\n") + "\n");
console.log(`\nbrowser tests that caught a defect alone: ${soloTests.size}, written to pr-browser.txt`);
node gen-history.mjs history
node layer-report.mjs history
cat pr-browser.txt
stage    layer          runs   p50    p90  billed-min    usd  held  alone  flaky  merges/catch
nightly  integration      20   420s   442s         184   1.10     5      5      0           3.0
nightly  browser-full     20  1151s  1231s         426   2.56     0      0      2             -
pr       unit            142    61s    70s         239   1.43    13     13      0             -
pr       contract        142    87s    96s         294   1.76     5      5      0             -
pr       browser-full    142  1113s  1221s        3216  19.30    12      4     13             -
queue    unit             61    64s    70s          98   0.59     1      1      0             -
queue    contract         61    87s    97s         122   0.73     0      0      0             -

browser tests that caught a defect alone: 3, written to pr-browser.txt
checkout.spec.ts › coupon field keeps focus
nav.spec.ts › mobile menu opens
search.spec.ts › empty query shows hint

Before reading anything into the table, check it against what was planted. The generator reported 13 logic defects, 5 contract breaks, 4 UI-only bugs, 5 migration bugs and 1 conflict. The pull request unit row holds 13 catches, contract holds 5, the browser suite caught 4 defects alone, nightly integration caught 5, and the queue's unit job caught the conflict. Every planted defect is accounted for, once, in the layer that could see it first.

What the report says to move

The browser suite on pull requests held 12 catches, but 8 of them were the same defects unit or contract had already failed on in that run. Only 4 were its own, and all 4 came from the three tests listed in pr-browser.txt. The other 37 tests caught nothing alone in 142 runs, while the job consumed 3,216 billed minutes and set an 18.5-minute p50 wait. It also produced 13 flaky failures that each cost a re-run. Counted naively, failures and flakes together, it would have looked like the most productive layer in the pipeline, with 25 red runs.

Integration at night caught 5 defects alone, every one a migration bug, and each catch left 3 merges to search. That is the case for promotion: a layer that catches things nothing else catches, run where its catches are most expensive. At the measured p50 of 420 seconds, it bills 7 or 8 minutes per run, so 61 queue runs come to roughly 430 to 490 billed minutes, a seventh of what the browser suite cost on pull requests.

Contract in the queue caught nothing in 61 runs, for 122 minutes in total. A zero only forces a decision when it sits next to a large bill.

The placement that follows: unit, contract and the three browser tests that earned it run on pull requests and in the queue; integration moves from nightly to the queue; the full browser suite stays nightly as the backstop for UI bugs the three tests will not see.

Switching layers by event in one workflow

Merge queue checks and pull request checks are configured together, in the same branch protection rule or ruleset, so one list of required checks gates both. The working pattern is one workflow that triggers on every stage's event, with job-level conditions deciding what actually runs:

name: tests
on:
  pull_request:
  merge_group:
    types: [checks_requested]
  schedule:
    - cron: "41 1 * * *"   # UTC, off the top of the hour
  workflow_dispatch:

jobs:
  unit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npm run test:unit

  contract:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npm run test:contract

  integration:
    # Required check. On pull_request the job is skipped, and a skipped job
    # reports Success. In the merge queue and at night it runs for real.
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npm run test:integration

  browser:
    runs-on: ubuntu-latest
    env:
      PLAYWRIGHT_JUNIT_OUTPUT_NAME: junit-browser.xml
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - name: Browser tests that earned a place before merge
        if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
        run: npx playwright test --reporter=junit --test-list ci/pr-browser.txt
      - name: Full browser suite
        if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
        run: npx playwright test --reporter=junit

Two documented behaviours make this work. A job skipped by its if condition reports its status as Success and does not prevent a pull request from merging, even when it is a required check, so integration can be required everywhere and only run in the queue and at night. And GitHub's docs state plainly that a required check run by Actions must also trigger on merge_group, or the check is never reported for the queued change and the merge fails.

The pull request subset comes from the report itself. Playwright 1.56 added --test-list, which runs only the tests named in a file, one file › test title per line. Playwright's JUnit reporter writes the spec file into classname and the title path, joined by ›, into name, which is why the report joins the two. Compare a line or two with what npx playwright test --list prints, to confirm the paths match your testDir, then commit the file as ci/pr-browser.txt and regenerate it when the data changes. Tags with --grep @smoke do the same job if you prefer to mark tests in source, at the price of someone remembering to re-tag.

The version that looks equivalent and is not:

name: integration
on:
  pull_request:
    paths:
      - "db/migrations/**"

jobs:
  integration:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: npm ci
      - run: npm run test:integration

If a workflow is skipped by path filtering, branch filtering or a commit message, its checks stay Pending, and a pull request that requires them is blocked from merging. Make integration from this file required and every pull request that does not touch a migration waits forever. Leave it optional and it gates nothing. The skip has to happen inside the run, at job level, where it reports Success.

Playwright's --only-changed [ref], added in 1.46, is the other tempting shortcut: run only test files changed between HEAD and the ref. It needs the ref in the clone, and actions/checkout fetches a single commit unless you set fetch-depth: 0. It also sees changed test files, while a browser test exercises the server over HTTP, so a change to the server alone selects nothing. Use it for fast local loops, not as the pull request gate.

When to overrule the report

A count of solo catches measures the defects you had, not the ones you will have. Three cases justify overruling it.

Severity the window did not sample. A payment or authentication journey that caught nothing in 20 days may still belong on pull requests, because one escape costs more than a year of its minutes. Keep it there deliberately, and write down that the reason is severity, so the next review does not mistake it for an oversight.

Too few runs. Twenty nightly runs that each cover three merges amount to 60 changes. A layer that catches one defect in a hundred changes will show zero most months. Extend the window before demoting anything that is cheap.

A demotion you never re-check. When one of the 37 demoted browser tests catches something, the defect has already merged and the bisect spans a night's merges. Record each nightly-only catch as an escape, and when a nightly test catches the same kind of defect twice, promote it back. The report produces the list, so promotion costs one regenerated file.

Placements that break without an error

A required check that never appears. The cause is a workflow-level paths, branches or skip-commit filter on a required workflow. To tell it apart from a slow runner, open the pull request's checks: a filtered workflow has no run for that commit at all, while a job skipped by if shows up as skipped.

Queue entries that time out or drop. The cause is a required workflow without merge_group in its triggers. Run gh run list --event merge_group --workflow tests; an empty list while pull requests are queued confirms it.

A nightly suite that stopped running. Scheduled workflows run only from the workflow file on the default branch, can be delayed or dropped at the top of the hour, and in a public repository are disabled automatically after 60 days with no repository activity. gh run list --event schedule shows when the last scheduled run happened. A gap there means your backstop was off, and every demotion you made relied on it.

Layers chained with needs. When a job fails, every job that needs it is skipped. Chaining browser after unit makes the pull request wait for the sum of both, not the slower one, and it hides overlap: the browser suite never runs on commits that unit already failed, so the report cannot show which of its catches were redundant. Chain only when the later job truly consumes the earlier one's output.

A layer that looks productive because it is flaky. Count only held failures. In the lab, counting every red browser run would have credited the suite with 25 catches instead of 4 made alone. The guide to gating on flaky Playwright tests covers keeping that evidence without letting it drive the gate.

Apply this now

  1. Make each layer its own job, writing its own JUnit file, named by stage, run, attempt and layer. If you need richer failure messages in those files, the guide to useful JUnit failure reports covers what to put in them.
  2. Collect two to four weeks of those files and run the report. Capture the table as it stands today, before you move anything, so the next review has a baseline.
  3. Find the costliest layer on pull requests with the fewest catches made alone. Move it to the merge queue or nightly, keeping its solo-catch tests on pull requests through --test-list.
  4. Find the cheapest layer with solo catches at night and promote it to the queue, triggered by merge_group and skipped on pull_request by a job-level if.
  5. Write down the expected change in p50 pull request wait and in billed minutes, and compare it with the next report.

Questions about placing tests by stage

Is it wasteful to run unit tests on the pull request and again in the queue?

Rarely. The queue run tests a different commit: the base as it is now plus the changes ahead in the queue. In the lab, the queue's unit job was the only thing that caught the conflict between two changes, for 98 billed minutes across 61 runs. Cheap layers that see a new commit are worth repeating; expensive ones need a reason.

Can a skipped required job let a broken change merge?

Yes, if the condition skips it in the queue as well. A skip reports Success everywhere. Test the condition against every event the workflow triggers on, and keep the expression in the form "not pull_request" rather than listing every event where it should skip.

How long a history do you need before moving a layer?

Long enough that the layer's expected solo catches are well above zero. If a layer has caught something about once a month historically, two weeks of zeros says nothing. Use the merge rate: a window should cover several hundred changes before you demote a cheap layer, and fewer only when the bill is large.

Primary references

CI and Test Infrastructure

Get part 2: Eliminate CI Test Data Collisions Across Jobs, Shards and Re-runs

It is live now: read part 2. The form below subscribes you to The Automation Brief, the site newsletter.

No spam, no sending cadence promised. Unsubscribe any time.