flowey_lib_hvlite/_jobs/
test_local_flowey_build_igvm.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Encapsulates the logic of invoking `cargo xflowey build-igvm x64 --install-missing-deps`
5use flowey::node::prelude::*;
6
7use crate::_jobs::local_build_igvm::non_production_build_igvm_tool_out_name;
8use crate::build_openhcl_igvm_from_recipe::OpenhclIgvmRecipe;
9
10flowey_request! {
11    pub struct Request {
12        pub base_recipe: OpenhclIgvmRecipe,
13        pub done: WriteVar<SideEffect>,
14    }
15}
16
17new_simple_flow_node!(struct Node);
18
19impl SimpleFlowNode for Node {
20    type Request = Request;
21
22    fn imports(ctx: &mut ImportCtx<'_>) {
23        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
24        ctx.import::<flowey_lib_common::install_rust::Node>();
25    }
26
27    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
28        let Request { base_recipe, done } = request;
29
30        let hvlite_repo = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
31        let rust_install = ctx.reqv(flowey_lib_common::install_rust::Request::EnsureInstalled);
32        let gh_token = (ctx.backend() == FlowBackend::Github)
33            .then(|| ctx.get_gh_context_var().global().token());
34
35        let test_local = ctx.emit_rust_step(
36            "test cargo xflowey build-igvm x64 --install-missing-deps",
37            |ctx| {
38                rust_install.claim(ctx);
39                let hvlite_repo = hvlite_repo.claim(ctx);
40                let gh_token = gh_token.claim(ctx);
41                move |rt| {
42                    let hvlite_repo = rt.read(hvlite_repo);
43                    let gh_token = rt.read(gh_token);
44                    let base_recipe = non_production_build_igvm_tool_out_name(&base_recipe);
45                    rt.sh.change_dir(hvlite_repo);
46                    let mut cmd = flowey::shell_cmd!(
47                        rt,
48                        "cargo xflowey build-igvm {base_recipe} --install-missing-deps"
49                    )
50                    .env("I_HAVE_A_GOOD_REASON_TO_RUN_BUILD_IGVM_IN_CI", "true");
51                    if let Some(gh_token) = gh_token {
52                        cmd = cmd.env("GITHUB_TOKEN", gh_token);
53                    }
54                    cmd.run()?;
55                    Ok(())
56                }
57            },
58        );
59
60        ctx.emit_side_effect_step([test_local], [done]);
61
62        Ok(())
63    }
64}