feat: make sure to add values property
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-03-30 15:26:13 +01:00
parent 9aa3e88b32
commit e479c79cc9
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394

View File

@ -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<String, String>,
}
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<String>,
value: impl Into<String>,
) -> &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::<Vec<_>>();
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")?;