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
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT EDIT - This file is generated by cigen
# Source: .cigen/workflows/
# Regenerate with: cargo run -- --config .cigen generate
# Source: .cigen
# Regenerate with: cigen generate
#
name: CI
on:
Expand Down Expand Up @@ -73,7 +73,6 @@ jobs:
mkdir -p .cigen/cache
./.cigen/bin/cigen hash \
--job clippy \
--config .cigen \
--base-dir . \
--output job_hash \
--cache .cigen/cache/file-hashes.json
Expand Down Expand Up @@ -149,7 +148,6 @@ jobs:
mkdir -p .cigen/cache
./.cigen/bin/cigen hash \
--job fmt \
--config .cigen \
--base-dir . \
--output job_hash \
--cache .cigen/cache/file-hashes.json
Expand Down Expand Up @@ -258,7 +256,6 @@ jobs:
mkdir -p .cigen/cache
./.cigen/bin/cigen hash \
--job test \
--config .cigen \
--base-dir . \
--output job_hash \
--cache .cigen/cache/file-hashes.json
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT EDIT - This file is generated by cigen
# Source: .cigen/workflows/
# Regenerate with: cargo run -- --config .cigen generate
# Source: .cigen
# Regenerate with: cigen generate
#
on:
push:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT EDIT - This file is generated by cigen
# Source: .cigen/workflows/
# Regenerate with: cargo run -- --config .cigen generate
# Source: .cigen
# Regenerate with: cigen generate
#
on:
push:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ workflows:
## Status

cigen is early. Generating workflows works for both providers, and the GitHub Actions skip flow is tested end to end, but
two gaps stop it skipping in your CI yet: generated workflows don't install cigen on the runner, and projects with a
`cigen.yml` (rather than `.cigen/`) can't skip in CI. Both are being fixed. CircleCI skipping and modules (shared job
setups you'd otherwise paste into every repository) are coming. [internal_docs/STATUS.md](internal_docs/STATUS.md) lists
what works and every known problem, and [internal_docs/DIRECTION.md](internal_docs/DIRECTION.md) says where it's going.
one gap stops it skipping in your CI yet: generated workflows don't install cigen on the runner. That's being fixed.
CircleCI skipping and modules (shared job setups you'd otherwise paste into every repository) are coming.
[internal_docs/STATUS.md](internal_docs/STATUS.md) lists what works and every known problem, and
[internal_docs/DIRECTION.md](internal_docs/DIRECTION.md) says where it's going.

## Install

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cigen generate --config ci/cigen.yml --output build/ci
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 `.cigen/` is an error.
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`

Expand Down
4 changes: 3 additions & 1 deletion docs/src/content/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ Jobs in subdirectories get ids with a slash: `workflows/ci/jobs/build/compile.ym

Two rules keep the layouts equivalent:

- A repository with both `cigen.yml` and `.cigen/` is an error. Keep one.
- 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
Expand Down
3 changes: 2 additions & 1 deletion docs/src/content/docs/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ its own binary (`cigen-provider-github`, `cigen-provider-circleci`) and returns

## GitHub Actions

`cigen generate` writes one file per workflow: `workflows.ci` becomes `.github/workflows/ci.yml`.
`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`.
Expand Down
6 changes: 4 additions & 2 deletions docs/src/content/docs/skipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The generated steps look like this (trimmed):
# generated: .github/workflows/ci.yml
- name: Compute source hash
id: compute_hash
run: ./.cigen/bin/cigen hash --job test --config .cigen --output job_hash
run: ./.cigen/bin/cigen hash --job test --output job_hash
- name: Restore skip cache
id: job_skip_cache
uses: actions/cache@v4
Expand All @@ -38,6 +38,9 @@ The generated steps look like this (trimmed):
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`.

## The rules

These behaviours are covered by end-to-end tests that run generated workflows in a GitHub Actions simulator:
Expand All @@ -54,7 +57,6 @@ These behaviours are covered by end-to-end tests that run generated workflows in
checkout. A planner job that decides before any job starts is [planned](/docs/roadmap/).
- **The hash step needs a cigen binary at `./.cigen/bin/cigen`.** cigen's own CI builds one; other repositories have
nothing that installs it yet.
- **The hash step passes `--config .cigen`**, so a project that uses `cigen.yml` fails at that step for now.
- **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
Expand Down
14 changes: 7 additions & 7 deletions internal_docs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ What the code does today, checked against the code in December 2026. Where cigen
`.cigen/` is the same document split into files (`config.yml` and `config/*.yml` for the top level,
`commands/<name>.yml`, `workflows/<name>.yml` or `workflows/<name>/config.yml` for a workflow's settings, and
`workflows/<name>/jobs/**/*.yml` for its jobs, where nested directories make ids like `build/compile`). Having both
layouts is an error, and so is a key defined in two files. Both layouts load to the same config and hash the same.
layouts is an error (a `.cigen/` holding only CI state such as `bin/` or `cache/` isn't a layout), and so is a key
defined in two files. Both layouts load to the same config and hash the same.
- The top level, workflow settings and jobs are strict: an unknown key is an error that names its file and path and
says what to write instead (a close match, a renamed key such as `requires` → `needs`, or a provider-only key
to move into a `github:` or `circleci:` block). Commands and package specs still accept unknown keys.
Expand Down Expand Up @@ -49,7 +50,8 @@ What the code does today, checked against the code in December 2026. Where cigen
`src/plugin/`), with the config converted to protobuf in `src/orchestrator/convert.rs`:
- `plugins/provider-github`: GitHub Actions workflows. Jobs with `inputs` get a skip flow: `cigen hash`
computes the job hash, an exact-key `actions/cache` restore finds a marker, the remaining steps are skipped on a
hit, and a marker is recorded on success.
hit, and a marker is recorded on success. Generated `cigen` commands pass `--config` only when the config isn't
`cigen.yml` or `.cigen/`, and the workflow header names the config and the `cigen generate` command.
- A step that names a command (`- setup_db`, `- setup_db: { name: test }`) is replaced by the command's steps,
through other commands too, with CircleCI's `<< parameters.x >>` filled in from the given values or defaults.
A missing or undeclared parameter, a `steps` parameter, a command that uses itself, and `<< pipeline.x >>` are
Expand Down Expand Up @@ -128,11 +130,9 @@ What the code does today, checked against the code in December 2026. Where cigen
13. CircleCI skipping can't run end to end. The CircleCI provider's setup job runs `cigen generate main`, which the
CLI rejects (`unexpected argument 'main'`), and passes the skip list in `CIGEN_SKIP_JOBS_FILE`, which nothing
reads. Its image, `cimg/rust:1.76`, has no `cigen` on it either.
14. Both providers' generated steps run `cigen hash --config .cigen`, so in a project that uses `cigen.yml` the hash
step fails.
15. The header of every generated GitHub workflow says `Source: .cigen/workflows/` and
`Regenerate with: cargo run -- --config .cigen generate`, whatever the layout. That command has the flag in the
wrong place and assumes a checkout of cigen itself.
14. Resolved (PR #21): generated hash steps ran `cigen hash --config .cigen`, which failed in a `cigen.yml` project.
15. Resolved (PR #21): the generated GitHub workflow header named `.cigen/workflows/` and a `cargo run` command
whatever the layout.
16. `matrix` expands a job into one job per combination, named `<job>-<value>`, but the values never reach the job's
steps. On CircleCI a value with a dot (`1.90`) gives a job name (`test-1.90`) that `circleci config validate`
rejects. The CircleCI provider runs that validation only when the `circleci` CLI is installed, so the same config
Expand Down
4 changes: 4 additions & 0 deletions plugins/provider-circleci/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::options::{
};
use crate::setup_config::generate_setup_config;
use anyhow::{Context, Result, bail};
use cigen::plugin::config_file::config_flag;
use cigen::plugin::protocol::{CigenSchema, Fragment, JobDefinition};
use serde_yaml::Value;
use std::collections::BTreeMap;
Expand All @@ -26,6 +27,8 @@ pub(crate) struct CircleciContext<'a> {
pub(crate) services: BTreeMap<String, ServiceDefinition>,
pub(crate) workflow_conditions: BTreeMap<String, Vec<WorkflowRunCondition>>,
pub(crate) raw_config: Value,
/// What generated `cigen` commands append to find the config (empty for the default names).
pub(crate) config_flag: String,
}

pub(crate) fn build_circleci_fragments(schema: &CigenSchema) -> Result<Vec<Fragment>> {
Expand All @@ -39,6 +42,7 @@ pub(crate) fn build_circleci_fragments(schema: &CigenSchema) -> Result<Vec<Fragm
services: extract_services(&raw_config),
workflow_conditions: extract_workflow_conditions(schema)?,
raw_config,
config_flag: config_flag(&schema.config_file)?,
};

let mut fragments = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions plugins/provider-circleci/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ pub(crate) fn convert_job(

let mut steps = vec![build_checkout_invocation(&context.checkout)];
if !job.source_files.is_empty() {
steps.push(build_job_runtime_hash_step(job));
steps.push(build_job_runtime_hash_step(job, &context.config_flag));
}
steps.extend(convert_steps_list(&job.steps)?);
if !job.source_files.is_empty() {
steps.push(build_job_completion_marker_step(job));
steps.push(build_job_completion_marker_step(job, &context.config_flag));
steps.push(build_job_status_save_step(job));
}
map.insert(Value::String("steps".into()), Value::Sequence(steps));
Expand Down
33 changes: 27 additions & 6 deletions plugins/provider-circleci/src/job_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::context::JobVariant;
use cigen::plugin::protocol::JobDefinition;
use serde_yaml::{Mapping, Value};

pub(crate) fn build_job_hash_step(variant: &JobVariant) -> Value {
pub(crate) fn build_job_hash_step(variant: &JobVariant, config_flag: &str) -> Value {
let command = [
"set -euo pipefail".to_string(),
"mkdir -p /tmp/cigen".to_string(),
format!(
"JOB_HASH=$(cigen hash --job {} --config .cigen | tr -d '\\r')",
"JOB_HASH=$(cigen hash --job {}{config_flag} | tr -d '\\r')",
variant.job.id
),
"printf '%s' \"$JOB_HASH\" > /tmp/cigen/job_hash".to_string(),
Expand Down Expand Up @@ -61,12 +61,12 @@ pub(crate) fn job_status_cache_key(job_name: &str) -> String {
)
}

pub(crate) fn build_job_runtime_hash_step(job: &JobDefinition) -> Value {
pub(crate) fn build_job_runtime_hash_step(job: &JobDefinition, config_flag: &str) -> Value {
let command = [
"set -euo pipefail".to_string(),
"mkdir -p /tmp/cigen /tmp/cigen_job_exists".to_string(),
format!(
"JOB_HASH=$(cigen hash --job {} --config .cigen | tr -d '\\r')",
"JOB_HASH=$(cigen hash --job {}{config_flag} | tr -d '\\r')",
job.id
),
"printf '%s' \"$JOB_HASH\" > /tmp/cigen/job_hash".to_string(),
Expand All @@ -88,13 +88,13 @@ pub(crate) fn build_job_runtime_hash_step(job: &JobDefinition) -> Value {
Value::Mapping(wrapper)
}

pub(crate) fn build_job_completion_marker_step(job: &JobDefinition) -> Value {
pub(crate) fn build_job_completion_marker_step(job: &JobDefinition, config_flag: &str) -> Value {
let command = [
"set -euo pipefail".to_string(),
"mkdir -p /tmp/cigen_job_exists".to_string(),
"if [ -z \"${JOB_HASH:-}\" ]; then".to_string(),
format!(
" JOB_HASH=$(cigen hash --job {} --config .cigen | tr -d '\\r')",
" JOB_HASH=$(cigen hash --job {}{config_flag} | tr -d '\\r')",
job.id
),
"fi".to_string(),
Expand Down Expand Up @@ -169,3 +169,24 @@ pub(crate) fn build_skip_list_append_step(variant: &JobVariant, workflow_id: &st
wrapper.insert(Value::String("run".into()), Value::Mapping(run_map));
Value::Mapping(wrapper)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn hash_steps_pass_the_config_only_when_cigen_cannot_find_it() {
let job = JobDefinition {
id: "test".into(),
..Default::default()
};
let command = |step: Value| serde_yaml::to_string(&step).unwrap();
let default = command(build_job_runtime_hash_step(&job, ""));
assert!(default.contains("cigen hash --job test | tr"), "{default}");
let named = command(build_job_completion_marker_step(&job, " --config ci.yml"));
assert!(
named.contains("cigen hash --job test --config ci.yml | tr"),
"{named}"
);
}
}
2 changes: 1 addition & 1 deletion plugins/provider-circleci/src/setup_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) fn build_setup_job(
if variant.job.source_files.is_empty() {
continue;
}
steps.push(build_job_hash_step(variant));
steps.push(build_job_hash_step(variant, &context.config_flag));
steps.push(build_job_status_restore_step(variant));
steps.push(build_skip_list_append_step(variant, workflow_id));
}
Expand Down
7 changes: 7 additions & 0 deletions plugins/provider-github/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! What every job and workflow in one generation shares: the config's commands, its service
//! definitions and the top-level `github:` block.
use anyhow::{Context as _, Result, bail};
use cigen::plugin::config_file::config_flag;
use cigen::plugin::protocol::{CigenSchema, CommandDefinition};
use serde_yaml::{Mapping, Value};
use std::collections::BTreeMap;
Expand All @@ -11,6 +12,10 @@ pub(crate) struct Context<'a> {
pub(crate) services: Mapping,
/// The top-level `github:` block, merged into every workflow's top level.
pub(crate) workflow_defaults: Mapping,
/// The config's path from the project root (`cigen.yml`, `.cigen`).
pub(crate) config_file: String,
/// What generated `cigen` commands append to find the config (empty for the default names).
pub(crate) config_flag: String,
}

impl<'a> Context<'a> {
Expand Down Expand Up @@ -43,6 +48,8 @@ impl<'a> Context<'a> {
commands: &schema.commands,
services,
workflow_defaults: raw,
config_file: schema.config_file.clone(),
config_flag: config_flag(&schema.config_file)?,
})
}
}
4 changes: 3 additions & 1 deletion plugins/provider-github/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub(crate) fn render_job(
let skip_flow = if is_builder_job || !has_source_files {
None
} else {
Some(build_skip_flow(&job.id))
Some(build_skip_flow(&job.id, &context.config_flag))
};

// Check what dependencies are actually needed
Expand Down Expand Up @@ -188,6 +188,8 @@ mod tests {
commands: &commands,
services: Mapping::new(),
workflow_defaults: Mapping::new(),
config_file: "cigen.yml".into(),
config_flag: String::new(),
};
let rendered = render_job(&job, &context, true).unwrap();

Expand Down
2 changes: 2 additions & 0 deletions plugins/provider-github/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ mod tests {
commands,
services: serde_yaml::from_str(services).unwrap(),
workflow_defaults: Mapping::new(),
config_file: "cigen.yml".into(),
config_flag: String::new(),
}
}

Expand Down
11 changes: 6 additions & 5 deletions plugins/provider-github/src/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ pub(crate) struct SkipFlow {
pub(crate) condition: String,
}

pub(crate) fn build_skip_flow(job_id: &str) -> SkipFlow {
/// `config_flag` is what `cigen hash` needs to find the config (empty for the default names).
pub(crate) fn build_skip_flow(job_id: &str, config_flag: &str) -> SkipFlow {
let compute_script = format!(
concat!(
"set -euo pipefail\n",
"mkdir -p .cigen/skip-cache\n",
"mkdir -p .cigen/cache\n",
"./.cigen/bin/cigen hash \\\n",
" --job {job_id} \\\n",
" --config .cigen \\\n",
" --job {job_id}{config_flag} \\\n",
" --base-dir . \\\n",
" --output job_hash \\\n",
" --cache .cigen/cache/file-hashes.json\n"
),
job_id = job_id
job_id = job_id,
config_flag = config_flag
);

let mut compute_step = Mapping::new();
Expand Down Expand Up @@ -132,7 +133,7 @@ mod tests {

#[test]
fn skip_cache_key_is_a_github_expression_of_the_job_hash() {
let flow = build_skip_flow("clippy");
let flow = build_skip_flow("clippy", "");
let with = flow
.restore_step
.get(Value::String("with".into()))
Expand Down
7 changes: 5 additions & 2 deletions plugins/provider-github/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ pub(crate) fn render_workflow_file(
workflow_map.insert(Value::String("jobs".into()), Value::Mapping(jobs_mapping));

let mut yaml = String::from("# DO NOT EDIT - This file is generated by cigen\n");
yaml.push_str("# Source: .cigen/workflows/\n");
yaml.push_str("# Regenerate with: cargo run -- --config .cigen generate\n");
yaml.push_str(&format!("# Source: {}\n", context.config_file));
yaml.push_str(&format!(
"# Regenerate with: cigen generate{}\n",
context.config_flag
));
yaml.push_str("#\n");

let rendered = serde_yaml::to_string(&workflow_map)
Expand Down
2 changes: 2 additions & 0 deletions proto/plugin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ message CigenSchema {
map<string, CommandDefinition> commands = 10;
map<string, string> provider_config = 11;
string raw_config_yaml = 12;
// The config's path from the project root, as written after `--config` (`cigen.yml`, `.cigen`)
string config_file = 13;
}

message WorkflowDefinition {
Expand Down
Loading
Loading