From 38810e4ab8da97401b99cc129a2753c3d85f5836 Mon Sep 17 00:00:00 2001 From: Sylvain Benner Date: Tue, 18 Jun 2024 10:00:32 -0400 Subject: [PATCH] Add guide command and run guide execution in pull-request-checks (#24) * Add guide command and run guide execution in pull-request-checks * Build xtask crate in dedicated directory --- .cargo/config.toml | 2 +- xtask/src/commands/pull_request_checks.rs | 6 ++++-- xtask/src/commands/test.rs | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index d8c2032..2759274 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -xtask = "run --manifest-path ./xtask/Cargo.toml --" +xtask = "run --target-dir target/xtask/debug --package xtask --bin xtask --" diff --git a/xtask/src/commands/pull_request_checks.rs b/xtask/src/commands/pull_request_checks.rs index ab01750..0f214aa 100644 --- a/xtask/src/commands/pull_request_checks.rs +++ b/xtask/src/commands/pull_request_checks.rs @@ -1,6 +1,6 @@ use strum::IntoEnumIterator; -use super::ci::{self, CICmdArgs, CICommand}; +use super::{ci::{self, CICmdArgs, CICommand}, test::run_guide}; pub(crate) fn handle_command() -> anyhow::Result<()> { CICommand::iter() @@ -10,5 +10,7 @@ pub(crate) fn handle_command() -> anyhow::Result<()> { target: super::Target::All, command: c.clone(), }) - ) + )?; + // Execute the guide example + run_guide() } diff --git a/xtask/src/commands/test.rs b/xtask/src/commands/test.rs index 45fedef..c983dfe 100644 --- a/xtask/src/commands/test.rs +++ b/xtask/src/commands/test.rs @@ -8,6 +8,9 @@ use crate::{endgroup, group, utils::workspace::{get_workspace_members, Workspace use super::Target; +const PROJECT_UUID: &str = "331a3907-bfd8-45e5-af54-1fee73a3c1b1"; +const API_KEY: &str = "dcaf7eb9-5acc-47d7-8b93-ca0fbb234096"; + #[derive(Args)] pub(crate) struct TestCmdArgs { /// Target to test for. @@ -26,6 +29,8 @@ enum TestCommand { Integration, /// Run documentation tests. Documentation, + /// Run guide test against Heat dev stack. + Guide, /// Run all the checks. All, } @@ -35,6 +40,7 @@ pub(crate) fn handle_command(args: TestCmdArgs) -> anyhow::Result<()> { TestCommand::Unit => run_unit(&args.target), TestCommand::Integration => run_integration(&args.target), TestCommand::Documentation => run_documentation(&args.target), + TestCommand::Guide => run_guide(), TestCommand::All => { TestCommand::iter() .filter(|c| *c != TestCommand::All) @@ -48,6 +54,20 @@ pub(crate) fn handle_command(args: TestCmdArgs) -> anyhow::Result<()> { } } +pub(crate) fn run_guide() -> Result<()> { + group!("Guide Test"); + info!("Command line: cargo run --release --bin guide -- --key \"...\" --project \"...\""); + let status = Command::new("cargo") + .args(["run", "--release", "--bin", "guide", "--", "--key", API_KEY, "--project", PROJECT_UUID]) + .status() + .map_err(|e| anyhow!("Failed to execute guide example: {}", e))?; + if !status.success() { + return Err(anyhow!("Failed to execute guide example")); + } + endgroup!(); + Ok(()) +} + pub(crate) fn run_unit(target: &Target) -> Result<()> { match target { Target::Crates | Target::Examples => {