From 855e1cbb693d5e00a87c85df7c4a8350148fbd09 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Mon, 17 Jun 2024 11:51:06 +0000 Subject: [PATCH] update example --- example/.fluentci/plugin/src/helpers.rs | 21 ++++++++++----------- example/.fluentci/plugin/src/lib.rs | 24 +++++++----------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/example/.fluentci/plugin/src/helpers.rs b/example/.fluentci/plugin/src/helpers.rs index e5965d8..ea0eaeb 100644 --- a/example/.fluentci/plugin/src/helpers.rs +++ b/example/.fluentci/plugin/src/helpers.rs @@ -1,19 +1,18 @@ use anyhow::Error; use fluentci_pdk::dag; -pub fn setup_swift(version: String) -> Result { - let mut version = version; - if version.is_empty() { - version = "5.7".into(); - } +pub fn setup_swift() -> Result { + let path = dag().get_env("PATH")?; + + dag().set_envs(vec![( + "PATH".into(), + format!("/home/linuxbrew/.linuxbrew/bin:{}", path), + )])?; let stdout = dag() - .devbox()? - .with_exec(vec!["[ -f devbox.json ] || devbox init"])? - .with_exec(vec![&format!( - "grep -q 'swift' devbox.json || devbox add swift@{} swiftpm", - version - )])? + .pipeline("setup")? + .with_exec(vec![r#"type brew > /dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)""#])? + .with_exec(vec!["type swift > /dev/null || brew install swift"])? .stdout()?; Ok(stdout) } diff --git a/example/.fluentci/plugin/src/lib.rs b/example/.fluentci/plugin/src/lib.rs index b87edb2..abe57f3 100644 --- a/example/.fluentci/plugin/src/lib.rs +++ b/example/.fluentci/plugin/src/lib.rs @@ -8,37 +8,27 @@ use crate::helpers::setup_swift; pub mod helpers; #[plugin_fn] -pub fn setup(version: String) -> FnResult { - let stdout = setup_swift(version)?; +pub fn setup() -> FnResult { + let stdout = setup_swift()?; Ok(stdout) } #[plugin_fn] pub fn build(args: String) -> FnResult { - let mut version = dag().get_env("SWIFT_VERSION").unwrap_or_default(); - if version.is_empty() { - version = "5.7".into(); - } - - setup_swift(version)?; + setup_swift()?; let stdout = dag() - .devbox()? - .with_exec(vec!["devbox run -- swift build", &args])? + .pipeline("build")? + .with_exec(vec!["swift", "build", &args])? .stdout()?; Ok(stdout) } #[plugin_fn] pub fn test(args: String) -> FnResult { - let mut version = dag().get_env("SWIFT_VERSION").unwrap_or_default(); - if version.is_empty() { - version = "5.7".into(); - } - - setup_swift(version)?; + setup_swift()?; let stdout = dag() .devbox()? - .with_exec(vec!["devbox run -- swift test", &args])? + .with_exec(vec!["swift", "test", &args])? .stdout()?; Ok(stdout) }