Skip to content

Add cigen replay: estimate skipping from git history - #59

Open
ndbroadbent wants to merge 1 commit into
mainfrom
tools/replay
Open

ndbroadbent wants to merge 1 commit into
mainfrom
tools/replay

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Adds cigen replay, which estimates how many job runs cigen would have skipped over a project's git history, without running any CI.

cigen replay --last 100 --workflow ci
cigen replay v1.2.0..main --format json
cigen replay --last 200 --config ../my-cigen.yml   # a project whose history has no cigen config

How it works

  • It walks first-parent commits (<from>..<to> or --last N), checking each one out in a temporary worktree that it removes afterwards.
  • It hashes every job with hashing::hash_job (from Add cigen explain <job>: what a job's hash covers #14), the same function cigen hash --job and cigen explain use. Modules, derived inputs and the hashes of the jobs a job needs are all included, as they are in CI.
  • A run counts as skipped when the same job and hash ran on an earlier commit and its marker hasn't gone 7 days unused, measured by commit date. A hit refreshes the marker, and --no-expiry turns expiry off.
  • git runs through cigen::git::command, so a checkout owned by another user works.
  • Options:
    • --workflow picks the workflows to replay;
    • --durations estimates the minutes saved;
    • --format json prints the full report and the model behind it.

What the estimate assumes

The output says this, and so does the new Estimate skipping page:

  • every run passed;
  • pushes to one branch only, so pull requests aren't modelled;
  • workflow triggers aren't modelled;
  • a matrix job counts once per commit.

Tests

  • tests/replay.rs builds histories with set commit dates and checks exact counts. A lockfile change must run, a revert skips, a definition change runs, a marker expires and a hit refreshes it. It also covers ranges, --config, --workflow, durations and leftover worktrees.
  • tests/replay_needs.rs: a job reruns when a job it needs changed. I checked that it fails with the needed jobs' hashes left out of the digest.

Rebase notes

This was written before #14 and modules landed. Rebased onto main:

  • hash_job takes the new modules_digest and matrix_entry arguments as None, so it uses this cigen's modules digest and no matrix entry.
  • Configs with modules now load directly. The earlier case-study runs needed a module-free copy of the config.
  • Docs: cli.md (next to cigen explain), the overview, the roadmap and the new replay page. STATUS is updated.

Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

cigen replay walks a range of first-parent commits (<from>..<to> or --last N),
checks each out in a temporary worktree, hashes every job with
hashing::hash_job (so it matches CI), and counts a run as skipped when the same
job and hash ran on an earlier commit and its marker hasn't gone 7 days unused
by commit date (a hit refreshes it; --no-expiry turns that off).

It is an estimate and says so: every run is assumed to pass, and workflow
triggers, pull requests and matrix combinations aren't modelled. --config
applies one config to every commit, for projects whose history has none (the
case-study mode); otherwise commits with no config, or one this cigen can't
load, are listed and left out. --workflow picks workflows, --durations
estimates minutes saved, and --format json gives the full report with its
model.

tests/replay.rs builds histories with set commit dates and checks exact counts,
including a lockfile change that must run. Docs: a new Estimate skipping page,
the CLI page, overview and roadmap. STATUS updated.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant