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
10 changes: 6 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ review bots read and write at the same time, written in Rust.
resolves from `policy.toml`. `plugin.rs` runs `origin <name>` as
`origin-<name>` from `PATH`, passing the repository in the environment.
- `apps/origin-ci`: the CI plugin, `origin-ci`. It reads `checks.toml`
from the revision it checks (`origin ci run`). It runs each check in a
checkout of the revision of its own, and issues the results. Like every
plugin, it uses only the public API: `Remote`, which is the SDK over HTTP
or the service in-process, never origin-src's internals.
from the revision it checks as a tool (`origin ci run`), or as a worker
answering `check.requested` (`origin ci worker`), from the tip of the
target landed on, never the candidate. It runs each check in a checkout
of the revision of its own, and issues the results. Like every plugin, it
uses only the public API: `Remote`, which is the SDK over HTTP or the
service in-process, never origin-src's internals.
- `tools/xtask`: development tasks, run with `cargo xtask`, such as timing
origin against git (`just bench-git`).

Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ origin token issue --scope "write src" [--ttl 1h] # a short-lived token for an

origin ci run [<rev>] # run the checks of checks.toml, and issue their results
origin ci exec lint --inputs src -- cargo clippy # run a command as the check ci.lint, now
origin ci worker --remote <url> # run the checks a server's landings wait for
```

Landing rebases a change onto the target's tip, file by file, checks the
Expand Down Expand Up @@ -153,7 +154,17 @@ with 0, with the last 64 KiB of its output as the payload, declaring its
inputs, `checks.toml` always among them, command and toolchain output, so
its result is promoted to every revision where they're the same. A check a
result of the same issuer already covers, ran or promoted, is skipped.
`origin ci run` reads the checks from the revision it checks.
`origin ci run` reads the checks from the revision it checks. A worker
reads them from the tip of the target being landed on, never from the
candidate, so a change can't redefine the checks that guard the target: an
edit to `checks.toml` takes effect once it has landed, after passing the
checks in force. The worker's results declare the target's `checks.toml`
among their inputs, not the candidate's, so a candidate that restores an
older one doesn't bring back the results of the older checks. Nor are
results promoted from one target to another,
whose checks may differ: landing a target on another runs the checks of
the one it lands on. A target without a `checks.toml` gets no
answer from the worker.
Each command runs in a process group of its own. On Linux, what it leaves
running in that group is killed once it ends, or if the run was killed, by
the next run; a process that leaves the group escapes.
Expand All @@ -167,7 +178,12 @@ check fails. `origin ci exec <name> [--rev <rev>] [--inputs <path>...]
[--toolchain <cmd>] [--external] -- <command...>` runs a command as the
check `ci.<name>` the same way, in a checkout of the revision, with the
command as its definition: always, even if a result covers it, superseding
your previous result of that kind. Its checkouts
your previous result of that kind. `origin ci worker` answers a remote's `check.requested` events
with a token of its own, such as one from `origin token issue --scope "read
/" --scope "annotate ci.*"`: its statements land what waited for them. When
it starts, once the remote is back after going away, and every minute, it
also answers every landing that waits for a check it hasn't run, so no
check is lost to a missed event, a restart or a failed run. Its checkouts
live in `$XDG_STATE_HOME/origin-ci/` (or `~/.local/state/`).

## Permissions
Expand Down
8 changes: 5 additions & 3 deletions apps/origin-ci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
//!
//! As a tool, `origin ci run` checks a revision of the repository it runs
//! in, as the user, and `origin ci exec` runs a command given to it as a
//! check the same way. It talks to origin only through its public API: the
//! SDK over HTTP, or for a repository on a local path, the same service
//! in-process.
//! check the same way. As a worker, `origin ci worker` answers a remote's
//! `check.requested` events, with a token that annotates `ci.*`. Both talk
//! to origin only through its public API: the SDK over HTTP, or for a
//! repository on a local path, the same service in-process.

pub mod checks;
pub mod runner;
pub mod state;
pub mod worker;
30 changes: 30 additions & 0 deletions apps/origin-ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use clap::{Parser, Subcommand};
use origin_ci::checks::Check;
use origin_ci::runner::{Outcome, Runner};
use origin_ci::state::State;
use origin_ci::worker::Worker;
use origin_shared::api::At;
use origin_shared::{ChangeId, RecordId, RepoPath, RevisionId};
use origin_src::config::UserConfig;
Expand Down Expand Up @@ -60,6 +61,23 @@ enum Command {
#[arg(last = true, required = true)]
command: Vec<String>,
},
/// Run the checks a remote's landings wait for, until stopped. Its
/// token, in `$ORIGIN_TOKEN` or the configuration, must read the
/// repository and annotate `ci.*`, such as one issued with `--scope
/// "read /" --scope "annotate ci.*"`. Checks don't inherit
/// `$ORIGIN_TOKEN`, so they don't print it by accident, but they run as
/// the worker's user and can read whatever it can, the token included:
/// run the worker as a user of its own, with a token scoped as above.
/// Runs each check as the
/// `checks.toml` at the tip of the target landed on defines it, never
/// the candidate's. Answers the landings that wait first, and outlives
/// the remote going away.
Worker {
/// The repository: `http://host[:port]/<repository>`, or a path.
/// By default, this repository's remote.
#[arg(long)]
remote: Option<String>,
},
}

fn main() -> ExitCode {
Expand Down Expand Up @@ -95,6 +113,18 @@ impl Cli {
let check = Check::adhoc(&name, &command, inputs, toolchain, external)?;
Ok(Self::report(&[runner.exec(subject, &check)?]))
}
Command::Worker { remote } => {
let url = match (remote, context.and_then(|context| context.remote)) {
(Some(url), _) => RemoteUrl::parse(&url)?,
(None, Some(url)) => url,
(None, None) => bail!("give the worker a --remote"),
};
let runner = Self::runner(&url, &config)?;
let mut worker = Worker::new(runner, &State::open(&url)?)?;
println!("Answering the check requests of {url}");
worker.run()?;
Ok(ExitCode::SUCCESS)
}
}
}

Expand Down
Loading