From 2c4a987b02bc89cce89c503fab539ea3858a427d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 30 Sep 2026 21:21:53 -0400 Subject: [PATCH] wfc: Let check take the runtime from a checkout of the compiler A repository that uses the compiler from elsewhere imports lib/ from a checkout of this one, so the enter steps in its lock files embed that checkout's runtime/, but check looked for runtime/ at the root and reported every job as having no enter step. Found while compiling a demo in bootc-dev/cgwalters-devspace-sandbox (part of #8); a root with no runtime scripts now says so instead. Generated-by: AI --- README.md | 4 +++- src/lib.rs | 12 ++++++++---- src/main.rs | 9 +++++++-- src/shape.rs | 22 +++++++++++++++------- tests/shape.rs | 12 +++++++++--- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 29e410c..1075737 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,9 @@ cargo test # wfc's own tests, and `check` of this repository `check` also checks every workflow in `.github/workflows/`: a lock file must have a source and the compiled shape (`src/shape.rs`: the generated enter and seal steps, byte for byte, and nothing between them that -leaves the wrapper), and anything else must be listed, with its reason, +leaves the wrapper; the enter step is compared with `runtime/`, or with +`--runtime DIR` in a repository that imports the library from a checkout +of this one), and anything else must be listed, with its reason, in `.github/uncompiled-workflows`. `trusted-check.yml` runs the same checks on every pull request with the base branch's code, the pull request's tree only as data, and needs a maintainer's `compiler-change` diff --git a/src/lib.rs b/src/lib.rs index dea69c6..1364507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,15 +117,19 @@ fn stale(path: &str, source: &str, committed: Option<&str>, compiled: &str) -> O /// Compiles or checks the repository at `root`, returning the problems /// found. Only fetching new actions' metadata happens outside it. -pub fn run(root: &Path, mode: Mode) -> Result> { +/// `runtime` is the directory, relative to `root`, of the compiler +/// runtime the lock files embed: `runtime` in this repository, and the +/// `runtime` of a checkout of it in a repository that imports its library +/// from there. +pub fn run(root: &Path, runtime: &str, mode: Mode) -> Result> { let repo = Repo::open(root)?; match mode { - Mode::Check => check(&repo), + Mode::Check => check(&repo, runtime), Mode::Compile => compile(&repo), } } -fn check(root: &Repo) -> Result> { +fn check(root: &Repo, runtime: &str) -> Result> { let lock = actions::read_lock(root)?; let mut problems = actions::check_lock(root, &lock); // The files the sources load, whose scripts are linted below; a @@ -160,7 +164,7 @@ fn check(root: &Repo) -> Result> { } } } - problems.extend(shape::check_tree(root)?); + problems.extend(shape::check_tree(root, runtime)?); problems.extend(pins::check(root)?); let loaded: Vec = loaded.into_iter().collect(); problems.extend(scripts::check(root, &loaded)?); diff --git a/src/main.rs b/src/main.rs index 3a82660..5f8811b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::process::ExitCode; use anyhow::Result; use clap::{Args, Parser, Subcommand}; -use workflow_compiler::{Mode, extract, run}; +use workflow_compiler::{Mode, extract, run, shape}; #[derive(Parser)] #[command( @@ -46,6 +46,11 @@ struct Repo { /// The repository's root. #[arg(long, default_value = ".")] root: PathBuf, + /// The compiler's runtime/ directory, relative to the root, that the + /// lock files embed: a checkout's, in a repository that imports the + /// library from a checkout of workflow-compiler (#8). + #[arg(long, default_value = shape::RUNTIME_DIR)] + runtime: String, } fn main_inner() -> Result { @@ -62,7 +67,7 @@ fn main_inner() -> Result { return Ok(true); } }; - let problems = run(&repo.root, mode)?; + let problems = run(&repo.root, &repo.runtime, mode)?; for p in &problems { eprintln!("error: {p}"); } diff --git a/src/shape.rs b/src/shape.rs index 346cc47..db89018 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -24,7 +24,9 @@ use crate::{LOCKS_DIR, SOURCES_DIR, UNCOMPILED, nickel}; /// name. pub type Runtime = BTreeMap; -const RUNTIME_DIR: &str = "runtime"; +/// Where a repository keeps the compiler's runtime scripts, by default: +/// this repository's own. +pub const RUNTIME_DIR: &str = "runtime"; const EXEC: &str = "/usr/local/bin/runner-sandbox-exec"; const SEAL_ID: &str = "runner-sandbox-seal"; const SEAL_CONDITION: &str = "steps.runner-sandbox-seal.outcome == 'success'"; @@ -620,11 +622,11 @@ fn files_in(root: &Repo, rel: &str) -> Result> { .collect()) } -/// The runtime scripts of the repository at `root`. -pub fn read_runtime(root: &Repo) -> Result { +/// The runtime scripts in `dir` of the repository at `root`. +pub fn read_runtime(root: &Repo, dir: &str) -> Result { let mut runtime = Runtime::new(); - for name in files_in(root, RUNTIME_DIR)? { - let rel = format!("{RUNTIME_DIR}/{name}"); + for name in files_in(root, dir)? { + let rel = format!("{dir}/{name}"); // Only files are scripts; a directory or symlink there is skipped. if root.is_file(&rel)? && let Some(text) = root.read(&rel)? @@ -640,7 +642,7 @@ pub fn read_runtime(root: &Repo) -> Result { /// [`UNCOMPILED`], one name per line with its reason after `#`: each runs /// with none of the compiler's guarantees, so each is a reviewed /// exception. Returns the problems. -pub fn check_tree(root: &Repo) -> Result> { +pub fn check_tree(root: &Repo, runtime_dir: &str) -> Result> { let mut found = Vec::new(); let list_name = Path::new(UNCOMPILED) .file_name() @@ -654,7 +656,7 @@ pub fn check_tree(root: &Repo) -> Result> { Value::from(line) )); } - let runtime = read_runtime(root)?; + let runtime = read_runtime(root, runtime_dir)?; let files = files_in(root, LOCKS_DIR)?; for file in &files { let rel = format!("{LOCKS_DIR}/{file}"); @@ -670,6 +672,12 @@ pub fn check_tree(root: &Repo) -> Result> { found.push(format!("{rel} has no source in {SOURCES_DIR}/")); continue; } + if runtime.is_empty() { + found.push(format!( + "{rel}: no runtime scripts in {runtime_dir}/ to check its enter step against; pass --runtime with the runtime/ directory of the compiler the sources import" + )); + continue; + } let text = root .read(&rel)? .with_context(|| format!("{rel} disappeared"))?; diff --git a/tests/shape.rs b/tests/shape.rs index 90a9bb8..e7aa785 100644 --- a/tests/shape.rs +++ b/tests/shape.rs @@ -7,14 +7,18 @@ use std::sync::LazyLock; use serde_json::{Value, json}; use workflow_compiler::repo::Repo; -use workflow_compiler::shape::{Runtime, check_tree, check_workflow, read_runtime}; +use workflow_compiler::shape::{RUNTIME_DIR, Runtime, check_tree, check_workflow, read_runtime}; const EXEC: &str = "/usr/local/bin/runner-sandbox-exec"; const SEAL: &str = "steps.runner-sandbox-seal.outcome == 'success'"; const UPLOAD: &str = "actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a"; static RUNTIME: LazyLock = LazyLock::new(|| { - read_runtime(&Repo::open(Path::new(env!("CARGO_MANIFEST_DIR"))).unwrap()).unwrap() + read_runtime( + &Repo::open(Path::new(env!("CARGO_MANIFEST_DIR"))).unwrap(), + RUNTIME_DIR, + ) + .unwrap() }); fn rt(name: &str) -> &'static str { @@ -487,7 +491,9 @@ fn every_workflow_file_is_compiled_or_a_listed_exception() { ".github/uncompiled-workflows", "# comment\nci.yml # our own checks\nnoreason.yml\ngone.yml # was here\n", ); - let found = check_tree(&Repo::open(root).unwrap()).unwrap().join("\n"); + let found = check_tree(&Repo::open(root).unwrap(), RUNTIME_DIR) + .unwrap() + .join("\n"); for want in [ "extra.YML isn't compiled", "orphan.lock.yml has no source",