use async_trait::async_trait; use dagger_sdk::Container; use crate::{dagger_middleware::DaggerMiddleware, MainAction, PullRequestAction}; pub type DynMiddleware = Box; pub enum RustServiceStage { BeforeDeps(DynMiddleware), AfterDeps(DynMiddleware), BeforeBase(DynMiddleware), AfterBase(DynMiddleware), BeforeRelease(DynMiddleware), AfterRelease(DynMiddleware), } pub struct RustService { client: dagger_sdk::Query, base_image: Option, stages: Vec, } impl From for RustService { fn from(value: dagger_sdk::Query) -> Self { Self { client: value, base_image: None, stages: Vec::new(), } } } impl RustService { pub async fn new() -> eyre::Result { Ok(Self { client: dagger_sdk::connect().await?, base_image: None, stages: Vec::new(), }) } pub fn with_base_image(&mut self, base: dagger_sdk::Container) -> &mut Self { self.base_image = Some(base); self } pub fn with_stage(&mut self, _stage: RustServiceStage) -> &mut Self { self } pub fn with_sqlx(&mut self) -> &mut Self { self } pub async fn build_release(&self) -> eyre::Result> { Ok(Vec::new()) } } #[async_trait] impl PullRequestAction for RustService { async fn execute_pull_request(&self) -> eyre::Result<()> { self.build_release().await?; Ok(()) } } #[async_trait] impl MainAction for RustService { async fn execute_main(&self) -> eyre::Result<()> { Ok(()) } } #[cfg(test)] mod test { use futures::FutureExt; use crate::{ dagger_middleware::middleware, rust_service::{RustService, RustServiceStage}, }; #[tokio::test] async fn can_build_rust() -> eyre::Result<()> { let client = dagger_sdk::connect().await?; RustService::from(client.clone()) .with_base_image(client.container().from("rustlang/rust:nightly")) .with_sqlx() .with_stage(RustServiceStage::BeforeDeps(middleware(|c| async move { Ok(c) }.boxed()))) .build_release() .await?; Ok(()) } }