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
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*", "server", "server/migration"]

[workspace.package]
version = "0.2.11"
version = "0.2.12"
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/DocSpring/visualci"
Expand Down
24 changes: 14 additions & 10 deletions crates/visualci-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ enum Command {
#[command(flatten)]
connection: Connection,
},
/// Run a test command inside one build: create the build, run the command with VISUALCI_BUILD_ID set (so every
/// Run a test command inside one build: create the build, run the command with VISUALCI_BUILD_ID and
/// VISUALCI_MODE (`local` or `ci`) set (so every
/// test, process or worker that sends snapshots adds them to this build), then finalize it when the command ends,
/// even when the tests fail or are interrupted (Ctrl-C), wait for the result and print what changed. A local run
/// is a subset: what it didn't send isn't "removed". Exits with the command's status when it failed, else 0 when
Expand Down Expand Up @@ -682,7 +683,7 @@ fn run() -> Result<()> {
if let Some(message) = build.blocked_message() {
eprintln!("visualci: {message}");
}
let status = run_tests(&command, &build.id, &connection)?;
let status = run_tests(&command, &build.id, if local { "local" } else { "ci" }, &connection)?;
if upload {
let snapshots = configured_uploads(&snapshot)?;
if !snapshots.is_empty() {
Expand Down Expand Up @@ -724,13 +725,14 @@ fn run() -> Result<()> {
Ok(())
}

/// Run the test command with VISUALCI_BUILD_ID (and the connection's options, when given on the command line) in its
/// environment, and return its exit status: its code, or 128 + the signal that ended it. While it runs this process
/// Run the test command with VISUALCI_BUILD_ID and VISUALCI_MODE (`local` or `ci`, as the build was created: test
/// helpers fail a test on its changes in a local run, and leave them to review in CI) in its environment, with the
/// connection's options when given on the command line, and return its exit status: its code, or 128 + the signal that ended it. While it runs this process
/// ignores Ctrl-C (the command, in the same process group, still gets it), so an interrupted run is still finalized.
fn run_tests(command: &[String], build_id: &str, connection: &Connection) -> Result<i32> {
fn run_tests(command: &[String], build_id: &str, mode: &str, connection: &Connection) -> Result<i32> {
let (program, args) = command.split_first().context("give the test command after --")?;
let mut child = std::process::Command::new(program);
child.args(args).env("VISUALCI_BUILD_ID", build_id);
child.args(args).env("VISUALCI_BUILD_ID", build_id).env("VISUALCI_MODE", mode);
if let Some(url) = &connection.api_url {
child.env("VISUALCI_API_URL", url);
}
Expand Down Expand Up @@ -1266,12 +1268,14 @@ mod tests {
fn runs_the_test_command_with_the_build() {
let connection = Connection { api_url: None, token: None, project: Some("acme/web".into()) };
let sh = |script: &str| vec!["sh".to_string(), "-c".to_string(), script.to_string()];
let ok = r#"[ "$VISUALCI_BUILD_ID" = b-1 ] && [ "$VISUALCI_PROJECT" = acme/web ]"#;
assert_eq!(run_tests(&sh(ok), "b-1", &connection).unwrap(), 0);
assert_eq!(run_tests(&sh("exit 7"), "b-1", &connection).unwrap(), 7);
let ok =
r#"[ "$VISUALCI_BUILD_ID" = b-1 ] && [ "$VISUALCI_MODE" = local ] && [ "$VISUALCI_PROJECT" = acme/web ]"#;
assert_eq!(run_tests(&sh(ok), "b-1", "local", &connection).unwrap(), 0);
assert_eq!(run_tests(&sh(r#"[ "$VISUALCI_MODE" = ci ]"#), "b-1", "ci", &connection).unwrap(), 0);
assert_eq!(run_tests(&sh("exit 7"), "b-1", "local", &connection).unwrap(), 7);
// Interrupted: 128 + SIGINT, and this process is still here to finalize. The command itself still stops on
// Ctrl-C (an ignored SIGINT would leave it running).
assert_eq!(run_tests(&sh("kill -INT $$; sleep 5"), "b-1", &connection).unwrap(), 130);
assert_eq!(run_tests(&sh("kill -INT $$; sleep 5"), "b-1", "local", &connection).unwrap(), 130);
}

#[test]
Expand Down
Loading