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 }
25}
26
27new_simple_flow_node!(struct Node);
28
29impl SimpleFlowNode for Node {
30 type Request = Request;
31
32 fn imports(ctx: &mut ImportCtx<'_>) {
33 ctx.import::<crate::cache::Node>();
34 ctx.import::<crate::use_gh_cli::Node>();
35 }
36
37 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
38 let Request {
39 repo_owner,
40 repo_name,
41 file_name,
42 path,
43 run_id,
44 } = request;
45
46 let gh_cli = ctx.reqv(crate::use_gh_cli::Request::Get);
47
48 ctx.emit_rust_step("download artifacts from github actions run", |ctx| {
49 let gh_cli = gh_cli.claim(ctx);
50 let run_id = run_id.claim(ctx);
51 let path = path.claim(ctx);
52 move |rt| {
53 let gh_cli = rt.read(gh_cli);
54 let run_id = rt.read(run_id);
55
56 let path_end = format!("{repo_owner}/{repo_name}/{run_id}");
57 let out_dir = std::env::current_dir()?.absolute()?.join(path_end);
58 fs_err::create_dir_all(&out_dir)?;
59 rt.sh.change_dir(&out_dir);
60
61 flowey::shell_cmd!(rt, "{gh_cli} run download {run_id} -R {repo_owner}/{repo_name} --pattern {file_name}").run()?;
62
63 if !out_dir.join(file_name).exists() {
64 anyhow::bail!("Failed to download artifact");
65 }
66
67 rt.write(path, &out_dir);
68 Ok(())
69 }
70 });
71
72 Ok(())
73 }
74}