Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jun 17, 2024
1 parent 5eb3036 commit 855e1cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
21 changes: 10 additions & 11 deletions example/.fluentci/plugin/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use anyhow::Error;
use fluentci_pdk::dag;

pub fn setup_swift(version: String) -> Result<String, Error> {
let mut version = version;
if version.is_empty() {
version = "5.7".into();
}
pub fn setup_swift() -> Result<String, Error> {
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)
}
24 changes: 7 additions & 17 deletions example/.fluentci/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,27 @@ use crate::helpers::setup_swift;
pub mod helpers;

#[plugin_fn]
pub fn setup(version: String) -> FnResult<String> {
let stdout = setup_swift(version)?;
pub fn setup() -> FnResult<String> {
let stdout = setup_swift()?;
Ok(stdout)
}

#[plugin_fn]
pub fn build(args: String) -> FnResult<String> {
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<String> {
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)
}

0 comments on commit 855e1cb

Please sign in to comment.