Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions docs/src/content/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,18 @@ steps:

## 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). |
| 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). |
| `narrow_inputs` | `true` gives every job only the toolchains' files it uses. See [inputs](/docs/inputs/#narrow_inputs). |
| `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:

Expand Down
119 changes: 113 additions & 6 deletions docs/src/content/docs/inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ On top of the job's `inputs`, a job's hash covers:
- **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`.
- **Toolchain pins and settings** in the project root: `rust-toolchain.toml`, `rust-toolchain`, `.ruby-version`,
`.node-version`, `.nvmrc`, `.npmrc`, `.yarnrc.yml`, `.python-version`, `.go-version`, `go.mod`, `go.work`,
`.java-version`, `gradle/wrapper/gradle-wrapper.properties`, `.mvn/wrapper/maven-wrapper.properties`,
`.terraform-version`, and `package.json`'s `packageManager`.
- **Shared pins**, which can pin any tool: `.tool-versions`, `mise.toml`, `.mise.toml`, `mise.local.toml`,
`.mise.local.toml`, `mise/config.toml`, `.mise/config.toml`, `.config/mise.toml` and `.config/mise/config.toml`.
- **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`.
`bun.lock`, `bun.lockb`, `poetry.lock`, `uv.lock`, `Pipfile.lock`, `composer.lock`, `go.sum`, `go.work.sum`,
`.terraform.lock.hcl`.
- **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.

Every job gets every toolchain's pins and lockfiles, unless it sets [`narrow_inputs`](#narrow_inputs).

A command or service the job doesn't use isn't in its hash, so changing it doesn't rerun the job.

### Known gaps
Expand All @@ -107,8 +113,109 @@ A command or service the job doesn't use isn't in its hash, so changing it doesn
- 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.
- Toolchain pins and lockfiles go into every job, so a `yarn.lock` change reruns Rust jobs too, unless the job sets
`narrow_inputs: true`.

## `narrow_inputs`

By default a job's hash covers every toolchain's pins and lockfiles, so a `yarn.lock` change reruns a job that only runs
`cargo`. That's safe, and wasteful. `narrow_inputs: true` gives a job only the toolchains it uses:

```yaml
# cigen.yml
provider: github
narrow_inputs: true

workflows:
ci:
jobs:
test:
inputs: ['src/**']
steps:
- run: cargo test
lint:
inputs: ['src/**']
narrow_inputs: false
steps:
- run: make lint
```

Set it at the top level for every job, or on a job, where the job's value wins. A narrowed job gets:

- the toolchains of the [modules](/docs/modules/) it uses, and those listed in its `toolchains`;
- the toolchains whose commands it visibly runs: `cargo test` brings Rust's files, `bundle exec rake` brings Ruby's;
- every toolchain, as soon as it runs anything cigen can't see into.

The shared pins can pin any tool, so they go into every job either way. A narrowed job gets the project's `package.json`
files only with Node.

cigen reads the job's run steps, the commands it uses and its local composite actions. It follows the shell scripts
they run or source (`sh scripts/check.sh`, `. ./env.sh`) in the directory they run in (`working-directory`, GitHub's
`defaults.run`, a literal `cd`). When the job runs npm, pnpm or Yarn, it reads the scripts of every `package.json` in the
project. Every file it read goes into the job's hash, so changing a script that decided the job's toolchains reruns it.

A toolchain's pins and lockfiles count where its commands run, and in the directories above, as well as in the root:
`cd web && pnpm install` brings `web/pnpm-lock.yaml` and `web/.nvmrc`, and the shared pins there. cigen follows the
options that move a tool to another directory: `yarn --cwd web`, `pnpm -C web`, `terraform -chdir=infra`,
`cargo --manifest-path sub/Cargo.toml`, `go -C dir`.

cigen trusts a toolchain's own commands to use only that toolchain: `cargo test`, `rake` and `pnpm build` bring their
own toolchain's files, and nothing else. Commands that run another command are read for the command they run:
`bundle exec`, `gem exec`, `npx`, `pnpm exec`, `yarn dlx`, `npm exec`, `rustup run stable`, `uv run`, `poetry run`,
`find -exec`, a word pnpm, Yarn or Bun runs that isn't their own subcommand or a package script (`pnpm make`), and a
prefix such as `timeout` or `sudo`. A subcommand that runs the project's own code, such as `cargo run`, `cargo xtask`,
`cargo make` (or `cargo-make`) or `go generate`, counts as something cigen can't see into.

Anything cigen can't see into gives the job every toolchain:

- an unknown command (`make`, a binary on `PATH`), an alias (`git my-alias`, a cargo alias, `alias x=make`), or an
action cigen doesn't know;
- `sh -c` (`bash -lc` too), a shell reading its input, `trap`, a command from a variable, and commands hidden in
arguments: `git rebase --exec`, `git submodule foreach`, `git bisect run`, awk's `system`, sed's `e`, `${X:-$(cmd)}`,
`<(cmd)`, `sort --compress-program`;
- settings that name a command: `git config core.hooksPath`, `GIT_EXTERNAL_DIFF=… git diff`, `export GIT_SSH_COMMAND=…`;
- a `<<` that isn't a heredoc cigen can read (a CircleCI `<< parameter >>`, quoted or not), or a heredoc that never
ends;
- a `cd` it can't follow, when a script or a toolchain's command runs after it: a variable, a directory outside the
project, a `cd` in a subshell, a pipeline or a function, or one that might not happen (inside `if`, a loop or `case`,
after `||`, or after `&&` once the list ends);
- a runner that picks packages itself (`pnpm --filter web exec`, `npm exec --workspace`), and `find -execdir`;
- a step whose `shell:` isn't a POSIX shell, a Windows runner (its steps run in PowerShell), or a runner chosen by an
expression (`runs-on: ${{ matrix.os }}`), which could be Windows.

That's the trade-off: narrowing saves reruns for jobs whose commands cigen can read, and changes nothing for the rest. A
wrong guess would make a job skip when its toolchain changed, so every unclear case includes more.

### What narrowing takes on trust

cigen can't read inside a toolchain's own programs, so it trusts them not to start another toolchain. Projects where
they do:

- `pip install .` or `uv sync` building a Rust extension (PyO3, maturin) with `cargo`;
- `rails assets:precompile` running `yarn` or `npm`;
- `node build.js` calling `cargo` to build a native addon (napi-rs);
- Gradle or Maven frontend plugins running `npm`;
- a runner in `.cargo/config.toml` that runs tests through another tool.

Name the other toolchain in the job's `toolchains`, and a narrowed job gets its pins and lockfiles too:

```yaml
# cigen.yml
provider: github
narrow_inputs: true

workflows:
ci:
jobs:
assets:
toolchains: [node]
inputs: ['app/**']
steps:
- run: bundle exec rails assets:precompile
```

The toolchains are `go`, `java`, `node`, `php`, `python`, `ruby`, `rust` and `terraform`. Or set `narrow_inputs: false`
on the job.

## See a job's hash

Expand Down
30 changes: 16 additions & 14 deletions docs/src/content/docs/jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ workflows:

## 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`. |
| 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. |
| `modules` | Setup steps by name, such as `rust`. See [modules](/docs/modules/). |
| `narrow_inputs` | Only the toolchains' files the job uses. See [inputs](/docs/inputs/#narrow_inputs). |
| `toolchains` | Toolchains a narrowed job uses without cigen seeing it. See [inputs](/docs/inputs/#what-narrowing-takes-on-trust). |
| `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.

Expand Down
Loading
Loading