diff --git a/crates/cuddle-ci/src/drone_templater.rs b/crates/cuddle-ci/src/drone_templater.rs index 9b9f4c4..4cd99a7 100644 --- a/crates/cuddle-ci/src/drone_templater.rs +++ b/crates/cuddle-ci/src/drone_templater.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, time::UNIX_EPOCH}; +use std::{collections::BTreeMap, path::PathBuf, time::UNIX_EPOCH}; const DRONE_TEMPLATER_IMAGE: &str = "kasperhermansen/drone-templater:main-1711807810"; @@ -10,6 +10,8 @@ use crate::MainAction; pub struct DroneTemplater { client: dagger_sdk::Query, template: PathBuf, + + variables: BTreeMap, } impl DroneTemplater { @@ -17,8 +19,19 @@ impl DroneTemplater { Self { client: client.pipeline("drone-templater"), template: template.into(), + variables: BTreeMap::default(), } } + + pub fn with_variable( + &mut self, + name: impl Into, + value: impl Into, + ) -> &mut Self { + self.variables.insert(name.into(), value.into()); + + self + } } #[async_trait] @@ -36,6 +49,18 @@ impl MainAction for DroneTemplater { .duration_since(UNIX_EPOCH) .context("failed to get system time")?; + let template_name = self.template.display().to_string(); + + let mut cmd = vec!["drone-templater", "upload", "--template", &template_name] + .into_iter() + .map(|v| v.to_string()) + .chain( + self.variables + .iter() + .map(|(name, value)| format!(r#"--variable='{name}={value}'"#)), + ) + .collect::>(); + self.client .container() .from(DRONE_TEMPLATER_IMAGE) @@ -45,12 +70,7 @@ impl MainAction for DroneTemplater { .with_env_variable("DRONE_HOST", drone_host) .with_env_variable("DRONE_USER", drone_user) .with_secret_variable("DRONE_TOKEN", drone_token_secret) - .with_exec(vec![ - "drone-templater", - "upload", - "--template", - &self.template.display().to_string(), - ]) + .with_exec(cmd) .sync() .await .context("failed to upload drone templates with error")?;