diff --git a/docs/src/content/case-studies/ripgrep.md b/docs/src/content/case-studies/ripgrep.md new file mode 100644 index 0000000..39a41b7 --- /dev/null +++ b/docs/src/content/case-studies/ripgrep.md @@ -0,0 +1,404 @@ +--- +title: ripgrep +description: ripgrep's CI workflow, a Rust workspace with an 18-entry matrix, as one cigen config, and an estimate from its last 100 commits of how many job runs cigen would have skipped. +project: BurntSushi/ripgrep +repository: https://github.com/BurntSushi/ripgrep +commit: 3e85c6c148fdce38a99ceeb9d2780dc7b03b4a4f +studied: 2026-12-04 +draft: true +--- + + + +ripgrep is a command-line search tool written in Rust: a workspace of nine library crates plus the `rg` binary in +`crates/core`, and a separate fuzzing workspace. Its main branch moves slowly and in bursts: 100 first-parent commits between 29 July and +24 November 2026, 78 of them in November. Its CI is one workflow, and its `test` job runs an 18-entry matrix of +toolchains and cross-compilation targets. We converted that workflow to a cigen config without changing ripgrep, then +replayed its last 100 commits to estimate what cigen would have skipped. + +**The estimate: 83 of 600 job runs skipped (13.8%).** It's an estimate from git history, not a measurement of real +CI, and the method and its limits are below. It's much lower than [Bootstrap's 35%](/case-studies/bootstrap/), and the +reason is the useful part: most of ripgrep's commits change code that every job builds. + +## The project's CI + +ripgrep has three workflow files. `ci.yml` runs on every push to `master`, on every pull request and nightly; the +other two publish releases on a tag or by hand, so they stay as they are. + +| Job | What it does | +| ------------------------- | ----------------------------------------------------------------------------------------------------- | +| test | Builds and tests the workspace in 18 matrix entries: 4 toolchains, 10 cross targets, macOS, 3 Windows | +| wasm | Builds for `wasm32-wasip1` | +| rustfmt | `cargo fmt --all --check` | +| docs | `cargo doc` with warnings as errors | +| Test benchmarks (benches) | Tests the `ignore` crate's benchmarks on nightly | +| Compile Fuzz Test Targets | Installs `cargo-fuzz` and checks the fuzz workspace builds | + +## The conversion + +The whole config, written by reading `.github/workflows/ci.yml` at the commit above: + +```yaml +# cigen.yml +provider: github + +input_groups: + # What building and testing ripgrep reads. The rust module adds every Cargo.toml, Cargo.lock + # and .cargo/config.toml. Left out: the Markdown docs, pkg/, benchsuite/, scripts/, + # HomebrewFormula/ and the release-only ci/ scripts. + rust: ['crates/**', '/build.rs', 'tests/**'] + +commands: + build_and_test: + description: The steps every test build runs, with cargo or cross as $CARGO + steps: + - name: Show command used for Cargo + run: | + echo "cargo command is: ${{ env.CARGO }}" + echo "target flag is: ${{ env.TARGET_FLAGS }}" + echo "target dir is: ${{ env.TARGET_DIR }}" + - name: Build ripgrep and all crates + run: ${{ env.CARGO }} build --verbose --workspace ${{ env.TARGET_FLAGS }} + - name: Build ripgrep with PCRE2 + run: ${{ env.CARGO }} build --verbose --workspace --features pcre2 ${{ env.TARGET_FLAGS }} + - name: Show build.rs stderr + shell: bash + run: | + set +x + stderr="$(find "${{ env.TARGET_DIR }}/debug" -name stderr -print0 | xargs -0 ls -t | head -n1)" + if [ -s "$stderr" ]; then + echo "===== $stderr ===== " + cat "$stderr" + echo "=====" + fi + set -x + - name: Run tests with PCRE2 (sans cross) + if: matrix.target == '' + run: ${{ env.CARGO }} test --verbose --workspace --features pcre2 ${{ env.TARGET_FLAGS }} + - name: Run tests without PCRE2 (with cross) + if: matrix.target != '' + run: ${{ env.CARGO }} test --verbose --workspace ${{ env.TARGET_FLAGS }} + - name: Test zsh shell completions (Unix, sans cross) + if: matrix.target == '' && !startsWith(matrix.os, 'windows') + shell: bash + run: ci/test-complete + - name: Print hostname detected by grep-cli crate + shell: bash + run: ${{ env.CARGO }} test --manifest-path crates/cli/Cargo.toml ${{ env.TARGET_FLAGS }} --lib print_hostname -- --nocapture + - name: Print available short flags + shell: bash + run: ${{ env.CARGO }} test --bin rg ${{ env.TARGET_FLAGS }} flags::defs::tests::available_shorts -- --nocapture + +workflows: + ci: + github: + name: ci + on: + pull_request: {} + push: { branches: [master] } + schedule: [{ cron: '00 01 * * *' }] + permissions: { contents: read } + jobs: + # GitHub's own matrix, passed through: cigen's `matrix:` can't pass values to steps yet, and + # the rust module refuses `toolchain: ${{ matrix.rust }}`, so this job installs Rust the way + # ripgrep does and lists the Cargo files the module would have added. + test: + image: '${{ matrix.os }}' + inputs: + - '@rust' + - 'Cargo.toml' + - '/Cargo.lock' + - '/.cargo/**' + - '/ci/ubuntu-install-packages' + - '/ci/test-complete' + env: + CARGO: cargo + TARGET_FLAGS: '' + TARGET_DIR: ./target + CROSS_VERSION: v0.2.5 + RUST_BACKTRACE: '1' + github: + name: test + strategy: + fail-fast: false + matrix: + include: + - { build: pinned, os: ubuntu-latest, rust: 1.96.0 } + - { build: stable, os: ubuntu-latest, rust: stable } + - { build: beta, os: ubuntu-latest, rust: beta } + - { build: nightly, os: ubuntu-latest, rust: nightly } + - { + build: stable-musl, + os: ubuntu-latest, + rust: stable, + target: x86_64-unknown-linux-musl, + } + - { + build: stable-x86, + os: ubuntu-latest, + rust: stable, + target: i686-unknown-linux-gnu, + } + - { + build: stable-aarch64, + os: ubuntu-latest, + rust: stable, + target: aarch64-unknown-linux-gnu, + } + - { + build: stable-aarch64-musl, + os: ubuntu-latest, + rust: stable, + target: aarch64-unknown-linux-musl, + } + - { + build: stable-arm-gnueabihf, + os: ubuntu-latest, + rust: stable, + target: armv7-unknown-linux-gnueabihf, + } + - { + build: stable-arm-musleabihf, + os: ubuntu-latest, + rust: stable, + target: armv7-unknown-linux-musleabihf, + } + - { + build: stable-arm-musleabi, + os: ubuntu-latest, + rust: stable, + target: armv7-unknown-linux-musleabi, + } + - { + build: stable-powerpc64, + os: ubuntu-latest, + rust: stable, + target: powerpc64-unknown-linux-gnu, + } + - { + build: stable-s390x, + os: ubuntu-latest, + rust: stable, + target: s390x-unknown-linux-gnu, + } + - { + build: stable-riscv64, + os: ubuntu-latest, + rust: stable, + target: riscv64gc-unknown-linux-gnu, + } + - { build: macos, os: macos-latest, rust: nightly } + - { build: win-msvc, os: windows-latest, rust: nightly } + - { + build: win-gnu, + os: windows-latest, + rust: nightly-x86_64-gnu, + } + - { build: winaarch64-msvc, os: windows-11-arm, rust: nightly } + steps: + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: ci/ubuntu-install-packages + - name: Update Docker (32-bit Linux) + if: matrix.target == 'i686-unknown-linux-gnu' + uses: docker/setup-docker-action@v5 + with: { version: latest, set-host: true } + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: { toolchain: '${{ matrix.rust }}' } + - name: Use Cross + if: matrix.os == 'ubuntu-latest' && matrix.target != '' + run: | + dir="$RUNNER_TEMP/cross-download" + mkdir "$dir" + echo "$dir" >> $GITHUB_PATH + cd "$dir" + curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz" + tar xf cross-x86_64-unknown-linux-musl.tar.gz + echo "CARGO=cross" >> $GITHUB_ENV + echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV + echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV + - build_and_test + + wasm: + image: ubuntu-latest + modules: + - rust: { toolchain: stable, targets: [wasm32-wasip1] } + inputs: ['@rust'] + steps: + - name: Basic build + run: cargo build --verbose + + rustfmt: + image: ubuntu-latest + modules: + - rust: { toolchain: stable, components: [rustfmt], cache: false } + inputs: ['*.rs', '/rustfmt.toml'] + steps: + - name: Check formatting + run: cargo fmt --all --check + + docs: + image: ubuntu-latest + modules: + - rust: { toolchain: stable } + inputs: ['@rust'] + steps: + - name: Check documentation + env: { RUSTDOCFLAGS: -D warnings } + run: cargo doc --no-deps --document-private-items --workspace + + benches: + image: ubuntu-latest + modules: + - rust: { toolchain: nightly } + inputs: ['@rust'] + github: { name: Test benchmarks } + steps: + - name: Test ignore benchmarks + run: cargo +nightly test -p ignore --benches + + fuzz_testing: + image: ubuntu-latest + modules: + - rust: { toolchain: stable, path: fuzz } + inputs: ['@rust', 'fuzz/**'] + github: { name: Compile Fuzz Test Targets } + steps: + - name: Install required packages (Ubuntu) + run: | + sudo apt-get update + sudo apt-get install g++ --yes + - name: Install Fuzzer + run: cargo install cargo-fuzz + working-directory: fuzz + - name: Verify fuzz targets build + run: cargo check + working-directory: fuzz +``` + +The `rust` module reads the workspace's `Cargo.toml` when it generates, and the fuzz job's `path: fuzz` needs +`fuzz/Cargo.toml`. These are the parts of ripgrep's two manifests it relies on: + +```toml title="Cargo.toml" +[package] +name = "ripgrep" +version = "16.0.0" + +[workspace] +members = [ + "crates/globset", + "crates/grep", + "crates/cli", + "crates/matcher", + "crates/pcre2", + "crates/printer", + "crates/regex", + "crates/searcher", + "crates/ignore", +] +``` + +```toml title="fuzz/Cargo.toml" +[package] +name = "fuzz" +version = "0.0.1" +publish = false +edition = "2024" + +[workspace] +members = ["."] +``` + +How to read it: + +- **The `rust` module installs the toolchain and adds the Cargo files as inputs.** Every `Cargo.toml`, `Cargo.lock` + and `.cargo/config.toml` becomes an input with no parameters, so the workspace needed no listing. It also caches + the build with `Swatinem/rust-cache`, which ripgrep doesn't do today. `components: [rustfmt]` and + `targets: [wasm32-wasip1]` replace ripgrep's own install steps, and `path: fuzz` points one job at the fuzz + workspace. +- **The `test` job doesn't use the module.** Each matrix entry picks its own toolchain, and the module can't take one + per entry yet ([#47](https://github.com/DocSpring/cigen/issues/47)). It installs Rust as ripgrep does and lists the + Cargo files itself. +- **The matrix is GitHub's own**, passed through in a `github:` block with its 18 entries. cigen hashes each entry + into the job's hash, so an entry that failed never reuses another entry's pass. +- **`build_and_test` is a cigen command**: the build and test steps every matrix entry runs, with `cargo` or `cross` + as `$CARGO`. +- **Inputs leave out what no job reads**: the Markdown docs, `pkg/`, `benchsuite/`, `scripts/` and the release-only + scripts in `ci/`. + +## The estimate + +`cigen replay` walks the last 100 first-parent commits of `master`, computes each job's hash at every commit with the +config above, and counts a job as skipped when that hash already ran on an earlier commit of the replay. + +| Job | Ran | Skipped | Skip rate | +| ------------------------- | --- | ------- | --------- | +| Compile Fuzz Test Targets | 84 | 16 | 16% | +| rustfmt | 85 | 15 | 15% | +| test | 87 | 13 | 13% | +| wasm | 87 | 13 | 13% | +| docs | 87 | 13 | 13% | +| Test benchmarks | 87 | 13 | 13% | +| **All six jobs** | 517 | 83 | **13.8%** | + +The ceiling is low because most commits change code. Of the 100 commits, 78 touched `crates/`, 17 `tests/` and 10 +`Cargo.lock`, and every job builds the whole workspace. Only 14 changed nothing a build reads: docs, `.github/`, +`pkg/` and scripts. + +The table counts `test` once per commit, but GitHub runs it 18 times. Each skip saves 15 entry runs (the three +Windows entries can't skip yet; see below), so its 13 skips are 195 of the 1,800 entry runs, and several of those are +slow cross builds under emulation. + +### What the estimate assumes + +- **Every run passed.** A real failure means the next commit runs the job again, so real CI would skip a little less. +- **One branch.** Only `master`'s first-parent history is replayed. Pull requests aren't modelled. +- **Triggers aren't modelled.** The nightly schedule isn't replayed. See the next section for why skipping it would be + wrong anyway. +- **A pass expires after 7 days unused**, as GitHub's cache evicts it, measured by commit dates. This matters for + ripgrep: with expiry turned off (`--no-expiry`), 94 runs skip (15.7%). In the summer months a commit came every week + or two, so passes expired between commits. +- **No minutes.** Without each job's average duration there's no figure for time saved. + +To run it yourself, clone ripgrep, save the config above as `cigen.yml` outside the clone, and run: + +```sh +cigen replay --config path/to/cigen.yml --repo path/to/ripgrep --last 100 +``` + +## What the conversion found + +Converting ripgrep found one false skip in cigen, fixed before this page: + +- **Matrix entries shared a skip key** ([#43](https://github.com/DocSpring/cigen/issues/43), fixed in + [#51](https://github.com/DocSpring/cigen/pull/51)). All 14 Linux entries of `test` got one hash, so an entry that + failed would have reused another entry's pass. Each entry's values now go into its job's hash. + +And gaps, filed as issues: + +- [#46](https://github.com/DocSpring/cigen/issues/46): `stable`, `beta` and `nightly` hash as words, so a new compiler + release never reruns a job. ripgrep's nightly schedule exists to catch toolchain breakage, and a skip would make it + test nothing. `cargo install cargo-fuzz` is unpinned in the same way. +- [#45](https://github.com/DocSpring/cigen/issues/45): the generated skip steps assume bash, and cigen has no Windows + release. As generated today, the three Windows entries would fail at the install step, so this config can't go into + ripgrep until that's fixed. +- [#47](https://github.com/DocSpring/cigen/issues/47): the `rust` module can't take a toolchain per matrix entry. +- [#48](https://github.com/DocSpring/cigen/issues/48): job `env` values must be strings (`RUST_BACKTRACE: 1` is + refused), and the error doesn't name the key. +- [#32](https://github.com/DocSpring/cigen/issues/32): cigen generates `actions/checkout@v4`, older than the `@v7` + ripgrep uses. + +## What a maintainer would notice + +- Every job but `rustfmt` gets `Swatinem/rust-cache` from the module. That's probably faster, but it's a change, and + the cross builds' `target/` directories may not be what the cache saves. +- Each job gains about 85 generated lines for installing cigen, hashing, the skip cache and the pass marker. The wasm + job is 99 lines, against 13 in ripgrep's file. +- A skipped job reports success, so branch protection stays satisfied.