From 7c8550af21f26f2ecd5e81c34e6d7f0d76c40e85 Mon Sep 17 00:00:00 2001 From: Alexandra Clifford Date: Tue, 31 Dec 2024 00:16:31 -0500 Subject: [PATCH] Add xtask simple CI --- .cargo/config.toml | 2 ++ .github/workflows/xtask.yml | 27 ++++++++++++++++++++++ examples/simple/main.rs | 3 ++- examples/supervised_simple/main.rs | 3 ++- examples/supervisor_core/main.rs | 3 ++- xtask/Cargo.toml | 7 ++++++ xtask/src/main.rs | 36 ++++++++++++++++++++++++++++++ 7 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 .github/workflows/xtask.yml create mode 100644 xtask/Cargo.toml create mode 100644 xtask/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..4b01400 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +xtask = "run --manifest-path xtask/Cargo.toml --" diff --git a/.github/workflows/xtask.yml b/.github/workflows/xtask.yml new file mode 100644 index 0000000..34ec5a6 --- /dev/null +++ b/.github/workflows/xtask.yml @@ -0,0 +1,27 @@ +name: Runner for CI + +on: + workflow_call: + push: + pull_request: + branches: [main] + types: + - opened + - ready_for_review + +jobs: + build: + name: CI Xtask + runs-on: ubuntu-latest + + steps: + - uses: dtolnay/rust-toolchain@stable + with: + target: x86_64-unknown-linux-gnu + + - uses: actions/checkout@v3 + + - name: compile check + run: | + cargo clippy -- -D warnings + cargo xtask run \ No newline at end of file diff --git a/examples/simple/main.rs b/examples/simple/main.rs index 439c4f1..35ad2be 100644 --- a/examples/simple/main.rs +++ b/examples/simple/main.rs @@ -117,7 +117,8 @@ impl HelloWorldActor { { self.say_hello().await; reply.send(()) - }.ok(); + } + .ok(); } HelloWorldEvent::Start => { self.state = ActorState::Running; diff --git a/examples/supervised_simple/main.rs b/examples/supervised_simple/main.rs index 5f5b163..3416f23 100644 --- a/examples/supervised_simple/main.rs +++ b/examples/supervised_simple/main.rs @@ -167,7 +167,8 @@ impl HelloWorldActor { { self.say_hello().await; reply.send(()) - }.ok(); + } + .ok(); } } } diff --git a/examples/supervisor_core/main.rs b/examples/supervisor_core/main.rs index 9add4cc..c0bab81 100644 --- a/examples/supervisor_core/main.rs +++ b/examples/supervisor_core/main.rs @@ -179,7 +179,8 @@ impl HelloWorldActor { { self.say_hello().await; reply.send(()) - }.ok(); + } + .ok(); } } } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..290049c --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "xtask" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.86" \ No newline at end of file diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..fbdb637 --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,36 @@ +use std::{env, path::Path, process::Command}; + +fn main() -> Result<(), Box> { + let task = if let Some(task) = std::env::args().nth(1) { + task + } else { + "build".to_string() + }; + + match task.as_str() { + "build" => command("build"), + "run" => command("run"), + _ => return Err(anyhow::anyhow! { "Unknown command" }.into()), + }?; + + Ok(()) +} + +fn command(input: &str) -> Result<(), Box> { + let cargo: String = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()); + let status = Command::new(cargo) + .current_dir( + Path::new(&env!("CARGO_MANIFEST_DIR")) + .ancestors() + .nth(1) + .unwrap() + .to_path_buf(), + ) + .args([input, "--release", "--example", "simple"]) + .status()?; + + if !status.success() { + return Err(anyhow::anyhow! { "example run step failed" }.into()); + } + Ok(()) +}