feat: create drone templater action
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 01:41:33 +01:00
parent d9ea6162d4
commit 9ba98284ae
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394

View File

@ -11,3 +11,56 @@ pub mod cuddle_please;
pub mod cuddle_releaser; pub mod cuddle_releaser;
pub mod cuddle_x; pub mod cuddle_x;
pub mod dagger_middleware; 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<PathBuf>) -> 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(())
}
}
}