# cigen documentation > cigen compiles one strict CI config (cigen.yml, or the same document split under .cigen/) into native GitHub Actions workflows and CircleCI config, and skips jobs whose inputs already passed. --- # Overview > What cigen is, what works today, and where to start. cigen compiles a small CI config into native GitHub Actions workflows and CircleCI config, and skips jobs whose inputs have already passed. You write one config, in a `cigen.yml` file or split across a `.cigen/` directory. `cigen generate` writes the provider's own files, which you commit. Each job lists the files its result depends on. cigen hashes those files, plus everything else the job depends on that it can find for itself, and the generated config skips the job when that hash has already passed. ## Who it's for Coding agents now write most CI config, and they keep writing "skip a job when its inputs already passed" by hand: a few hundred lines of hashing, cache markers and trust rules in each repository. The bugs in that code are silent, because a missed input turns a real failure into a green check. cigen is meant to be the one shared, tested implementation. The config is strict so that agents get it right first time: an unknown key is an error that names the file and says what to write instead. ## What works today - Both config layouts, with strict keys and errors that suggest a fix. - `cigen validate`, which lists every problem in a config, as text or JSON. - `cigen generate` for GitHub Actions and CircleCI. - `cigen hash`, which computes a job's hash from its inputs and the inputs cigen derives. - `cigen explain`, which shows what a job's hash covers: each input, the files it matches, and the derived inputs. - `cigen expand`, which prints the whole config as one `cigen.yml`, the way the loader sees it. - Skipping on GitHub Actions, using markers in the GitHub Actions cache. - Deterministic output: generating twice gives the same bytes. ## Not built yet - **Prebuilt binaries.** The current code installs from source with `cargo install`. - **Skipping on CircleCI.** The setup workflow is generated but can't run yet. - **A planner job**, so that a skipped job never starts a runner. Today a skipped GitHub job still starts, checks out and stops early. - **Hosted pass records on VisualCI**, visible across branches and never evicted. The [roadmap](/docs/roadmap/) has the order of work. ## Where to start - [Install](/docs/install/) cigen. - Follow the [quick start](/docs/quick-start/) to generate your first workflow. - Read [configuration](/docs/configuration/) for the full schema. ## For agents Every page is also plain Markdown: add `.md` to its address, as in [`/docs/quick-start.md`](/docs/quick-start.md). [`/llms.txt`](/llms.txt) lists the pages, and [`/llms-full.txt`](/llms-full.txt) holds all of them in one file. To install cigen, an agent can read [`/install.md`](/install.md). --- # Install > Install cigen from source with cargo. Written so an agent can follow it. cigen is a Rust command-line tool. There are no prebuilt binaries for the current code yet (the v0.1.0 release predates it), so install it from source. ## What you need - **Rust**, edition 2024 (Rust 1.85 or later), from [rustup](https://rustup.rs). - **protoc**, the Protocol Buffers compiler. cigen compiles its plugin protocol at build time. - macOS: `brew install protobuf` - Debian or Ubuntu: `apt-get install -y protobuf-compiler` - **git**. `cigen hash` uses `git ls-files` to find the files a pattern matches. ## Install cigen runs each CI provider as a separate binary, so install all three: ```sh cargo install --locked --git https://github.com/DocSpring/cigen \ cigen cigen-provider-github cigen-provider-circleci ``` cargo puts them in `~/.cargo/bin`. cigen looks for the provider binaries next to its own binary, so keep the three together. To keep them somewhere else, set `CIGEN_PLUGIN_DIR` to their directory. ## Check it ```sh cigen --version ``` Then follow the [quick start](/docs/quick-start/). ## Optional - The [CircleCI CLI](https://circleci.com/docs/local-cli/). When `circleci` is on your `PATH`, cigen runs `circleci config validate` on the CircleCI config it generates and fails if the config is invalid. ## For agents To set cigen up in a repository: 1. Install it as above, and run `cigen --version` to check. 2. Write a `cigen.yml` at the repository root. Start from the example in the [quick start](/docs/quick-start/). The schema is in [configuration](/docs/configuration/) and [jobs](/docs/jobs/). 3. Run `cigen generate`. Fix any error it prints: each one names the file and key and says what to change. 4. Commit `cigen.yml` and the generated files together. Never edit the generated files by hand. Change `cigen.yml` and generate again. Every docs page is available as Markdown by adding `.md` to its address, and [`/llms-full.txt`](/llms-full.txt) has them all in one file. --- # Quick start > Write a cigen.yml, generate a GitHub Actions workflow, and see which inputs each job hashes. This takes a Rust project from nothing to a generated GitHub Actions workflow. [Install](/docs/install/) cigen first. ## 1. Write the config Create `cigen.yml` at the root of your repository: ```yaml # cigen.yml provider: github input_groups: rust: ['src/**/*.rs', 'Cargo.toml', 'Cargo.lock'] workflows: ci: github: on: pull_request: {} push: { branches: [main] } jobs: test: image: rust:latest inputs: ['@rust', 'tests/**'] steps: - run: cargo test clippy: image: rust:latest inputs: '@rust' steps: - run: name: Clippy command: cargo clippy --all-targets -- -D warnings ``` - `provider` says what to generate for. - `input_groups` names sets of files that several jobs depend on. - Each job under `workflows.ci.jobs` lists its `inputs`: globs, or `@group` references. When none of them have changed since the job last passed, the job skips. - The workflow's `github:` block is passed to GitHub as it is. That's where GitHub's own keys, such as `on:`, go. ## 2. Generate ```sh cigen generate ``` cigen finds `cigen.yml` (or `.cigen/`) in the current directory and writes `.github/workflows/ci.yml`. Run it again and you get the same bytes. Commit `cigen.yml` and the workflow together. If the config has a mistake, `cigen generate` stops with an error that names the file, the key and the fix ([`cigen validate`](/docs/cli/#cigen-validate) checks without generating): ```text error: cigen.yml (at workflows.ci.jobs.test.stpes): unknown key `stpes` help: did you mean `steps`? The config has 1 problem. `cigen validate --format json` lists them as data. ``` ## 3. Look at a job's hash ```sh cigen hash --job test ``` This prints the hash the generated workflow computes for `test` in CI. It covers the job's `inputs` and its definition, and also files cigen [derives for itself](/docs/inputs/#derived-inputs): `Cargo.lock`, `rust-toolchain.toml`, and any script a step runs. Change a file in `src/` and the hash changes. Change only `README.md` and it doesn't. ## What the workflow does Each job with `inputs` gets a step that installs the cigen release that generated the workflow, then four extra steps: compute its hash, look for a marker under that hash in the GitHub Actions cache, skip the remaining steps if there is one, and record a marker when the job passes. [Skipping](/docs/skipping/) explains the rules. > **Needs a release.** The install step downloads the release whose version generated the workflow. v0.2.0 will be > the first release with those archives; until then a workflow generated from source fails at that step. Jobs without > `inputs` don't run cigen and work anywhere. ## Next - Split the config into files under `.cigen/` when it grows: see [configuration](/docs/configuration/). - Every job key is in [jobs](/docs/jobs/). --- # Configuration > One schema in two layouts, strict keys, JSON schemas for editors, top-level keys, workflow settings and provider blocks. A cigen config is one document. You can keep it in a single `cigen.yml` file, or split the same document into files under `.cigen/`. Both layouts load to the same config and generate the same files. ## The single-file layout ```yaml # cigen.yml provider: github input_groups: rust: ['src/**/*.rs', 'Cargo.toml', 'Cargo.lock'] workflows: ci: jobs: test: image: rust:latest inputs: '@rust' steps: - run: cargo test ``` ## The split layout The same config, as files under `.cigen/`: ```yaml # .cigen/config.yml provider: github input_groups: rust: ['src/**/*.rs', 'Cargo.toml', 'Cargo.lock'] ``` ```yaml # .cigen/workflows/ci/jobs/test.yml image: rust:latest inputs: '@rust' steps: - run: cargo test ``` Where each part of the document goes: | File | Holds | | -------------------------------------------------------------- | --------------------------------------------------- | | `.cigen/config.yml` | Top-level keys. Required, with at least `provider`. | | `.cigen/config/*.yml` | More top-level keys, merged into `config.yml`. | | `.cigen/commands/.yml` | `commands.` | | `.cigen/workflows/.yml` or `workflows//config.yml` | `workflows.`: the workflow's settings | | `.cigen/workflows//jobs/.yml` | `workflows..jobs.` | Jobs in subdirectories get ids with a slash: `workflows/ci/jobs/build/compile.yml` is the job `build/compile`. Two rules keep the layouts equivalent: - A repository with both `cigen.yml` and `.cigen/` is an error. Keep one. A `.cigen/` beside `cigen.yml` counts only if it holds config (`config.yml`, `config/`, `commands/` or `workflows/`): the generated skip steps keep files of their own there (`bin/`, `cache/`, `skip-cache/`). - Every key is defined in one place. Setting the same key in two files is an error that names both files. ## Strict keys The top level, workflow settings and jobs only accept the keys on these pages. Anything else is an error that names the file and the key, and says what to write instead: ```yaml # cigen.yml # error: did you mean `steps`? provider: github workflows: ci: jobs: test: stpes: - run: cargo test ``` Keys from older cigen versions say what they're called now (`requires` is `needs`, `source_files` is `inputs`). Keys that only one provider understands say which provider block to move them into: ```yaml # cigen.yml # error: it's CircleCI-only: move it into a `circleci:` block. provider: circleci workflows: ci: jobs: test: resource_class: large steps: - run: cargo test ``` Commands and package specs still accept keys cigen doesn't know. Steps keep every key they're given and pass it to the provider: see [other step keys](/docs/steps-and-commands/#other-step-keys). ## JSON schemas cigen publishes JSON schemas generated from the same types the loader uses, so they're as strict as cigen is: an unknown key is a schema error everywhere except inside provider blocks, commands, steps and package specs. Point your editor at one for completion and errors as you type. | Schema | For | | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | | [`cigen.schema.json`](https://raw.githubusercontent.com/DocSpring/cigen/main/schemas/v1/cigen.schema.json) | `cigen.yml`, `.cigen/config.yml` and `.cigen/config/*.yml` | | [`workflow.schema.json`](https://raw.githubusercontent.com/DocSpring/cigen/main/schemas/v1/workflow.schema.json) | `.cigen/workflows/.yml` and `.cigen/workflows//config.yml` | | [`job.schema.json`](https://raw.githubusercontent.com/DocSpring/cigen/main/schemas/v1/job.schema.json) | `.cigen/workflows//jobs/**/*.yml` | | [`command.schema.json`](https://raw.githubusercontent.com/DocSpring/cigen/main/schemas/v1/command.schema.json) | `.cigen/commands/.yml` | The top level of a config accepts a `$schema` key: ```yaml # cigen.yml $schema: https://raw.githubusercontent.com/DocSpring/cigen/main/schemas/v1/cigen.schema.json provider: github workflows: ci: jobs: test: image: rust:latest steps: - run: cargo test ``` The other files don't, so name their schema in a comment that editors using the YAML language server read: ```yaml # .cigen/config.yml provider: github ``` ```yaml # .cigen/workflows/ci/jobs/test.yml # yaml-language-server: $schema=https://raw.githubusercontent.com/DocSpring/cigen/main/schemas/v1/job.schema.json image: rust:latest steps: - run: cargo test ``` ## Top-level keys | Key | What it is | | --------------- | --------------------------------------------------------------------------------------------- | | `provider` | Required. `github`, `circleci`, or a list of both. | | `input_groups` | Named lists of globs that jobs reference as `@name`. See [inputs](/docs/inputs/). | | `services` | Service containers jobs can name. See [jobs](/docs/jobs/#services). | | `commands` | Reusable steps. See [steps and commands](/docs/steps-and-commands/). | | `cigen_install` | How jobs that skip get cigen. See [skipping](/docs/skipping/#installing-cigen-on-the-runner). | | `workflows` | Workflows by name. Each holds its settings and its `jobs`. | | `github` | Passed to the GitHub provider untouched. | | `circleci` | Passed to the CircleCI provider untouched. | | `$schema` | Ignored by cigen, so an editor can find the [JSON schema](#json-schemas). | A config with no `provider` is an error: ```yaml # cigen.yml # error: no CI provider configured workflows: ci: jobs: test: steps: - run: cargo test ``` ## Workflow settings Everything under `workflows.` other than `jobs`: | Key | What it is | | ------------------------ | ---------------------------------------------------------------------------------------------------------------------- | | `github` | GitHub workflow keys, such as `on`, `permissions` and `concurrency`. | | `circleci` | CircleCI workflow keys. | | `run_when` | CircleCI only: conditions on pipeline parameters (`parameter`, `equals`) that decide whether the workflow runs. | | `stage_prefix` | `true` to name generated jobs after their full id: `build/compile` becomes `build_compile`. By default it's `compile`. | | `stage_prefix_separator` | What replaces the slash when `stage_prefix` is on. Default `_`. | A GitHub workflow without an `on:` runs on pull requests and on pushes to `main`. ## Provider blocks Anything only one provider understands goes in a `github:` or `circleci:` block: at the top level, in a workflow, or in a job. When cigen generates for that provider, it merges the block in as if its keys were written beside it, unchanged. Other providers never see it. On GitHub, the top-level `github:` block is merged into every workflow, and a key the workflow's own `github:` block sets wins, as a whole value (not merged key by key). ```yaml # cigen.yml provider: github workflows: release: github: on: push: { tags: ['v*'] } permissions: contents: write concurrency: group: release jobs: publish: image: ubuntu-latest github: timeout-minutes: 30 environment: name: release steps: - run: ./scripts/publish.sh ``` GitHub's `on`, `permissions`, `concurrency`, `timeout-minutes`, `if` and `outputs`, and CircleCI's `resource_class`, `parallelism`, `parameters` and `orbs`, all live in provider blocks. ## Job ids Job ids are unique across all workflows: two workflows can't both have a `test` job. A job in a subdirectory can name a sibling without its directory: in `build/test`, `needs: [compile]` means `build/compile` when that job exists. --- # Jobs > Every key a job accepts, what each provider does with it, and services. A job lives under `workflows..jobs.`, or in its own file at `.cigen/workflows//jobs/.yml`. ```yaml # cigen.yml provider: github services: postgres: image: postgres:17 environment: POSTGRES_PASSWORD: postgres workflows: ci: jobs: build: image: rust:latest inputs: ['src/**', 'Cargo.toml', 'Cargo.lock'] steps: - run: cargo build --locked test: image: rust:latest needs: build inputs: ['src/**', 'tests/**', 'Cargo.toml', 'Cargo.lock'] services: [postgres] env: DATABASE_URL: postgres://postgres:postgres@postgres:5432/test steps: - run: cargo test --locked ``` ## Keys | Key | What it is | | ----------- | --------------------------------------------------------------------------------------------------- | | `image` | Where the job runs. Default `ubuntu-latest`. See below. | | `steps` | What the job does. See [steps and commands](/docs/steps-and-commands/). | | `needs` | Jobs that must finish first: one id or a list. | | `inputs` | What the job's result depends on: globs, or `@group` references. See [inputs](/docs/inputs/). | | `env` | Environment variables for every step. | | `services` | Names from the top-level `services`. | | `matrix` | Run the job once per combination of values. See below. | | `packages` | GitHub only: `rust` or `node` adds a dependency cache restore step. | | `checkout` | GitHub only: options for the `actions/checkout` step cigen adds, such as `fetch-depth`. | | `artifacts` | Accepted, but neither provider generates anything from it yet. | | `github` | Job keys passed to GitHub untouched: `timeout-minutes`, `if`, `outputs`, `strategy`, `environment`. | | `circleci` | Job keys passed to CircleCI untouched: `resource_class`, `parallelism`, `parameters`. | Any other key is an error that says what to write instead. ## `image` - **GitHub Actions:** a runner label such as `ubuntu-latest`, `macos-15` or `windows-latest` becomes `runs-on`. Anything else is a container image, and the job runs in it on `ubuntu-latest`. - **CircleCI:** a Docker image for the job's executor. To choose a GitHub runner for a container job, set `runs-on` in the job's `github:` block. ## `needs` `needs` takes one job id or a list. Every id must be a job in the config, and a job can't need itself. Generated jobs keep the dependencies. A job's hash includes the hashes of the jobs it needs, so it runs again whenever one of them would (see [inputs](/docs/inputs/)). A job that a matrix runs in several stages (`- { stage: us }`, `- { stage: eu }`, with `stage_prefix` on) is needed stage by stage: a job in the `us` stage needs `us_build`, and a job in a stage `build` has no instance in (an approval in `review`) needs every instance. ## Services Define each service once at the top level with an `image` (and optionally `environment`), then name it in the jobs that use it. ```yaml # cigen.yml provider: github services: postgres: image: postgres:17 environment: POSTGRES_PASSWORD: postgres workflows: ci: jobs: test: image: ruby:3.4 services: [postgres] steps: - run: bundle exec rspec ``` - **GitHub Actions:** each service becomes a service container. `environment` becomes `env`, and `ports`, `volumes`, `options` and `credentials` pass through. A container job (like `test` above) reaches the service by its name (`postgres`); a job that runs on the runner itself needs `ports`, and reaches it on `localhost`. - **CircleCI:** each service becomes an extra Docker image in the job's executor. A service a job names is part of that job's [hash](/docs/inputs/#derived-inputs), so changing its image reruns the job. ## `matrix` ```yaml # cigen.yml provider: github workflows: ci: jobs: test: image: rust:latest matrix: toolchain: [stable, beta] steps: - run: cargo test ``` Each combination becomes its own job, named after the job and its values: `test-stable` and `test-beta`. A job name keeps only letters, digits, `-` and `_`, the characters both GitHub and CircleCI accept, so any other character in a value becomes `_`: `toolchain: ["1.90"]` gives `test-1_90`. Two combinations that would get the same name are an error, and so is a name that doesn't start with a letter. Today the values aren't passed into the job's steps, and a matrix job with `inputs` fails at its hash step. GitHub's own matrix also works, passed through the `github:` block (`github: { strategy: { matrix: … } }`), with `${{ matrix.x }}` in the steps. Every entry runs the same job definition, so the generated hash step passes the entry to `cigen hash --matrix`, and each entry gets its own hash and pass marker: an entry that failed never reuses another entry's pass. --- # Steps and commands > The step forms cigen understands, and reusable commands. ## Steps A job's `steps` run in order, after the checkout step that cigen adds. ```yaml # .cigen/config.yml provider: github ``` ```yaml # .cigen/workflows/ci/jobs/lint.yml image: node:24 steps: # A shell command - run: npm ci # A shell command with options - run: name: Lint command: npm run lint env: CI: 'true' if: github.event_name == 'pull_request' # A GitHub Action - uses: actions/upload-artifact@v4 with: name: lint-report path: reports/lint.json ``` | Form | GitHub Actions | CircleCI | | -------------------------------------------- | ------------------- | --------------------------------------- | | `- run: ` | A `run` step | A `run` step | | `- run: {name, command, env, if}` | A named `run` step | A named `run` step | | `- uses: ` with `with:` and `if:` | The action | Passed through, and CircleCI rejects it | | A command name, such as `- setup_db` | The command's steps | The command | | A CircleCI step, such as `- store_artifacts` | An error | Passed through unchanged | On GitHub Actions, a step that's neither a GitHub step nor a command is an error that names the job and the step, and says what to use instead where there's an equivalent: ```yaml # cigen.yml # error: `restore_cache` is a CircleCI step. On GitHub, use the `actions/cache` action provider: github workflows: ci: jobs: test: image: ubuntu-latest steps: - restore_cache: keys: [deps-v1] - run: make test ``` ### Other step keys A step keeps every key you give it. Keys cigen doesn't model, such as `id`, `shell`, `continue-on-error` or CircleCI's `when`, go to the provider unchanged and are part of the job's hash, so changing one makes the job run. A key can sit beside `run:` or inside it: ```yaml # cigen.yml provider: github workflows: ci: jobs: lint: image: node:24 steps: - run: npm ci name: Install - run: name: Lint command: npm run lint shell: bash - name: Upload the report id: upload uses: actions/upload-artifact@v4 with: name: lint-report path: reports/lint.json continue-on-error: true ``` The GitHub provider fails on a key a GitHub step can't have, and names the job, the step and the keys it can have: ```yaml # cigen.yml # error: `when` is not a GitHub step key provider: github workflows: ci: jobs: test: image: ubuntu-latest steps: - run: make test when: always ``` ## Commands A command is a named list of steps that jobs can share. Define it under `commands` in `cigen.yml`, or in `.cigen/commands/.yml`: ```yaml # cigen.yml provider: circleci commands: install_gems: description: Install Ruby gems parameters: path: type: string default: vendor/bundle steps: - run: bundle config set path << parameters.path >> - run: bundle install workflows: ci: jobs: test: image: cimg/ruby:3.4 steps: - install_gems - run: bundle exec rspec ``` On CircleCI, commands become CircleCI commands, with their parameters. On GitHub Actions, which has no commands, a step that names a command is replaced by the command's steps (and the steps of any command it uses), with `<< parameters.x >>` filled in from the values the step gives or the parameter's default. Pass values the CircleCI way: ```yaml # fragment steps: - install_gems # path is vendor/bundle, the default - install_gems: path: gems ``` On GitHub these are errors: a parameter with no value and no default, a value for a parameter the command doesn't declare, a parameter of type `steps`, a command that uses itself, and `<< pipeline.x >>`. A command a job uses, and every command that command uses, is part of the job's [hash](/docs/inputs/#derived-inputs): changing a command reruns the jobs that use it, and no others. --- # Inputs > What a job's hash covers. Declared inputs, input groups, and the inputs cigen derives for itself. A job's `inputs` say what its result depends on. When nothing in a job's hash has changed since it last passed, the job skips. A job without `inputs` always runs. ## `inputs` A glob, or a list of globs and `@group` references: ```yaml # cigen.yml provider: github input_groups: rust: ['src/**/*.rs', 'Cargo.toml', 'Cargo.lock'] rust_tests: ['@rust', 'tests/**'] workflows: ci: jobs: test: image: rust:latest inputs: ['@rust_tests', 'fixtures/**/*.json'] steps: - run: cargo test ``` Globs are relative to the project root, the directory that holds `cigen.yml` or `.cigen/`. In a git repository they match the files git tracks (`git ls-files`), so build output and untracked files never change a hash. Outside one, the same rules apply to the files on disk. A checkout owned by another user, as in a container job, works too. If git fails for any other reason, `cigen hash` stops with git's message rather than guess at the files. The rules are gitignore's, which err towards matching more files: a glob that matches too little would skip a job whose inputs changed. | Glob | Matches | | -------------- | --------------------------------------------------------------------------------------------------------- | | `*.md` | Markdown files everywhere: a glob with no `/` matches at any depth, like `**/*.md`. | | `/*.md` | Markdown files at the root only: a leading `/` (or `./`) anchors a glob to the root. | | `docs/*.md` | Markdown files directly in `docs/`: a glob with a `/` starts at the root, and `*` stays in one directory. | | `docs/**/*.md` | Markdown files in `docs/` and every directory under it: `**/` is zero or more directories. | | `docs/**` | Every file under `docs/`. | | `/docs` | Every file under `docs/`: a glob that matches a directory matches every file under it. | | `docs` | Every file under each directory named `docs`, at the root or deeper (`site/docs/`). | A file name with no `/` matches that name in every directory: `Cargo.lock` includes `tools/Cargo.lock`. Write `/Cargo.lock` for the root one only. ## `input_groups` Named lists of globs at the top level. A job refers to one as `@name`. A group can include other groups. A reference to a group that doesn't exist is an error, and so is a cycle: ```yaml # cigen.yml # error: Input groups reference each other in a cycle provider: github input_groups: app: ['src/**', '@shared'] shared: ['lib/**', '@app'] workflows: ci: jobs: test: inputs: '@app' steps: - run: make test ``` ## Derived inputs A job's result depends on more than the files it lists, and a missed input is the worst bug a skipping system can have: the job skips when it should have failed. So `cigen hash` adds the inputs it can find for itself. Each rule errs towards including too much, because an extra input costs a rerun, while a missing one hides a failure. On top of the job's `inputs`, a job's hash covers: - **cigen's version**, the job's id and workflow, the **job's own definition**, and its **workflow's settings**. Changing a step reruns the job. - **The jobs it `needs`**, each by its whole hash, and so the jobs those need too. A job usually uses what the jobs before it made, so a change that reruns `build` also reruns the `test` that needs it. A job it doesn't need isn't in its hash. - **Commands** the job uses, and the commands those use. - **Services** the job names. - **Top-level provider blocks** (`github:`, `circleci:`), which shape every generated job. - **Files its steps name.** Any word in a step that is a path to a project file: `sh scripts/check.sh`, `require('./.github/wait-for-checks.js')`, a file in an action's `with:`. A local action (`uses: ./path`) brings every file in its directory. - **Toolchain pins** in the project root: `rust-toolchain.toml`, `rust-toolchain`, `.ruby-version`, `.node-version`, `.nvmrc`, `.python-version`, `.go-version`, `.java-version`, `.terraform-version`, `.tool-versions`, `mise.toml`, `.mise.toml`, and `package.json`'s `packageManager`. - **Lockfiles** in the project root: `Cargo.lock`, `Gemfile.lock`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `bun.lock`, `bun.lockb`, `poetry.lock`, `uv.lock`, `Pipfile.lock`, `composer.lock`, `go.sum`. - **Every `package.json`** in the project, tracked by git. `npm run test` runs whatever the `test` script says, and cigen can't tell which job runs a package manager, or in which package. A command or service the job doesn't use isn't in its hash, so changing it doesn't rerun the job. ### Known gaps - Files that a named script mentions aren't followed. - Paths in steps are looked up from the project root, so a step with a different working directory can miss its script. - A moving image tag such as `rust:latest` isn't resolved to a digest, so a new image under the same tag doesn't rerun the job. - Toolchain pins and lockfiles go into every job, so a `yarn.lock` change reruns Rust jobs too. Modules will narrow this per toolchain. ## See a job's hash `cigen hash --job ` prints the hash CI computes for a job. See [CLI](/docs/cli/#cigen-hash). --- # Modules > Setup steps you'd otherwise paste into every job, as one line under modules. What a module adds and how it reaches the job's hash. A module is setup you'd otherwise paste into every job: installing a toolchain, caching its downloads, and the inputs that setup depends on. A job lists its modules under `modules:`, and cigen expands each into ordinary steps before a provider sees the job. The project in this page's examples is a Rust crate: ```toml title="Cargo.toml" [package] name = "app" version = "0.1.0" edition = "2024" ``` ```toml title="rust-toolchain.toml" [toolchain] channel = "1.85.0" ``` ## Using a module Name it, or name it with parameters: ```yaml # cigen.yml provider: github workflows: ci: jobs: clippy: modules: - rust: { components: [clippy] } inputs: ['src/**'] steps: - run: cargo clippy --all-targets -- -D warnings fmt: modules: - rust: { components: [rustfmt], cache: false } inputs: ['src/**'] steps: - run: cargo fmt --check ``` A module's steps go after the checkout and the skip check, before the job's own steps. A module that saves a cache after the job (CircleCI's `save_cache`) adds that step after the job's steps. Modules run in the order listed. An unknown module or parameter is an error that names the closest one: ```yaml # cigen.yml # error: there's no module named `rsut`: did you mean `rust`? provider: github workflows: ci: jobs: test: modules: [rsut] steps: - run: cargo test ``` ## Modules and the job's hash A module changes what a job runs, so everything about it goes into the job's hash: - its parameters, after defaults and detection (the toolchain it found in `rust-toolchain.toml`, say); - the steps it adds, for every provider the config names; - the files it depends on. The `rust` module adds `Cargo.toml`, every tracked `**/Cargo.toml`, `Cargo.lock`, the toolchain files and `.cargo/config.toml`, so a job that uses it reruns when any of them changes, without listing them in its `inputs`. The generated hash step also passes `--modules-digest`, a digest of the job's module steps when the config was generated. `cigen hash` mixes it into the hash and warns when its own steps differ, so a config generated by another version of cigen never reuses a pass recorded by this one. Declare the job's own sources in `inputs` (`src/**`, `tests/**`); the module brings its toolchain's files. ## The `rust` module Installs the Rust toolchain your project pins, adds components and targets, and caches cargo's downloads and `target/`. | Parameter | Default | Meaning | | ------------ | ------------------------------------------------------------------- | ------------------------------------------------------------------------- | | `toolchain` | what `rust-toolchain.toml` or `rust-toolchain` names, else `stable` | a channel or version; setting it when a toolchain file exists is an error | | `components` | `[]` | components to add, such as `[clippy, rustfmt]` | | `targets` | `[]` | targets to add, such as `[x86_64-unknown-linux-musl]` | | `cache` | `true` | cache the cargo registry, git dependencies and `target/` | | `path` | `.` | the workspace root, where `Cargo.toml` and `Cargo.lock` are | It installs with `rustup`, which GitHub's runners and the Rust images ship. On GitHub Actions it caches with `Swatinem/rust-cache`, pinned to a commit; on CircleCI with `restore_cache` and `save_cache`, keyed by the architecture, the toolchain and `Cargo.lock`. Its full reference is [`src/modules/rust/README.md`](https://github.com/DocSpring/cigen/blob/main/src/modules/rust/README.md). ## More modules `rust` is the first. Node with npm, pnpm or Yarn comes next, then Playwright, services (Postgres, an S3-compatible store), a shared compile cache and Ruby with Bundler. The [module catalogue](https://github.com/DocSpring/cigen/blob/main/src/modules/README.md) lists the ones that exist. --- # How skipping works > How a job's hash becomes a skip on GitHub Actions, the rules it follows, and its limits today. Skipping rests on one rule: **a job may skip only when everything its result depends on is exactly what it was when it last passed.** cigen hashes that state (the job's [inputs](/docs/inputs/), declared and derived), and keeps a record of each hash that passed. ## On GitHub Actions Every job with `inputs` gets cigen [installed on the runner](#installing-cigen-on-the-runner), then four steps after its checkout: 1. **Compute source hash.** `cigen hash --job ` hashes the job's inputs and writes the result to a step output. 2. **Restore skip cache.** `actions/cache` looks for the exact key `job-skip---`. Only an exact match counts. 3. **Skip job (cached).** On a hit, every remaining step is skipped and the job ends green. 4. **Record job completion.** If every step passed, a marker is saved under that key, so the next run with the same hash skips. The generated steps look like this (trimmed): ```yaml # generated: .github/workflows/ci.yml - name: Compute source hash id: compute_hash run: cigen hash --job test --output job_hash - name: Restore skip cache id: job_skip_cache uses: actions/cache@v4 with: path: .cigen/skip-cache/test key: job-skip-${{ runner.os }}-test-${{ steps.compute_hash.outputs.job_hash }} - name: Skip job (cached) if: steps.job_skip_cache.outputs.cache-hit == 'true' run: echo 'Job cache hit; skipping remaining steps.' && exit 0 - run: cargo test if: steps.job_skip_cache.outputs.cache-hit != 'true' ``` The hash step finds a `cigen.yml` or `.cigen/` config by itself. For a config with any other name, such as `cigen generate --config ci.yml`, it passes `--config ci.yml`. ## Installing cigen on the runner The hash step runs `cigen`, so the jobs that skip need it on the runner. `cigen_install` says how they get it. By default (`release`), a step `Install cigen ` downloads the cigen release whose version generated the workflow, for the runner's OS and architecture (Linux or macOS, x86_64 or arm64), checks it against the release's `.sha256`, and puts it on `PATH`. A download that doesn't match its checksum fails the job, before anything can skip. The `.sha256` comes from the same release as the archive, so this catches a corrupt or truncated download, not a release someone replaced. Set `CIGEN_RELEASE_URL` on the runner to download from a mirror with the same layout as the GitHub releases. A repository that builds cigen itself, as cigen's own does to test the commit under review, names the job that builds it: ```yaml # cigen.yml provider: github cigen_install: job: build_cigen workflows: ci: jobs: build_cigen: image: rust:latest steps: - run: cargo build --workspace && mkdir -p out && cp target/debug/cigen* out/ - uses: actions/upload-artifact@v4 with: name: cigen-bin path: out test: image: rust:latest inputs: 'src/**' steps: - run: cargo test ``` Every other job in that workflow then needs that job and takes cigen from the `cigen-bin` artifact it uploads. The job must exist, and must be in the same workflow as the jobs that skip: ```yaml # cigen.yml # error: `cigen_install` names job `build_cigen`, which isn't defined provider: github cigen_install: job: build_cigen workflows: ci: jobs: test: image: rust:latest steps: - run: cargo test ``` ## The rules These behaviours are covered by end-to-end tests that run generated workflows in a GitHub Actions simulator: - An unchanged tree skips. - A changed input, or a changed job definition, runs. - A failed job records no pass, so the next run tries again. - A pull request reuses passes recorded on `main`, but `main` can't reuse a pull request's. - A pass expires after 7 days without use. ## Limits today - **A skipped job still starts.** Skipping happens step by step inside a running job, so it still takes a runner and a checkout. A planner job that decides before any job starts is [planned](/docs/roadmap/). - **The install step needs its version's release.** It downloads the release whose version generated the workflow, and no release has the archives it expects yet (v0.2.0 will be the first), so a workflow generated by an unreleased build fails at that step until its version is released. - **Cache limits.** Markers live in the GitHub Actions cache, so they inherit its rules: scoped by branch, evicted after 7 days unused, one lookup per job. - **Forcing a rerun** means deleting the job's cache entries, such as with `gh cache delete --all` or by key prefix `job-skip-`. - **Under `act`**, the restore step is turned off, so every job runs. ## On CircleCI The CircleCI provider generates a setup workflow that hashes every job, looks for job-status markers in the CircleCI cache, and continues with only the jobs that need to run. Its setup job can't run end to end yet: it calls a form of `cigen generate` the CLI doesn't have, on an image without cigen. ## Where it's going Pass records will be pluggable: the GitHub Actions cache by default, self-hosted stores such as Redis or S3, and a free hosted store on VisualCI that is visible across branches and never evicted. If a store can't be reached, every job runs: skipping must never fail or block a build. See the [roadmap](/docs/roadmap/). --- # Providers > What cigen generates for GitHub Actions and CircleCI, and what each provider doesn't do yet. Set `provider: github`, `provider: circleci`, or `provider: [github, circleci]` to generate both. Each provider runs as its own binary (`cigen-provider-github`, `cigen-provider-circleci`) and returns files that cigen writes. ## GitHub Actions `cigen generate` writes one file per workflow: `workflows.ci` becomes `.github/workflows/ci.yml`. Its header names the config it came from and the command that regenerates it (`cigen generate`, with `--config` for any other config name). - The workflow's `github:` block supplies the workflow keys (`on`, `permissions`, `concurrency`). Without `on:`, the workflow runs on pull requests and on pushes to `main`. - Each job gets `runs-on` from its `image`, or runs in a container on `ubuntu-latest` (see [jobs](/docs/jobs/#image)). - Every job starts with an `actions/checkout` step. Its options come from the job's `checkout:`. - Jobs with `inputs` get the [skip steps](/docs/skipping/), after a step that [installs cigen](/docs/skipping/#installing-cigen-on-the-runner). - A job's `github:` block is merged into the generated job unchanged. The top-level `github:` block is merged into every workflow's top level; a key the workflow's own `github:` block sets wins, as a whole value. - A step that names a command is replaced by the command's steps, with `<< parameters.x >>` filled in (see [commands](/docs/steps-and-commands/#commands)). - A job's `services` become GitHub service containers (see [services](/docs/jobs/#services)). - A step GitHub can't run, such as CircleCI's `restore_cache`, is an error that names the job and the step. - Steps keep every key they're given; a key a GitHub step can't have is an error (see [other step keys](/docs/steps-and-commands/#other-step-keys)). ## CircleCI `cigen generate` writes two files: - `.circleci/config.yml`: a setup workflow that hashes each job and continues with the jobs that need to run, using the `circleci/continuation` orb. This setup job [can't run yet](/docs/skipping/#on-circleci). - `.circleci/main.yml`: the jobs and workflows, with a shallow-checkout command, your commands, and each job's services as extra Docker images. A job's `circleci:` block is merged into the generated job, and the top-level `circleci:` block into the config. When the `circleci` CLI is on your `PATH`, the provider runs `circleci config validate` on what it generates and fails if CircleCI rejects it. Without the CLI it skips that check, so a config can generate on one machine and fail on another. ## The plugin protocol cigen talks to providers over stdin and stdout with length-prefixed Protocol Buffers messages (`proto/plugin.proto` in the repository). cigen looks for provider binaries in `CIGEN_PLUGIN_DIR` if it's set, then `/usr/local/lib/cigen/plugins`, then next to its own binary. --- # CLI > cigen validate, generate, hash, explain and expand, with every option. ```text cigen [-v | -vv] ``` `-v` prints progress and `-vv` prints debug output. With no command, cigen runs `generate`. ## `cigen validate` Loads the config, checks it, and lists every problem it finds, without generating anything. It exits non-zero when there's a problem. ```sh cigen validate # finds cigen.yml or .cigen/ in the current directory cigen validate --config .cigen cigen validate --format json # the problems as data ``` | Option | What it does | | ----------------------- | ------------------------------------------------------------------------------------------------------ | | `-c`, `--config ` | The config: a `cigen.yml` file or a `.cigen/` directory. Default: whichever the current directory has. | | `--format ` | `text` (the default) or `json`. | The top level is checked first, then each command, workflow and job on its own, so one broken job doesn't hide the problems in the others, then `needs` and input groups across the jobs that loaded. A file that isn't valid YAML stops loading at that file. ```text $ cigen validate error: cigen.yml (at workflows.ci.jobs.build.stpes): unknown key `stpes` help: did you mean `steps`? error: cigen.yml (at workflows.ci.jobs.test.requires): unknown key `requires` help: `requires` is now `needs`. The config has 2 problems. `cigen validate --format json` lists them as data. ``` With `--format json`, it prints one object on stdout, for agents and scripts. `line` is set for YAML syntax errors, and `suggestion` is `null` when there's nothing to suggest: ```json { "valid": false, "config": "cigen.yml", "errors": [ { "file": "cigen.yml", "line": null, "path": ["workflows", "ci", "jobs", "test", "requires"], "message": "unknown key `requires`", "suggestion": "`requires` is now `needs`." } ] } ``` `generate` and `hash --job` print config errors in the same text form. ## `cigen generate` Loads the config, checks it, and writes the generated files. ```sh cigen generate # finds cigen.yml or .cigen/ in the current directory cigen generate --config .cigen # a .cigen/ directory cigen generate --config ci/cigen.yml --output build/ci ``` | Option | What it does | | ----------------------- | ------------------------------------------------------------------------------------------------------ | | `-c`, `--config ` | The config: a `cigen.yml` file or a `.cigen/` directory. Default: whichever the current directory has. | | `-o`, `--output ` | Where to write the files. Default: the directory that holds the config. | Generated files are deterministic: the same config always gives the same bytes. Commit them, and check in CI that generating again changes nothing. Errors name the file and key and say what to change. A directory with both `cigen.yml` and a `.cigen/` that holds config is an error. ## `cigen hash` Prints a hash: of one job, or of the files some patterns match. ```sh cigen hash --job test cigen hash --pattern 'src/**/*.rs' --pattern Cargo.lock ``` | Option | What it does | | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | | `--job ` | Hash a job: its inputs, its definition and its [derived inputs](/docs/inputs/#derived-inputs). | | `-p`, `--pattern ` | Hash the files these globs match, with the same [rules as inputs](/docs/inputs/). Repeat it for more globs. Used when there's no `--job`. | | `--config ` | The config for `--job`. Default: the one in `--base-dir`. | | `--base-dir ` | The project root that globs are relative to. Default `.`. | | `--output ` | Also write `name=` to `$GITHUB_OUTPUT`, when that's set. | | `--cache ` | Keep per-file hashes in this file, keyed by size and modification time, to hash faster next time. | | `--matrix ` | The job's matrix entry (`${{ toJSON(matrix) }}`), for a job that runs GitHub's own matrix. Each entry gets its own hash. | Patterns that match no files hash to the word `empty`. ## `cigen explain` Shows what a job's hash covers: each declared input with the files it matches, the inputs cigen derived from the job, and the hash. Use it to see why a job ran or skipped, or to check that a new job's `inputs` match the files you meant. ```sh cigen explain test cigen explain test --format json # the same, as data ``` | Option | What it does | | ----------------------- | --------------------------------------------------------------------------------- | | `` | The job's id. | | `-c`, `--config ` | The config. Default: the one in `--base-dir`. | | `--base-dir ` | The project root, where input patterns and step paths are looked up. Default `.`. | | `--format ` | `text` (the default) or `json`. | | `--matrix ` | For a job that runs GitHub's own matrix: one entry, to show that entry's hash. | For this config: ```yaml # cigen.yml provider: github input_groups: rust: - 'src/**/*.rs' - Cargo.toml - Cargo.lock workflows: ci: jobs: test: image: rust:1.85 inputs: - '@rust' - scripts/test.sh steps: - run: ./scripts/test.sh ``` ```text $ cigen explain test Job `test` in workflow `ci` Declared inputs: @rust Cargo.lock (1 file) Cargo.lock Cargo.toml (1 file) Cargo.toml src/**/*.rs (1 file) src/main.rs scripts/test.sh (1 file) scripts/test.sh Derived inputs: Cargo.lock (lockfile) rust-toolchain (toolchain pin) scripts/test.sh (named in a step) **/package.json (every package.json, no files) Also hashed: cigen 0.1.0 the job's definition (workflows.ci.jobs.test) the settings of workflow `ci` Hash: 843bac1cb1ef04feb36b3f4f95fa1d00cf1fbacab3372cbead8d85ad403c4d19 ``` A declared pattern that matches no files shows `(no files)`, which usually means a typo. Derived inputs are the files cigen adds on its own (see [derived inputs](/docs/inputs/#derived-inputs)); commands and services the job uses are listed by their config path, and patterns cigen adds (every `package.json`, and the files a job's modules contribute) say which. A job that `needs` others lists them under `Needs` with their own hashes, which are part of its hash, so a change upstream makes it run too. The hash is the one `cigen hash --job test` prints, and the one the generated workflow looks up while it's up to date with the config. A job that runs GitHub's own matrix hashes each entry in, so each entry has its own hash: explain says so, and `--matrix '{"rust": "nightly"}'` shows one entry's hash. With `--format json`, it prints one object with `job`, `workflow`, `inputs` (each `entry` with its `patterns` and their `files`), `derived` (`config` paths, and `files` and `patterns`, each with a `reason`), `needs` (each `job` with its `hash`), `also_hashed`, `runs_matrix`, `matrix_entry` (the entry given, or `null`) and `hash`. An unknown job is an error that suggests the closest id. ## `cigen expand` Prints the whole config as one `cigen.yml`, the way the loader sees it: a `.cigen/` directory's files merged into one document. Use it to read a split config in one place, to turn a `.cigen/` directory into a single `cigen.yml`, or to hand an agent the whole config at once. ```sh cigen expand # finds cigen.yml or .cigen/ in the current directory cigen expand --config .cigen > cigen.yml cigen expand --format json ``` | Option | What it does | | ----------------------- | ------------------------------------------------------------------------------------------------------ | | `-c`, `--config ` | The config: a `cigen.yml` file or a `.cigen/` directory. Default: whichever the current directory has. | | `--format ` | `yaml` (the default) or `json`. | For a `.cigen/` directory with `config.yml`, `commands/setup.yml`, `workflows/ci.yml` and `workflows/ci/jobs/test.yml`: ```text $ cigen expand provider: github input_groups: rust: - src/**/*.rs - Cargo.lock commands: setup: steps: - run: cargo fetch workflows: ci: jobs: test: image: rust:1.85 inputs: - '@rust' steps: - setup - run: cargo test github: on: - push ``` The YAML loads to the same config as the directory, but comments aren't kept. Commands stay as references (`- setup`): expanding them into steps is the provider's job. The config is checked first, so a config with problems prints the same errors as `cigen validate` and nothing on stdout. ## Environment | Variable | What it does | | ------------------ | ----------------------------------------------- | | `CIGEN_PLUGIN_DIR` | The directory that holds the provider binaries. | --- # Roadmap > What's planned for cigen, in order. Nothing here is built yet. cigen is being rebuilt as an agent-first CI compiler whose main job is skipping work that already passed, and getting that right. This page lists what's planned. Nothing on it exists yet; what exists is on the other pages. ## In order 1. **Modules.** Packaged setups for common toolchains (Rust, pnpm and Node, Ruby and Bundler, Playwright, Docker builds, release matrices), each adding the inputs it knows about. A Rust module adds `rust-toolchain.toml` and `Cargo.lock` to the jobs that use Rust, and to no others. 2. **A planner job for GitHub Actions.** One cheap job computes every hash and looks them all up in one batch. Jobs that already passed never start a runner, and a final job counts "skipped" as passed for required checks. 3. **Pluggable pass-record stores.** The GitHub Actions cache by default, self-hosted stores such as Redis and S3, and an open protocol. If a store can't be reached, everything runs. 4. **Agent tools.** `cigen plan`: which jobs will run or skip, and why. (The [JSON schemas](/docs/configuration/#json-schemas), [`cigen validate`](/docs/cli/#cigen-validate) with errors as JSON, [`cigen explain`](/docs/cli/#cigen-explain), which shows what a job's hash covers, and [`cigen expand`](/docs/cli/#cigen-expand), which prints the whole config as one file, are already built.) 5. **Prebuilt binaries** and Docker images with cigen installed. Generated workflows already install the release that generated them; v0.2.0 will be the first release with the archives they download. 6. **Hosted pass records on VisualCI.** A free account, signed in with GitHub, with records visible across branches, no 7-day eviction, batch lookup, and a history of why each job ran. Records hold hashes, job names and who wrote them, never code. 7. **CircleCI parity**, including skipping in the setup workflow. ## Not planned Runners or compute, Docker layer or dependency caches, build-artifact caches, test selection inside a job, test analytics, flaky-test tracking, merge queues, local CI runners, or a CI platform.