From eae0b723d9318fa82a1c2ef7504b08f1b66a8afb Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 13:47:27 +1300 Subject: [PATCH 1/2] Name the real config in generated hash steps and headers Both providers ran `cigen hash --config .cigen`, so a cigen.yml project failed at the hash step, and the GitHub header always named `.cigen/workflows/` and a `cargo run` command. The core now sends the config's path from the project root (`CigenSchema.config_file`). Generated commands add `--config` only when cigen wouldn't find the config by itself, and the header names the config and the `cigen generate` command to rerun. A `.cigen/` holding only CI state (the binary and caches the skip flow keeps there) beside a cigen.yml is no longer taken for a second layout; the new mockci scenario for a cigen.yml project hit exactly that. --- .github/workflows/ci.yml | 7 ++-- .github/workflows/docs.yml | 4 +-- .github/workflows/release.yml | 4 +-- README.md | 5 ++- internal_docs/STATUS.md | 14 ++++---- plugins/provider-circleci/src/context.rs | 4 +++ plugins/provider-circleci/src/job.rs | 4 +-- plugins/provider-circleci/src/job_status.rs | 33 +++++++++++++++---- plugins/provider-circleci/src/setup_job.rs | 2 +- plugins/provider-github/src/context.rs | 7 ++++ plugins/provider-github/src/job.rs | 4 ++- plugins/provider-github/src/services.rs | 2 ++ plugins/provider-github/src/skip.rs | 11 ++++--- plugins/provider-github/src/workflow.rs | 7 ++-- proto/plugin.proto | 2 ++ src/commands/generate.rs | 6 +++- src/config/mod.rs | 16 +++++++-- src/orchestrator/convert.rs | 12 +++++-- src/orchestrator/workflow.rs | 11 +++++-- src/plugin/config_file.rs | 36 +++++++++++++++++++++ src/plugin/mod.rs | 1 + tests/config_layouts.rs | 14 ++++++++ tests/end_to_end_workflow.rs | 4 +-- tests/github_provider.rs | 34 +++++++++++++++++++ tests/skip_scenarios.rs | 25 ++++++++++++++ 25 files changed, 222 insertions(+), 47 deletions(-) create mode 100644 src/plugin/config_file.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fe55a2..2285300 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0d718aa..e4ae208 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b16c94..9b3cf36 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/README.md b/README.md index 59397e3..e1c8b0d 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,8 @@ 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 +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 diff --git a/internal_docs/STATUS.md b/internal_docs/STATUS.md index bca0a38..a68e03e 100644 --- a/internal_docs/STATUS.md +++ b/internal_docs/STATUS.md @@ -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/.yml`, `workflows/.yml` or `workflows//config.yml` for a workflow's settings, and `workflows//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. @@ -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 @@ -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 `-`, 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 diff --git a/plugins/provider-circleci/src/context.rs b/plugins/provider-circleci/src/context.rs index c3b26a5..558a0d4 100644 --- a/plugins/provider-circleci/src/context.rs +++ b/plugins/provider-circleci/src/context.rs @@ -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; @@ -26,6 +27,8 @@ pub(crate) struct CircleciContext<'a> { pub(crate) services: BTreeMap, pub(crate) workflow_conditions: BTreeMap>, 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> { @@ -39,6 +42,7 @@ pub(crate) fn build_circleci_fragments(schema: &CigenSchema) -> Result 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(), @@ -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(), @@ -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(), @@ -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}" + ); + } +} diff --git a/plugins/provider-circleci/src/setup_job.rs b/plugins/provider-circleci/src/setup_job.rs index 556a410..032b5f7 100644 --- a/plugins/provider-circleci/src/setup_job.rs +++ b/plugins/provider-circleci/src/setup_job.rs @@ -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)); } diff --git a/plugins/provider-github/src/context.rs b/plugins/provider-github/src/context.rs index 14a3a27..78d1a21 100644 --- a/plugins/provider-github/src/context.rs +++ b/plugins/provider-github/src/context.rs @@ -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; @@ -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> { @@ -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)?, }) } } diff --git a/plugins/provider-github/src/job.rs b/plugins/provider-github/src/job.rs index 4137084..3fc7852 100644 --- a/plugins/provider-github/src/job.rs +++ b/plugins/provider-github/src/job.rs @@ -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 @@ -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(); diff --git a/plugins/provider-github/src/services.rs b/plugins/provider-github/src/services.rs index 953e40e..f52ae32 100644 --- a/plugins/provider-github/src/services.rs +++ b/plugins/provider-github/src/services.rs @@ -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(), } } diff --git a/plugins/provider-github/src/skip.rs b/plugins/provider-github/src/skip.rs index ea3a4a4..fb6b568 100644 --- a/plugins/provider-github/src/skip.rs +++ b/plugins/provider-github/src/skip.rs @@ -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(); @@ -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())) diff --git a/plugins/provider-github/src/workflow.rs b/plugins/provider-github/src/workflow.rs index de61ef4..c5bba8b 100644 --- a/plugins/provider-github/src/workflow.rs +++ b/plugins/provider-github/src/workflow.rs @@ -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) diff --git a/proto/plugin.proto b/proto/plugin.proto index f9243d4..5fb90a9 100644 --- a/proto/plugin.proto +++ b/proto/plugin.proto @@ -79,6 +79,8 @@ message CigenSchema { map commands = 10; map 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 { diff --git a/src/commands/generate.rs b/src/commands/generate.rs index 59ccd21..261a385 100644 --- a/src/commands/generate.rs +++ b/src/commands/generate.rs @@ -24,7 +24,11 @@ pub fn generate_command(file: Option, output: Option) -> Result< // Execute workflow println!("Executing workflow..."); let runtime = tokio::runtime::Runtime::new()?; - let result = runtime.block_on(orchestrator.execute(config))?; + let config_file = config_path + .file_name() + .and_then(|name| name.to_str()) + .with_context(|| format!("Config path has no file name: {}", config_path.display()))?; + let result = runtime.block_on(orchestrator.execute(config, config_file))?; // Write output files // Without --output, files go in the project the config belongs to, wherever cigen runs. diff --git a/src/config/mod.rs b/src/config/mod.rs index 42b3a4f..78d3bdd 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -23,7 +23,7 @@ pub fn find(project_dir: &Path) -> Result { }; let file = within("cigen.yml"); let dir = within(".cigen"); - match (file.is_file(), dir.is_dir()) { + match (file.is_file(), holds_split_config(&dir)) { (true, true) => Err(both_layouts(project_dir)), (true, false) => Ok(file), (false, true) => Ok(dir), @@ -35,6 +35,16 @@ pub fn find(project_dir: &Path) -> Result { } } +/// Whether `dir` is a `.cigen/` config. Generated CI steps keep files in `.cigen/` too (`bin/`, +/// `cache/`, `skip-cache/`), so a `.cigen/` beside a `cigen.yml` is a second layout only when it +/// holds config files. +fn holds_split_config(dir: &Path) -> bool { + dir.join("config.yml").is_file() + || ["config", "commands", "workflows"] + .iter() + .any(|part| dir.join(part).is_dir()) +} + /// Loads and checks the config at `path` (a `cigen.yml` file or a `.cigen/` directory). pub fn load(path: &Path) -> Result { if !path.exists() { @@ -46,7 +56,9 @@ pub fn load(path: &Path) -> Result { if let Some(project_dir) = path.parent() { let name = path.file_name().and_then(|n| n.to_str()); let other = match name { - Some("cigen.yml") => Some(project_dir.join(".cigen")), + Some("cigen.yml") => { + Some(project_dir.join(".cigen")).filter(|dir| holds_split_config(dir)) + } Some(".cigen") => Some(project_dir.join("cigen.yml")), _ => None, }; diff --git a/src/orchestrator/convert.rs b/src/orchestrator/convert.rs index b54d2ea..3d074f6 100644 --- a/src/orchestrator/convert.rs +++ b/src/orchestrator/convert.rs @@ -11,8 +11,13 @@ use serde_yaml::{Mapping, Value}; /// Converts a config into what one provider receives. Each provider gets the shared config /// plus its own `github:` or `circleci:` blocks, merged in as if their keys were written beside -/// them; it never sees another provider's blocks. -pub fn config_to_proto(config: &schema::CigenConfig, provider: &str) -> CigenSchema { +/// them; it never sees another provider's blocks. `config_file` is the config's path from the +/// project root, which generated steps pass to `cigen hash`. +pub fn config_to_proto( + config: &schema::CigenConfig, + provider: &str, + config_file: &str, +) -> CigenSchema { let mut raw = Mapping::new(); if !config.services.is_empty() { raw.insert( @@ -62,6 +67,7 @@ pub fn config_to_proto(config: &schema::CigenConfig, provider: &str) -> CigenSch .collect(), provider_config: BTreeMap::new(), raw_config_yaml: serialize_value(&Value::Mapping(raw)), + config_file: config_file.to_string(), } } @@ -364,7 +370,7 @@ mod tests { #[test] fn test_config_to_proto() { let config = create_simple_config(); - let proto = config_to_proto(&config, "github"); + let proto = config_to_proto(&config, "github", "cigen.yml"); assert_eq!(proto.version, "1"); assert_eq!(proto.jobs.len(), 1); diff --git a/src/orchestrator/workflow.rs b/src/orchestrator/workflow.rs index 76171f3..2677f86 100644 --- a/src/orchestrator/workflow.rs +++ b/src/orchestrator/workflow.rs @@ -26,8 +26,13 @@ impl WorkflowOrchestrator { } } - /// Execute the full workflow: detect → plan → generate → merge - pub async fn execute(&mut self, mut config: CigenConfig) -> Result { + /// Execute the full workflow: detect → plan → generate → merge. `config_file` is the + /// config's path from the project root (`cigen.yml`, `.cigen`). + pub async fn execute( + &mut self, + mut config: CigenConfig, + config_file: &str, + ) -> Result { // 1. Build DAG from job definitions (expands matrix and resolves dependencies) let dag = JobDAG::build(&config) .context("Failed to build dependency graph from job definitions")?; @@ -55,7 +60,7 @@ impl WorkflowOrchestrator { let mut all_fragments = Vec::new(); for (provider, plugin_id) in providers.iter().zip(&plugin_ids) { // Each provider gets its own conversion, with only its own provider blocks. - let proto_schema = config_to_proto(&config, provider); + let proto_schema = config_to_proto(&config, provider, config_file); // Send PlanRequest let plan_request = PlanRequest { capabilities: vec![], // TODO: Collect from all plugins diff --git a/src/plugin/config_file.rs b/src/plugin/config_file.rs new file mode 100644 index 0000000..ec9dee2 --- /dev/null +++ b/src/plugin/config_file.rs @@ -0,0 +1,36 @@ +//! How generated steps name the config when they run `cigen`. `cigen hash` and `cigen generate` +//! find `cigen.yml` or `.cigen/` in the project by themselves; any other name needs `--config`. + +use anyhow::{Result, bail}; + +/// The ` --config ` to append to a generated `cigen` command, or nothing when `cigen` +/// finds the config by itself. `config_file` is the config's path from the project root. +pub fn config_flag(config_file: &str) -> Result { + match config_file { + "" => bail!("The generate request names no config file; the core must send `config_file`"), + "cigen.yml" | ".cigen" => Ok(String::new()), + name if name + .chars() + .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-' | '/')) => + { + Ok(format!(" --config {name}")) + } + name => bail!( + "The config file name `{name}` can't be used in a generated shell command: rename it to cigen.yml" + ), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn default_names_need_no_flag() { + assert_eq!(config_flag("cigen.yml").unwrap(), ""); + assert_eq!(config_flag(".cigen").unwrap(), ""); + assert_eq!(config_flag("ci.yml").unwrap(), " --config ci.yml"); + assert!(config_flag("my config.yml").is_err()); + assert!(config_flag("").is_err()); + } +} diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 992aa20..b869752 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -3,6 +3,7 @@ /// This module implements the plugin architecture that allows CIGen to be extended /// with providers (CircleCI, GitHub Actions, Buildkite) and modules (language support, /// caching, etc.) as separate processes communicating via gRPC. +pub mod config_file; pub mod discovery; pub mod framing; pub mod manager; diff --git a/tests/config_layouts.rs b/tests/config_layouts.rs index bb9b07b..d9dc717 100644 --- a/tests/config_layouts.rs +++ b/tests/config_layouts.rs @@ -156,6 +156,20 @@ fn having_both_layouts_is_an_error() { } } +#[test] +fn a_cigen_dir_of_ci_state_beside_cigen_yml_is_not_a_second_layout() { + // Generated CI steps keep the cigen binary and caches in `.cigen/`. + let dir = tempdir().unwrap(); + write(&dir.path().join("cigen.yml"), SINGLE_FILE); + write(&dir.path().join(".cigen/bin/cigen"), ""); + write(&dir.path().join(".cigen/cache/file-hashes.json"), "{}"); + assert_eq!( + cigen::config::find(dir.path()).unwrap(), + dir.path().join("cigen.yml") + ); + cigen::config::load(&dir.path().join("cigen.yml")).unwrap(); +} + #[test] fn a_key_defined_in_two_files_is_an_error() { let dir = tempdir().unwrap(); diff --git a/tests/end_to_end_workflow.rs b/tests/end_to_end_workflow.rs index 2f1a313..be68bad 100644 --- a/tests/end_to_end_workflow.rs +++ b/tests/end_to_end_workflow.rs @@ -36,7 +36,7 @@ workflows: // Execute the workflow with github provider let result = orchestrator - .execute(config) + .execute(config, "cigen.yml") .await .expect("Failed to execute workflow"); @@ -93,7 +93,7 @@ workflows: let mut orchestrator = WorkflowOrchestrator::new(plugin_dir); let result = orchestrator - .execute(config) + .execute(config, "cigen.yml") .await .expect("Failed to execute workflow"); diff --git a/tests/github_provider.rs b/tests/github_provider.rs index e64db10..f1aec7c 100644 --- a/tests/github_provider.rs +++ b/tests/github_provider.rs @@ -169,3 +169,37 @@ workflows: "a workflow's own keys win" ); } + +#[test] +fn the_header_and_hash_step_name_the_real_config() { + let config = "provider: github\nworkflows:\n ci:\n jobs:\n test:\n inputs: [\"src/**\"]\n steps:\n - run: cargo test\n"; + let generate_named = |name: &str, args: &[&str]| { + let repo = FixtureRepo::new(); + repo.write(name, config); + let output = support::cigen() + .arg("generate") + .args(args) + .current_dir(repo.path()) + .output() + .unwrap(); + assert!(output.status.success(), "{output:?}"); + std::fs::read_to_string(repo.path().join(".github/workflows/ci.yml")).unwrap() + }; + + let workflow = generate_named("cigen.yml", &[]); + assert!( + workflow.contains("# Source: cigen.yml\n# Regenerate with: cigen generate\n"), + "{workflow}" + ); + assert!(!workflow.contains("--config"), "{workflow}"); + + let workflow = generate_named("ci.yml", &["--config", "ci.yml"]); + assert!( + workflow.contains("# Source: ci.yml\n# Regenerate with: cigen generate --config ci.yml\n"), + "{workflow}" + ); + assert!( + workflow.contains("--job test --config ci.yml"), + "{workflow}" + ); +} diff --git a/tests/skip_scenarios.rs b/tests/skip_scenarios.rs index d6b8811..1b24bed 100644 --- a/tests/skip_scenarios.rs +++ b/tests/skip_scenarios.rs @@ -67,6 +67,31 @@ fn a_change_outside_the_inputs_skips() { assert!(!tests_ran(&sim.run(WORKFLOW, &push(&docs_only)).unwrap())); } +#[test] +fn a_cigen_yml_project_skips_and_runs() { + // The generated hash step must find the config whatever its layout. + let repo = FixtureRepo::new(); + repo.write( + "cigen.yml", + "provider: github\nworkflows:\n ci:\n jobs:\n test:\n image: rust:latest\n inputs: [\"src/**\"]\n steps:\n - name: Run tests\n run: sh src/test.sh\n", + ) + .write("src/test.sh", "echo testing\n"); + let output = support::cigen() + .arg("generate") + .current_dir(repo.path()) + .output() + .unwrap(); + assert!(output.status.success(), "{output:?}"); + let mut sim = simulator(&repo); + let first = repo.commit("initial"); + assert!(tests_ran(&sim.run(WORKFLOW, &push(&first)).unwrap())); + assert!(!tests_ran(&sim.run(WORKFLOW, &push(&first)).unwrap())); + + repo.write("src/test.sh", "echo testing more\n"); + let changed = repo.commit("change an input"); + assert!(tests_ran(&sim.run(WORKFLOW, &push(&changed)).unwrap())); +} + #[test] fn changing_the_job_definition_runs() { let repo = fixture(); From de0b4aea7ee6bbc55de57caa804767b133467bec Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 14:29:46 +1300 Subject: [PATCH 2/2] Docs: --config only for other config names, the header, and a .cigen/ of CI state (PR #21) --- README.md | 5 +++-- docs/src/content/docs/cli.md | 2 +- docs/src/content/docs/configuration.md | 4 +++- docs/src/content/docs/providers.md | 3 ++- docs/src/content/docs/skipping.md | 6 ++++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e1c8b0d..3b90c9b 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,9 @@ workflows: cigen is early. Generating workflows works for both providers, and the GitHub Actions skip flow is tested end to end, but 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. +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 diff --git a/docs/src/content/docs/cli.md b/docs/src/content/docs/cli.md index 345475a..95ec994 100644 --- a/docs/src/content/docs/cli.md +++ b/docs/src/content/docs/cli.md @@ -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` diff --git a/docs/src/content/docs/configuration.md b/docs/src/content/docs/configuration.md index 5a06947..13af03a 100644 --- a/docs/src/content/docs/configuration.md +++ b/docs/src/content/docs/configuration.md @@ -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 diff --git a/docs/src/content/docs/providers.md b/docs/src/content/docs/providers.md index db973f7..1d00d99 100644 --- a/docs/src/content/docs/providers.md +++ b/docs/src/content/docs/providers.md @@ -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`. diff --git a/docs/src/content/docs/skipping.md b/docs/src/content/docs/skipping.md index 53b989b..8c6884e 100644 --- a/docs/src/content/docs/skipping.md +++ b/docs/src/content/docs/skipping.md @@ -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 @@ -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: @@ -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