From 326a43e93cb27c6f1cdb14e82534f6f926e1b724 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 26 Oct 2024 00:23:17 +0200 Subject: [PATCH] feat: with further rust build actions Signed-off-by: kjuulh --- Cargo.lock | 336 +++++++++++++++++- crates/cuddle-actions/src/lib.rs | 7 +- crates/cuddle/Cargo.toml | 4 + .../actions/project/actions/rust/Cargo.toml | 2 +- .../actions/project/actions/rust/src/main.rs | 2 - crates/cuddle/src/actions.rs | 135 ++++++- 6 files changed, 460 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8f6172..442630d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "action" +version = "0.1.0" +dependencies = [ + "anyhow", + "cuddle-actions 0.1.0 (git+ssh://git@git.front.kjuulh.io/kjuulh/cuddle-v2)", + "tokio", +] + [[package]] name = "addr2line" version = "0.22.0" @@ -53,7 +62,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -63,7 +72,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -72,6 +81,29 @@ version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "async-trait" +version = "0.1.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -99,6 +131,28 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "blake3" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82033247fd8e890df8f740e407ad4d038debb9eb1f40533fffb32e7d17dc6f7" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bytes" version = "1.7.1" @@ -166,21 +220,50 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "cuddle" version = "0.1.0" dependencies = [ "anyhow", + "blake3", "clap", + "dirs", "dotenv", "fs_extra", "serde", "serde_json", + "sha256", "tokio", "toml", "tracing", "tracing-subscriber", "uuid", + "walkdir", ] [[package]] @@ -211,6 +294,37 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -229,6 +343,16 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -264,6 +388,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "indexmap" version = "2.4.0" @@ -298,6 +428,16 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + [[package]] name = "lock_api" version = "0.4.12" @@ -338,7 +478,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -366,6 +506,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "overload" version = "0.1.1" @@ -392,7 +538,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -439,12 +585,14 @@ dependencies = [ ] [[package]] -name = "rust" -version = "0.1.0" +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ - "anyhow", - "cuddle-actions 0.1.0 (git+ssh://git@git.front.kjuulh.io/kjuulh/cuddle-v2)", - "tokio", + "getrandom", + "libredox", + "thiserror", ] [[package]] @@ -459,6 +607,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -506,6 +663,30 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha256" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0" +dependencies = [ + "async-trait", + "bytes", + "hex", + "sha2", + "tokio", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -543,7 +724,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -563,6 +744,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "thiserror" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -588,7 +789,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -694,6 +895,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" @@ -721,6 +928,22 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -743,19 +966,52 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -764,28 +1020,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -798,24 +1072,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/crates/cuddle-actions/src/lib.rs b/crates/cuddle-actions/src/lib.rs index 5e1b77e..106dbb7 100644 --- a/crates/cuddle-actions/src/lib.rs +++ b/crates/cuddle-actions/src/lib.rs @@ -20,6 +20,11 @@ struct ActionSchema<'a> { description: Option<&'a str>, } +#[derive(Clone, Debug, Serialize)] +struct ActionsSchema<'a> { + actions: Vec>, +} + #[derive(Default)] pub struct CuddleActions { actions: BTreeMap, @@ -113,7 +118,7 @@ impl CuddleActions { }) .collect::>(); - let output = serde_json::to_string_pretty(&schema)?; + let output = serde_json::to_string_pretty(&ActionsSchema { actions: schema })?; Ok(output) } diff --git a/crates/cuddle/Cargo.toml b/crates/cuddle/Cargo.toml index 718e49a..d40ee30 100644 --- a/crates/cuddle/Cargo.toml +++ b/crates/cuddle/Cargo.toml @@ -17,3 +17,7 @@ uuid.workspace = true toml = "0.8.19" fs_extra = "1.3.0" +dirs = "5.0.1" +walkdir = "2.5.0" +sha256 = "1.5.0" +blake3 = "1.5.4" diff --git a/crates/cuddle/examples/actions/project/actions/rust/Cargo.toml b/crates/cuddle/examples/actions/project/actions/rust/Cargo.toml index 2afb665..f223067 100644 --- a/crates/cuddle/examples/actions/project/actions/rust/Cargo.toml +++ b/crates/cuddle/examples/actions/project/actions/rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust" +name = "action" version = "0.1.0" edition = "2021" diff --git a/crates/cuddle/examples/actions/project/actions/rust/src/main.rs b/crates/cuddle/examples/actions/project/actions/rust/src/main.rs index 9f27314..76acd8e 100644 --- a/crates/cuddle/examples/actions/project/actions/rust/src/main.rs +++ b/crates/cuddle/examples/actions/project/actions/rust/src/main.rs @@ -2,8 +2,6 @@ use cuddle_actions::AddActionOptions; #[tokio::main] async fn main() -> anyhow::Result<()> { - println!("Hello, world!"); - cuddle_actions::CuddleActions::default() .add_action("something", || Ok(()), &AddActionOptions::default()) .execute()?; diff --git a/crates/cuddle/src/actions.rs b/crates/cuddle/src/actions.rs index c8e17de..befe656 100644 --- a/crates/cuddle/src/actions.rs +++ b/crates/cuddle/src/actions.rs @@ -4,13 +4,17 @@ use std::{ }; use rust_builder::RustActionsBuilder; +use serde::{Deserialize, Serialize}; use crate::state::validated_project::Value; pub mod builder; pub mod rust_builder { - use std::path::PathBuf; + use std::{ + env::temp_dir, + path::{Path, PathBuf}, + }; use super::ExecutableActions; @@ -23,8 +27,131 @@ pub mod rust_builder { Self { root_path } } + fn actions_path(&self) -> Option { + let actions_path = self.root_path.join("actions/rust"); + if !actions_path.exists() { + return None; + } + + Some(actions_path) + } + + fn global_registry(&self) -> anyhow::Result> { + if let Some(dir) = dirs::cache_dir().map(|c| c.join("sh.cuddle/registry/actions/rust")) + { + if !dir.exists() { + std::fs::create_dir_all(&dir)?; + } + + Ok(Some(dir)) + } else { + Ok(None) + } + } + pub async fn build(&self) -> anyhow::Result { - Ok(ExecutableActions::default()) + tracing::debug!("building rust action: {}", self.root_path.display()); + + let Some(path) = self.actions_path() else { + anyhow::bail!( + "action was not found: {}", + self.root_path.display().to_string() + ); + }; + + let actions_registry = self + .global_registry()? + .ok_or(anyhow::anyhow!("failed to find global registry"))?; + + let staging_id = uuid::Uuid::new_v4(); + let actions_temp = temp_dir() + .join("cuddle/actions") + .join(staging_id.to_string()); + std::fs::create_dir_all(&actions_temp)?; + + let mut hasher = blake3::Hasher::new(); + + tracing::debug!("moving file into: {}", actions_temp.display()); + for entry in walkdir::WalkDir::new(&path) { + let entry = entry?; + let full_path = entry.path(); + let rel_path = full_path + .strip_prefix(path.canonicalize()?.to_string_lossy().to_string())? + .to_string_lossy(); + + if rel_path.contains("target/") + || rel_path.contains(".cuddle/") + || rel_path.contains(".git/") + { + continue; + } + + let metadata = entry.metadata()?; + if metadata.is_file() { + let temp_file_path = actions_temp.join(rel_path.to_string()); + + if let Some(temp_parent) = temp_file_path.parent() { + std::fs::create_dir_all(temp_parent)?; + } + + std::fs::copy(entry.path(), temp_file_path)?; + + hasher.update(entry.path().to_string_lossy().as_bytes()); + let file_bytes = tokio::fs::read(entry.path()).await?; + hasher.update(&file_bytes); + } + } + let digest = hasher.finalize().to_hex().to_string(); + + let action_index = actions_registry.join(digest); + if action_index.exists() { + tracing::debug!("action already exists in: {}", action_index.display()); + + return self.get_actions(&action_index.join("action")).await; + } + std::fs::create_dir_all(&action_index)?; + + tracing::debug!("building rust code: {}", actions_temp.display()); + let mut cmd = tokio::process::Command::new("cargo"); + let output = cmd + .args(vec!["build", "--release"]) + .current_dir(&actions_temp) + .output() + .await?; + if !output.status.success() { + anyhow::bail!( + "cargo build failed: {}", + std::str::from_utf8(&output.stderr)? + ); + } + + let temp_file_bin_path = actions_temp.join("target/release/action"); + tokio::fs::copy(temp_file_bin_path, action_index.join("action")).await?; + + self.get_actions(&action_index.join("action")).await + } + + pub async fn get_actions(&self, action_path: &Path) -> anyhow::Result { + tracing::debug!("querying schema: {}", action_path.display()); + let output = tokio::process::Command::new(action_path.to_string_lossy().to_string()) + .arg("schema") + .output() + .await?; + + let actions: ExecutableActions = match serde_json::from_slice(&output.stdout) { + Ok(output) => output, + Err(e) => { + let schema_output = std::str::from_utf8(&output.stdout)?; + + anyhow::bail!( + "failed to query schema: {} {}", + e.to_string(), + schema_output + ) + } + }; + + Ok(actions) } } } @@ -76,17 +203,19 @@ pub enum ActionVariant { Docker, } -#[derive(Default)] +#[derive(Default, Serialize, Deserialize)] pub struct ExecutableActions { actions: Vec, } +#[derive(Debug, Serialize, Deserialize)] pub struct ExecutableAction { name: String, description: String, flags: BTreeMap, } +#[derive(Debug, Serialize, Deserialize)] pub enum ExecutableActionFlag { String, Bool,