Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
7a1ad63b57
commit
3c28b30f8f
@ -1,6 +1,7 @@
|
||||
use async_trait::async_trait;
|
||||
use dagger_sdk::Container;
|
||||
use std::{future::Future, pin::Pin};
|
||||
pub type DynMiddleware = Box<dyn DaggerMiddleware + Send + Sync>;
|
||||
|
||||
#[async_trait]
|
||||
pub trait DaggerMiddleware {
|
||||
|
@ -5,9 +5,12 @@ use dagger_rust::source::RustSource;
|
||||
use dagger_sdk::Container;
|
||||
use futures::{stream, StreamExt};
|
||||
|
||||
use crate::{dagger_middleware::DaggerMiddleware, MainAction, PullRequestAction};
|
||||
use crate::{
|
||||
dagger_middleware::{DaggerMiddleware, DynMiddleware},
|
||||
MainAction, PullRequestAction,
|
||||
};
|
||||
|
||||
pub type DynMiddleware = Box<dyn DaggerMiddleware + Send + Sync>;
|
||||
use self::architecture::{Architecture, Os};
|
||||
|
||||
pub enum RustServiceStage {
|
||||
BeforeDeps(DynMiddleware),
|
||||
@ -30,6 +33,8 @@ pub struct RustService {
|
||||
source: Option<PathBuf>,
|
||||
crates: Vec<String>,
|
||||
bin_name: String,
|
||||
arch: Option<Architecture>,
|
||||
os: Option<Os>,
|
||||
}
|
||||
|
||||
impl From<dagger_sdk::Query> for RustService {
|
||||
@ -42,6 +47,8 @@ impl From<dagger_sdk::Query> for RustService {
|
||||
source: None,
|
||||
crates: Vec::new(),
|
||||
bin_name: String::new(),
|
||||
arch: None,
|
||||
os: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,6 +63,8 @@ impl RustService {
|
||||
source: None,
|
||||
crates: Vec::new(),
|
||||
bin_name: String::new(),
|
||||
arch: None,
|
||||
os: None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -92,12 +101,44 @@ impl RustService {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_arch(&mut self, arch: Architecture) -> &mut Self {
|
||||
self.arch = Some(arch);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_os(&mut self, os: Os) -> &mut Self {
|
||||
self.os = Some(os);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn get_src(&self) -> PathBuf {
|
||||
self.source
|
||||
.clone()
|
||||
.unwrap_or(std::env::current_dir().unwrap())
|
||||
}
|
||||
|
||||
fn get_arch(&self) -> Architecture {
|
||||
self.arch
|
||||
.clone()
|
||||
.unwrap_or_else(|| match std::env::consts::ARCH {
|
||||
"x86" | "x86_64" | "amd64" => Architecture::Amd64,
|
||||
"arm" => Architecture::Arm64,
|
||||
arch => panic!("unsupported architecture: {arch}"),
|
||||
})
|
||||
}
|
||||
|
||||
fn get_os(&self) -> Os {
|
||||
self.os
|
||||
.clone()
|
||||
.unwrap_or_else(|| match std::env::consts::OS {
|
||||
"linux" => Os::Linux,
|
||||
"macos" => Os::MacOS,
|
||||
os => panic!("unsupported os: {os}"),
|
||||
})
|
||||
}
|
||||
|
||||
async fn run_stage(
|
||||
&self,
|
||||
stages: impl IntoIterator<Item = &Box<dyn DaggerMiddleware + Send + Sync>>,
|
||||
@ -278,24 +319,32 @@ impl MainAction for RustService {
|
||||
}
|
||||
|
||||
pub mod architecture {
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Architecture {
|
||||
Amd64,
|
||||
Arm64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Os {
|
||||
Linux,
|
||||
MacOS,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod apt;
|
||||
pub mod cargo_binstall;
|
||||
pub mod clap_sanity_test;
|
||||
pub mod mold;
|
||||
pub mod sqlx;
|
||||
mod apt;
|
||||
mod cargo_binstall;
|
||||
mod clap_sanity_test;
|
||||
mod mold;
|
||||
mod sqlx;
|
||||
|
||||
pub mod extensions {
|
||||
pub use super::apt::*;
|
||||
pub use super::cargo_binstall::*;
|
||||
pub use super::clap_sanity_test::*;
|
||||
pub use super::mold::*;
|
||||
pub use super::sqlx::*;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
@ -320,12 +369,14 @@ mod test {
|
||||
let root_dir = std::path::PathBuf::from("../../").canonicalize()?;
|
||||
|
||||
let container = RustService::from(client.clone())
|
||||
.with_arch(Architecture::Amd64)
|
||||
.with_os(Os::Linux)
|
||||
.with_apt(&["git"])
|
||||
.with_cargo_binstall(Architecture::Amd64, Os::Linux, "latest", ["sqlx-cli"])
|
||||
.with_cargo_binstall("latest", ["sqlx-cli"])
|
||||
.with_source(root_dir)
|
||||
.with_bin_name("ci")
|
||||
.with_crates(["crates/*", "examples/*", "ci"])
|
||||
.with_mold(Architecture::Amd64, Os::Linux, "2.3.3")
|
||||
.with_mold("2.3.3")
|
||||
.with_stage(RustServiceStage::BeforeDeps(middleware(|c| {
|
||||
async move {
|
||||
// Noop
|
||||
|
@ -83,8 +83,6 @@ impl DaggerMiddleware for CargoBInstall {
|
||||
pub trait CargoBInstallExt {
|
||||
fn with_cargo_binstall(
|
||||
&mut self,
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
crates: impl IntoIterator<Item = impl Into<String>>,
|
||||
) -> &mut Self {
|
||||
@ -95,15 +93,13 @@ pub trait CargoBInstallExt {
|
||||
impl CargoBInstallExt for RustService {
|
||||
fn with_cargo_binstall(
|
||||
&mut self,
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
crates: impl IntoIterator<Item = impl Into<String>>,
|
||||
) -> &mut Self {
|
||||
let crates: Vec<String> = crates.into_iter().map(|s| s.into()).collect();
|
||||
|
||||
self.with_stage(super::RustServiceStage::BeforeDeps(
|
||||
Box::new(CargoBInstall::new(arch, os, version, crates))
|
||||
Box::new(CargoBInstall::new(self.get_arch(), self.get_os(), version, crates))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -88,25 +88,15 @@ impl DaggerMiddleware for MoldInstall {
|
||||
}
|
||||
|
||||
pub trait MoldActionExt {
|
||||
fn with_mold(
|
||||
&mut self,
|
||||
architecture: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
) -> &mut Self {
|
||||
fn with_mold(&mut self, version: impl Into<String>) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl MoldActionExt for RustService {
|
||||
fn with_mold(
|
||||
&mut self,
|
||||
architecture: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
) -> &mut Self {
|
||||
fn with_mold(&mut self, version: impl Into<String>) -> &mut Self {
|
||||
self.with_stage(super::RustServiceStage::AfterDeps(
|
||||
Box::new(MoldInstall::new(architecture, os, version))
|
||||
Box::new(MoldInstall::new(self.get_arch(), self.get_os(), version))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user