Skip to content
Merged
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
1 change: 1 addition & 0 deletions .cigen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ input_groups:
- "tests/**/*.rs"
- "tests/**/*.yml"
- "tests/**/*.trycmd"
- "tests/cmd/**"
- "integration_tests/**/*"
# tests/json_schema.rs reads the committed schemas and checks every config against them
- "schemas/v1/**"
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ open an issue first so we can agree on the approach.
`CIGEN_UPDATE_GOLDEN=1 cargo test --test golden_fixtures` and review the diff before committing.
- **JSON schemas.** `schemas/v1/` is generated from the config types in `src/schema/`. Refresh it with
`CIGEN_UPDATE_GOLDEN=1 cargo test --test json_schema`.
- **CLI snapshots.** `tests/cmd/*.trycmd` hold the exact output of cigen commands, run by `tests/cli.rs`. After an
intended change to help text or output, refresh them with `TRYCMD=overwrite cargo test --test cli -- cli_coverage`
and review the diff before committing.
- **cigen's own CI.** `.github/workflows/` is generated from `.cigen/`, so never edit it by hand. Change `.cigen/`, then
run `cargo build --workspace && cargo run -- generate --config .cigen` (the build matters: `cargo run` alone doesn't
rebuild the provider binaries) and commit both.
Expand Down
3 changes: 3 additions & 0 deletions internal_docs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ What the code does today, checked against the code in December 2026. Where cigen
input or a needed job changes, and for a matrix entry.
- `tests/expand.rs`: expanding every config in the repository gives a `cigen.yml` that loads to the same config and
expands to itself; the JSON form is the same document; an invalid config isn't expanded.
- `tests/cli.rs` runs the trycmd snapshots in `tests/cmd/*.trycmd`: every command's help, `validate` on a broken
config (text, JSON and `generate`'s matching errors), and `validate`, `explain`, `hash --job` and `expand` on a
small project. Refresh them with `TRYCMD=overwrite cargo test --test cli -- cli_coverage` and review the diff.
- `tests/derived_inputs.rs`: changing a script a step runs, a command the job uses, a toolchain pin or the
`package.json` script that `npm run test` runs (the root's or a sub-package's) makes the job run in mockci, and changing a used command, a named service, a top-level provider block, a local action, a lockfile or the
`packageManager` pin changes the job's hash; an unused command or service doesn't.
Expand Down
15 changes: 12 additions & 3 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ fn cli_coverage() {
// Stable env
cases.env("CIGEN_SKIP_CIRCLECI_CLI", "1");

// Note: paths in outputs will be absolute to the CI runner; acceptable for snapshots.

cases.case("tests/cmd/**/*.trycmd");
cases.env(
"CIGEN_PLUGIN_DIR",
support::plugin_dir().display().to_string(),
);
// Inside a git hook, an inherited GIT_DIR would point `cigen hash` at this repository.
// trycmd can't unset a variable, so point it nowhere: git fails and patterns are matched
// on the filesystem, as they are in the sandboxes, which aren't repositories.
let no_git = support::repo_root().join("target/no-git-here");
cases.env("GIT_DIR", no_git.display().to_string());
// Refresh the snapshots after an intended change with
// `TRYCMD=overwrite cargo test --test cli -- cli_coverage`, and review the diff.
cases.case("tests/cmd/*.trycmd");
}

#[test]
Expand Down
7 changes: 0 additions & 7 deletions tests/cmd/generate_inline.trycmd

This file was deleted.

113 changes: 111 additions & 2 deletions tests/cmd/help.trycmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,113 @@
The commands and their options.

```console
$ cigen --help
? status = 0
A CLI tool that generates CI pipeline configurations from templates
A CLI tool that generates CI pipeline configurations

Usage: cigen [OPTIONS] [COMMAND]

Commands:
generate Generate CI configuration (default command)
hash Compute hashes for file patterns or jobs
explain Show what a job's hash covers: its inputs, the files they match, and the hash
expand Print the whole config as one cigen.yml document, the way the loader sees it
validate Check the config and list every problem in it
help Print this message or the help of the given subcommand(s)

Options:
-v, --verbose... Enable verbose output (use -vv for debug output)
-h, --help Print help
-V, --version Print version

```

```console
$ cigen validate --help
Check the config and list every problem in it

Usage: cigen validate [OPTIONS]

Options:
-c, --config <CONFIG> The config: a cigen.yml file or a .cigen/ directory (found in the current directory by default)
--format <FORMAT> Output format [default: text] [possible values: text, json]
-v, --verbose... Enable verbose output (use -vv for debug output)
-h, --help Print help

```

```console
$ cigen explain --help
Show what a job's hash covers: its inputs, the files they match, and the hash

Usage: cigen explain [OPTIONS] <JOB>

Arguments:
<JOB> The job's id

Options:
-c, --config <CONFIG> The config: a cigen.yml file or a .cigen/ directory (found in --base-dir by default)
--base-dir <BASE_DIR> The project root, where input patterns and step paths are looked up [default: .]
--format <FORMAT> Output format [default: text] [possible values: text, json]
--matrix <MATRIX> A matrix entry as JSON, for a job that runs GitHub's own matrix: the hash is that entry's, as its CI hash step computes it
-v, --verbose... Enable verbose output (use -vv for debug output)
-h, --help Print help

```

```console
$ cigen expand --help
Print the whole config as one cigen.yml document, the way the loader sees it

Usage: cigen expand [OPTIONS]

Options:
-c, --config <CONFIG> The config: a cigen.yml file or a .cigen/ directory (found in the current directory by default)
--format <FORMAT> Output format. YAML output is a cigen.yml that loads to the same config (comments aren't kept) [default: yaml] [possible values: yaml, json]
-v, --verbose... Enable verbose output (use -vv for debug output)
-h, --help Print help

```

```console
$ cigen hash --help
Compute hashes for file patterns or jobs

Usage: cigen hash [OPTIONS]

Options:
-p, --pattern <PATTERNS>
Glob patterns to include when computing the hash (relative to --base-dir)
--job <JOB>
Optional job identifier to hash using the loaded cigen config
--config <CONFIG>
The config: a cigen.yml file or a .cigen/ directory (found in --base-dir by default)
--output <OUTPUT_NAME>
Optional name for the output value (written to $GITHUB_OUTPUT when set)
--base-dir <BASE_DIR>
Base directory the patterns are evaluated relative to (defaults to current dir) [default: .]
--cache <CACHE_PATH>
Optional cache file path to persist per-file hashes
-v, --verbose...
Enable verbose output (use -vv for debug output)
--modules-digest <MODULES_DIGEST>
The digest of the job's module expansions when its CI config was generated. It goes into the hash, so the hash covers the steps that config runs
--matrix <MATRIX>
The job's matrix entry as JSON (`${{ toJSON(matrix) }}`), for a job that runs GitHub's own matrix. It goes into the hash, so each entry has its own hash and pass marker
-h, --help
Print help

```

```console
$ cigen generate --help
Generate CI configuration (default command)

Usage: cigen generate [OPTIONS]

Options:
-c, --config <CONFIG> Path to .cigen directory or cigen.yml file
-o, --output <OUTPUT> Output directory for generated files (default: .)
-v, --verbose... Enable verbose output (use -vv for debug output)
-h, --help Print help

```
4 changes: 0 additions & 4 deletions tests/cmd/invalid_config.trycmd

This file was deleted.

2 changes: 2 additions & 0 deletions tests/cmd/project.in/.cigen/commands/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
steps:
- run: echo setting up
3 changes: 3 additions & 0 deletions tests/cmd/project.in/.cigen/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider: github
input_groups:
rust: ["src/**/*.rs", "Cargo.toml"]
4 changes: 4 additions & 0 deletions tests/cmd/project.in/.cigen/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github:
on:
push:
branches: [main]
5 changes: 5 additions & 0 deletions tests/cmd/project.in/.cigen/workflows/ci/jobs/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
image: rust:latest
inputs: ["@rust"]
steps:
- setup
- run: sh scripts/check.sh
1 change: 1 addition & 0 deletions tests/cmd/project.in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/cmd/project.in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[package]
name = "demo"
1 change: 1 addition & 0 deletions tests/cmd/project.in/scripts/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo ok
1 change: 1 addition & 0 deletions tests/cmd/project.in/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn one() {}
2 changes: 2 additions & 0 deletions tests/cmd/project.out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[package]
name = "demo"
Loading
Loading