flowey_lib_hvlite/_jobs/
consolidate_and_publish_gh_pages.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Consolidate various pre-built HTML artifacts (guide, docs, etc...), and glue
5//! them together into a single HTML bundle which can be published to
6//! `openvmm.dev` via gh pages.
7
8use crate::build_guide::GuideOutput;
9use crate::build_rustdoc::RustdocOutput;
10use flowey::node::prelude::*;
11
12flowey_request! {
13    pub struct Params {
14        pub rustdoc_linux: ReadVar<RustdocOutput>,
15        pub rustdoc_windows: ReadVar<RustdocOutput>,
16        pub guide: ReadVar<GuideOutput>,
17        pub output: WriteVar<GhPagesOutput>,
18    }
19}
20
21#[derive(Serialize, Deserialize)]
22pub struct GhPagesOutput {
23    pub gh_pages: PathBuf,
24}
25
26impl Artifact for GhPagesOutput {}
27
28new_simple_flow_node!(struct Node);
29
30impl SimpleFlowNode for Node {
31    type Request = Params;
32
33    fn imports(ctx: &mut ImportCtx<'_>) {
34        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
35        ctx.import::<crate::_jobs::build_test_results_website::Node>();
36    }
37
38    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
39        let Params {
40            rustdoc_linux,
41            rustdoc_windows,
42            guide: rendered_guide,
43            output,
44        } = request;
45
46        let repo = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
47        let logview_new_build =
48            ctx.reqv(|v| crate::_jobs::build_test_results_website::Request { path: v });
49
50        let consolidated_html = ctx.emit_rust_stepv("generate consolidated gh pages html", |ctx| {
51            let rendered_guide = rendered_guide.claim(ctx);
52            let rustdoc_windows = rustdoc_windows.claim(ctx);
53            let rustdoc_linux = rustdoc_linux.claim(ctx);
54            let repo = repo.claim(ctx);
55            let logview_new_build = logview_new_build.claim(ctx);
56            |rt| {
57                let rendered_guide = rt.read(rendered_guide);
58                let rustdoc_windows = rt.read(rustdoc_windows);
59                let rustdoc_linux = rt.read(rustdoc_linux);
60                let repo = rt.read(repo);
61                let logview_new_build = rt.read(logview_new_build);
62
63                let consolidated_html = std::env::current_dir()?.join("out").absolute()?;
64                fs_err::create_dir(&consolidated_html)?;
65
66                // DEVNOTE: Please try to keep this top-level structure stable!
67                //
68                // As the project grows, its quite likely more external websites
69                // will be linking to specific pages under `openvmm.dev`. Lets
70                // do our best to avoid linkrot, and if we are moving things
71                // around, lets make sure to add appropriate redirects whenever
72                // we can.
73
74                // Make the OpenVMM Guide accessible under `openvmm.dev/guide/`
75                flowey_lib_common::_util::copy_dir_all(
76                    rendered_guide.guide,
77                    consolidated_html.join("guide"),
78                )?;
79
80                // Make rustdocs accessible under `openvmm.dev/rustdoc/{platform}`
81                flowey_lib_common::_util::copy_dir_all(
82                    rustdoc_windows.docs,
83                    consolidated_html.join("rustdoc/windows"),
84                )?;
85                flowey_lib_common::_util::copy_dir_all(
86                    rustdoc_linux.docs,
87                    consolidated_html.join("rustdoc/linux"),
88                )?;
89
90                // Old logviewer. Keeping this around while the new one is stabilized.
91                flowey_lib_common::_util::copy_dir_all(
92                    repo.join("petri/logview"),
93                    consolidated_html.join("test-results-old"),
94                )?;
95
96                // New logviewer (built in CI).
97                flowey_lib_common::_util::copy_dir_all(
98                    logview_new_build,
99                    consolidated_html.join("test-results"),
100                )?;
101
102                // as we do not currently have any form of "landing page",
103                // redirect `openvmm.dev` to `openvmm.dev/guide`
104                fs_err::write(consolidated_html.join("index.html"), REDIRECT)?;
105
106                Ok(consolidated_html)
107            }
108        });
109
110        let consolidated_html = if matches!(ctx.backend(), FlowBackend::Github) {
111            let did_upload = ctx
112                .emit_gh_step("Upload pages artifact", "actions/upload-pages-artifact@v3")
113                .with(
114                    "path",
115                    consolidated_html.map(ctx, |x| x.display().to_string()),
116                )
117                .finish(ctx);
118
119            let did_deploy = ctx
120                .emit_gh_step("Deploy to GitHub Pages", "actions/deploy-pages@v4")
121                .requires_permission(GhPermission::IdToken, GhPermissionValue::Write)
122                .requires_permission(GhPermission::Pages, GhPermissionValue::Write)
123                .run_after(did_upload)
124                .finish(ctx);
125
126            consolidated_html.depending_on(ctx, &did_deploy)
127        } else {
128            consolidated_html
129        };
130
131        consolidated_html.write_into(ctx, output, |p| GhPagesOutput { gh_pages: p });
132        Ok(())
133    }
134}
135
136const REDIRECT: &str = r#"
137<!DOCTYPE html>
138<html>
139<head>
140    <title>Redirecting...</title>
141    <link rel="canonical" href="/guide"/>
142    <meta charset="utf-8"/>
143    <meta http-equiv="refresh" content="0; url=/guide">
144</head>
145<body>
146    <p>If you are not redirected automatically, follow this <a href="/guide">link to openvmm.dev/guide</a>.</p>
147</body>
148</html>
149"#;