flowey_lib_common/
download_gh_artifact.rs1use flowey::node::prelude::*;
7
8flowey_request! {
9 pub struct Request {
10 pub repo_owner: String,
14 pub repo_name: String,
18 pub file_name: String,
20 pub path: WriteVar<PathBuf>,
22 pub run_id: ReadVar<String>,
24 pub gh_token: ReadVar<String>,
26 }
27}
28
29new_simple_flow_node!(struct Node);
30
31impl SimpleFlowNode for Node {
32 type Request = Request;
33
34 fn imports(ctx: &mut ImportCtx<'_>) {
35 ctx.import::<crate::cache::Node>();
36 ctx.import::<crate::use_gh_cli::Node>();
37 }
38
39 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
40 let Request {
41 repo_owner,
42 repo_name,
43 file_name,
44 path,
45 run_id,
46 gh_token,
47 } = request;
48
49 ctx.req(crate::use_gh_cli::Request::WithAuth(
50 crate::use_gh_cli::GhCliAuth::AuthToken(gh_token),
51 ));
52 let gh_cli = ctx.reqv(crate::use_gh_cli::Request::Get);
53
54 ctx.emit_rust_step("download artifacts from github actions run", |ctx| {
55 let gh_cli = gh_cli.claim(ctx);
56 let run_id = run_id.claim(ctx);
57 let path = path.claim(ctx);
58 move |rt| {
59 let sh = xshell::Shell::new()?;
60 let gh_cli = rt.read(gh_cli);
61 let run_id = rt.read(run_id);
62
63 let path_end = format!("{repo_owner}/{repo_name}/{run_id}");
64 let out_dir = std::env::current_dir()?.absolute()?.join(path_end);
65 fs_err::create_dir_all(&out_dir)?;
66 sh.change_dir(&out_dir);
67
68 xshell::cmd!(sh, "{gh_cli} run download {run_id} -R {repo_owner}/{repo_name} --pattern {file_name}").run()?;
69
70 if !out_dir.join(file_name).exists() {
71 anyhow::bail!("Failed to download artifact");
72 }
73
74 rt.write(path, &out_dir);
75 Ok(())
76 }
77 });
78
79 Ok(())
80 }
81}