CLI

cigen validate, cigen generate, cigen hash and cigen explain, with every option.

View as MarkdownEdit on GitHub

cigen [-v | -vv] <command>

-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.

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 <path> The config: a cigen.yml file or a .cigen/ directory. Default: whichever the current directory has.
--format <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.

$ 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:

{
  "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.

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 <path> The config: a cigen.yml file or a .cigen/ directory. Default: whichever the current directory has.
-o, --output <dir> 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.

cigen hash --job test
cigen hash --pattern 'src/**/*.rs' --pattern Cargo.lock
Option What it does
--job <id> Hash a job: its inputs, its definition and its derived inputs.
-p, --pattern <glob> Hash the files these globs match, with the same rules as inputs. Repeat it for more globs. Used when there’s no --job.
--config <path> The config for --job. Default: the one in --base-dir.
--base-dir <dir> The project root that globs are relative to. Default ..
--output <name> Also write name=<hash> to $GITHUB_OUTPUT, when that’s set.
--cache <file> Keep per-file hashes in this file, keyed by size and modification time, to hash faster next time.
--matrix <json> 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.

cigen explain test
cigen explain test --format json   # the same, as data
Option What it does
<job> The job’s id.
-c, --config <path> The config. Default: the one in --base-dir.
--base-dir <dir> The project root, where input patterns and step paths are looked up. Default ..
--format <format> text (the default) or json.
--matrix <json> For a job that runs GitHub’s own matrix: one entry, to show that entry’s hash.

For this config:

# 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
$ 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); 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.

Environment

Variable What it does
CIGEN_PLUGIN_DIR The directory that holds the provider binaries.