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                            let dbg_name = PathBuf::from(format!("vmgstool-{target}.dbg"));
47                            fs_err::hard_link(&dbg, &dbg_name)?;
48                            files.push((dbg_name.absolute()?, None));
49                        }
50                        VmgstoolOutput::WindowsBin { exe, pdb } => {
51                            let exe_name = PathBuf::from(format!("vmgstool-{target}.exe"));
52                            fs_err::hard_link(&exe, &exe_name)?;
53                            files.push((exe_name.absolute()?, None));
54
55                            if let Some(pdb) = pdb {
56                                let pdb_name = PathBuf::from(format!("vmgstool-{target}.pdb"));
57                                fs_err::hard_link(&pdb, &pdb_name)?;
58                                files.push((pdb_name.absolute()?, None));
59                            }
60                        }
61                    }
62                }
63                Ok(files)
64            }
65        });
66
67        let openvmm_repo_path = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
68        let vmgstool_path =
69            openvmm_repo_path.map(ctx, |p| p.join("vm").join("vmgs").join("vmgstool"));
70        let version = ctx.reqv(|v| flowey_lib_common::get_cargo_crate_version::Request {
71            path: vmgstool_path,
72            version: v,
73        });
74        let version = version.map(ctx, |v| v.unwrap_or("0.1.0".into()));
75        let tag = version.map(ctx, |v| format!("vmgstool-v{v}"));
76        let title = version.map(ctx, |v| format!("VmgsTool v{v}"));
77
78        let target = ctx.emit_rust_stepv("get current commit", |ctx| {
79            let openvmm_repo_path = openvmm_repo_path.claim(ctx);
80            move |rt| {
81                let path = rt.read(openvmm_repo_path);
82                rt.sh.change_dir(path);
83                let target = flowey::shell_cmd!(rt, "git rev-parse HEAD").read()?;
84                log::info!("current commit is {target}");
85                Ok(target)
86            }
87        });
88
89        ctx.req(flowey_lib_common::publish_gh_release::Request(
90            flowey_lib_common::publish_gh_release::GhReleaseParams {
91                repo_owner: "microsoft".into(),
92                repo_name: "openvmm".into(),
93                target,
94                tag,
95                title,
96                files,
97                notes: flowey_lib_common::publish_gh_release::GhReleaseNotes::Text("TODO".into()),
98                draft: true,
99                verify_tag: false,
100                // This job runs on every push to main, but the tag only
101                // changes when the version in the tree does, so an existing
102                // release is the normal steady state rather than a problem.
103                on_existing: flowey_lib_common::publish_gh_release::OnExistingRelease::Skip,
104                prerequisites: Vec::new(),
105                done,
106            },
107        ));
108
109        Ok(())
110    }
111}