diff --git a/_examples/actions/write_a_readme/dist/bin b/_examples/actions/write_a_readme/dist/bin new file mode 100755 index 0000000..0f3982a Binary files /dev/null and b/_examples/actions/write_a_readme/dist/bin differ diff --git a/_examples/actions/write_a_readme/main.go b/_examples/actions/write_a_readme/main.go index 5c24133..a652402 100644 --- a/_examples/actions/write_a_readme/main.go +++ b/_examples/actions/write_a_readme/main.go @@ -6,6 +6,8 @@ func main() { _, err := script. Echo("# Readme"). WriteFile("README.md") + + println("i did something!") if err != nil { panic(err) } diff --git a/crates/octopush_core/src/builder/builders/golang_bin.rs b/crates/octopush_core/src/builder/builders/golang_bin.rs index 7acab58..10cbfa8 100644 --- a/crates/octopush_core/src/builder/builders/golang_bin.rs +++ b/crates/octopush_core/src/builder/builders/golang_bin.rs @@ -2,10 +2,7 @@ use std::path::PathBuf; use async_trait::async_trait; -use crate::{ - builder::RunnableBin, - shell::{execute_shell, print_res}, -}; +use crate::{builder::RunnableBin, shell::execute_shell}; pub struct GolangBinBuildOpts { pub entry: String, @@ -26,14 +23,15 @@ impl GolangBinBuild { "build golang_bin" ); - let res = execute_shell( - format!("go build {}", opts.entry), + execute_shell( + format!("go build -o dist/bin {}", opts.entry), Some(opts.src_path.clone()), ) .await?; - print_res("golang_bin".into(), res); - Ok(GolangBin::new(opts.src_path)) + let abs_path = std::fs::canonicalize(opts.src_path.join("dist/bin"))?; + + Ok(GolangBin::new(abs_path)) } } @@ -49,7 +47,9 @@ impl GolangBin { #[async_trait] impl RunnableBin for GolangBin { - async fn run(&self) -> eyre::Result<()> { - todo!("not implemented") + async fn run(&self, victim_path: PathBuf) -> eyre::Result<()> { + execute_shell(self.path.to_string_lossy().to_string(), Some(victim_path)).await?; + + Ok(()) } } diff --git a/crates/octopush_core/src/builder/mod.rs b/crates/octopush_core/src/builder/mod.rs index e3e7931..c22c629 100644 --- a/crates/octopush_core/src/builder/mod.rs +++ b/crates/octopush_core/src/builder/mod.rs @@ -9,7 +9,7 @@ use crate::schema::models::Action; #[async_trait] pub trait RunnableBin { - async fn run(&self) -> eyre::Result<()>; + async fn run(&self, victim_path: PathBuf) -> eyre::Result<()>; } pub type DynRunnableBin = Arc; diff --git a/crates/octopush_core/src/executor/default_executor.rs b/crates/octopush_core/src/executor/default_executor.rs index a23bce1..324fc25 100644 --- a/crates/octopush_core/src/executor/default_executor.rs +++ b/crates/octopush_core/src/executor/default_executor.rs @@ -31,11 +31,7 @@ impl Executor for DefaultExecutor { match action { Action::Go { entry } => { GolangExecutor::new() - .execute(GolangExecutorOpts { - bin, - entry, - src_path: victim_path, - }) + .execute(GolangExecutorOpts { bin, victim_path }) .await? } } diff --git a/crates/octopush_core/src/executor/executors/golang.rs b/crates/octopush_core/src/executor/executors/golang.rs index d9b8b2a..af6c7a8 100644 --- a/crates/octopush_core/src/executor/executors/golang.rs +++ b/crates/octopush_core/src/executor/executors/golang.rs @@ -4,8 +4,7 @@ use crate::builder::DynRunnableBin; pub struct GolangExecutorOpts { pub bin: DynRunnableBin, - pub entry: String, - pub src_path: PathBuf, + pub victim_path: PathBuf, } pub struct GolangExecutor; @@ -16,6 +15,8 @@ impl GolangExecutor { } pub async fn execute(&self, opts: GolangExecutorOpts) -> eyre::Result<()> { + opts.bin.run(opts.victim_path).await?; + Ok(()) } } diff --git a/crates/octopush_core/src/shell/mod.rs b/crates/octopush_core/src/shell/mod.rs index 5159f3f..ea5d588 100644 --- a/crates/octopush_core/src/shell/mod.rs +++ b/crates/octopush_core/src/shell/mod.rs @@ -3,7 +3,7 @@ use std::{path::PathBuf, process::Stdio}; use eyre::Context; use tokio::io::{AsyncBufReadExt, BufReader}; -pub async fn execute_shell(cmd: String, path: Option) -> eyre::Result> { +pub async fn execute_shell(cmd: String, path: Option) -> eyre::Result<()> { let mut command = tokio::process::Command::new("sh"); let command = command.arg("-c"); @@ -42,16 +42,9 @@ pub async fn execute_shell(cmd: String, path: Option) -> eyre::Result = Vec::new(); while let Some(line) = reader.next_line().await? { - lines.push(line) + tracing::trace!("{}", line) } - Ok(lines) -} - -pub fn print_res(scope: String, res: Vec) { - for r in res { - tracing::debug!("{}: {}", scope, r); - } + Ok(()) }