flowey_lib_hvlite/_jobs/
build_test_results_website.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build the test-results website using npm.
5
6use flowey::node::prelude::*;
7
8flowey_request! {
9    pub struct Request {
10        pub path: WriteVar<PathBuf>,
11    }
12}
13
14new_simple_flow_node!(struct Node);
15
16impl SimpleFlowNode for Node {
17    type Request = Request;
18
19    fn imports(ctx: &mut ImportCtx<'_>) {
20        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
21        ctx.import::<flowey_lib_common::install_nodejs::Node>();
22    }
23
24    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
25        let Request { path } = request;
26
27        // Make sure that npm is installed
28        let npm_installed = ctx.reqv(flowey_lib_common::install_nodejs::Request::EnsureInstalled);
29        let openvmm_repo_path = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
30
31        ctx.emit_rust_step("build test-results website", |ctx| {
32            npm_installed.claim(ctx);
33            let path = path.claim(ctx);
34            let openvmm_repo_path = openvmm_repo_path.claim(ctx);
35
36            move |rt| {
37                let sh = xshell::Shell::new()?;
38                let mut dist_path = rt.read(openvmm_repo_path);
39
40                // Navigate to the petri/logview_new directory within the
41                // OpenVMM repo
42                dist_path.push("petri");
43                dist_path.push("logview_new");
44
45                sh.change_dir(&dist_path);
46
47                // Because the project is using vite, the output will go
48                // directly to the 'dist-ci' folder
49                xshell::cmd!(sh, "npm install").run()?;
50                xshell::cmd!(sh, "npm run build:ci").run()?;
51
52                dist_path.push("dist-ci");
53                if !dist_path.exists() {
54                    anyhow::bail!(
55                        "logview_new build failed. Expected 'dist-ci' directory at {:?} but it was not found.",
56                        dist_path
57                    );
58                }
59
60                rt.write(path, &dist_path);
61
62                Ok(())
63            }
64        });
65
66        Ok(())
67    }
68}