Skip to main content

flowey_lib_hvlite/_jobs/
publish_vmgstool_gh_release.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Publishes a GitHub release for VmgsTool
5
6use crate::build_vmgstool::VmgstoolOutput;
7use flowey::node::prelude::*;
8use std::collections::BTreeMap;
9
10flowey_request! {
11    pub struct Request {
12        pub vmgstools: BTreeMap<String, ReadVar<VmgstoolOutput>>,
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::<flowey_lib_common::publish_gh_release::Node>();
24        ctx.import::<flowey_lib_common::get_cargo_crate_version::Node>();
25        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
26    }
27
28    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
29        let Request { vmgstools, done } = request;
30
31        let files = ctx.emit_rust_stepv("enumerate vmgstool release files", |ctx| {
32            let vmgstools = vmgstools
33                .into_iter()
34                .map(|(t, v)| (t, v.claim(ctx)))
35                .collect::<BTreeMap<_, _>>();
36            move |rt| {
37                let mut files = Vec::new();
38                for (target, vmgstool) in vmgstools {
39                    let vmgstool = rt.read(vmgstool);
40                    match vmgstool {
41                        VmgstoolOutput::LinuxBin { bin, dbg } => {
42                            let bin_name = PathBuf::from(format!("vmgstool-{target}"));
43                            fs_err::hard_link(&bin, &bin_name)?;
44                            files.push((bin_name.absolute()?, None));
45
46                            if let Some(dbg) = dbg {
47                                let dbg_name = PathBuf::from(format!("vmgstool-{target}.dbg"));
48                                fs_err::hard_link(&dbg, &dbg_name)?;
49                                files.push((dbg_name.absolute()?, None));
50                            }
51                        }
52                        VmgstoolOutput::WindowsBin { exe, pdb } => {
53                            let exe_name = PathBuf::from(format!("vmgstool-{target}.exe"));
54                            fs_err::hard_link(&exe, &exe_name)?;
55                            files.push((exe_name.absolute()?, None));
56
57                            if let Some(pdb) = pdb {
58                                let pdb_name = PathBuf::from(format!("vmgstool-{target}.pdb"));
59                                fs_err::hard_link(&pdb, &pdb_name)?;
60                                files.push((pdb_name.absolute()?, None));
61                            }
62                        }
63                    }
64                }
65                Ok(files)
66            }
67        });
68
69        let openvmm_repo_path = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
70        let vmgstool_path =
71            openvmm_repo_path.map(ctx, |p| p.join("vm").join("vmgs").join("vmgstool"));
72        let version = ctx.reqv(|v| flowey_lib_common::get_cargo_crate_version::Request {
73            path: vmgstool_path,
74            version: v,
75        });
76        let version = version.map(ctx, |v| v.unwrap_or("0.1.0".into()));
77        let tag = version.map(ctx, |v| format!("vmgstool-v{v}"));
78        let title = version.map(ctx, |v| format!("VmgsTool v{v}"));
79
80        let target = ctx.emit_rust_stepv("get current commit", |ctx| {
81            let openvmm_repo_path = openvmm_repo_path.claim(ctx);
82            move |rt| {
83                let path = rt.read(openvmm_repo_path);
84                rt.sh.change_dir(path);
85                let target = flowey::shell_cmd!(rt, "git rev-parse HEAD").read()?;
86                log::info!("current commit is {target}");
87                Ok(target)
88            }
89        });
90
91        ctx.req(flowey_lib_common::publish_gh_release::Request(
92            flowey_lib_common::publish_gh_release::GhReleaseParams {
93                repo_owner: crate::common::OPENVMM_GITHUB_OWNER.into(),
94                repo_name: crate::common::OPENVMM_GITHUB_REPO.into(),
95                target,
96                tag,
97                title,
98                files,
99                notes: flowey_lib_common::publish_gh_release::GhReleaseNotes::Text("TODO".into()),
100                draft: true,
101                verify_tag: false,
102                // This job runs on every push to main, but the tag only
103                // changes when the version in the tree does, so an existing
104                // release is the normal steady state rather than a problem.
105                on_existing: flowey_lib_common::publish_gh_release::OnExistingRelease::Skip,
106                prerequisites: Vec::new(),
107                done,
108            },
109        ));
110
111        Ok(())
112    }
113}