From 9ba98284ae7fc23fbd0ef38c74ab848238fb527f Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 30 Mar 2024 01:41:33 +0100 Subject: [PATCH] feat: create drone templater action Signed-off-by: kjuulh --- crates/cuddle-ci/src/lib.rs | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/cuddle-ci/src/lib.rs b/crates/cuddle-ci/src/lib.rs index daec4e0..ce8a093 100644 --- a/crates/cuddle-ci/src/lib.rs +++ b/crates/cuddle-ci/src/lib.rs @@ -11,3 +11,56 @@ pub mod cuddle_please; pub mod cuddle_releaser; pub mod cuddle_x; pub mod dagger_middleware; +pub mod drone_templater { + use std::path::PathBuf; + + const DRONE_TEMPLATER_IMAGE: &str = "kasperhermansen/drone-templater:main-1711758171"; + + use async_trait::async_trait; + + use crate::MainAction; + + pub struct DroneTemplater { + client: dagger_sdk::Query, + template: PathBuf, + } + + impl DroneTemplater { + pub fn new(client: dagger_sdk::Query, template: impl Into) -> Self { + Self { + client: client.pipeline("drone-templater"), + template: template.into(), + } + } + } + + #[async_trait] + impl MainAction for DroneTemplater { + async fn execute_main(&self, _ctx: &mut crate::Context) -> eyre::Result<()> { + let src = client.host().directory(".cuddle/tmp/"); + + let drone_host = std::env::var("DRONE_HOST"); + let drone_user = std::env::var("DRONE_USER"); + let drone_token = std::env::var("DRONE_TOKEN"); + + let drone_token_secret = client.set_secret("DRONE_TOKEN", drone_token); + + client + .container() + .from(DRONE_TEMPLATER_IMAGE) + .with_directory("/src/templates", src) + .with_workdir("/src") + .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(), + ]); + + Ok(()) + } + } +}