Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
124aa93b98
commit
80b99c27a5
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -326,6 +326,7 @@ version = "0.2.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"clap",
|
"clap",
|
||||||
|
"dagger-cuddle-please",
|
||||||
"dagger-rust",
|
"dagger-rust",
|
||||||
"dagger-sdk",
|
"dagger-sdk",
|
||||||
"eyre",
|
"eyre",
|
||||||
|
@ -11,6 +11,7 @@ repository.workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dagger-rust.workspace = true
|
dagger-rust.workspace = true
|
||||||
|
dagger-cuddle-please.workspace = true
|
||||||
|
|
||||||
dagger-sdk.workspace = true
|
dagger-sdk.workspace = true
|
||||||
eyre.workspace = true
|
eyre.workspace = true
|
||||||
|
@ -4,9 +4,9 @@ use async_trait::async_trait;
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
pub struct CuddleCI {
|
pub struct CuddleCI {
|
||||||
pr_action: Arc<Mutex<dyn PullRequestAction + Send + Sync>>,
|
pr_action: Vec<Arc<Mutex<dyn PullRequestAction + Send + Sync>>>,
|
||||||
main_action: Arc<Mutex<dyn MainAction + Send + Sync>>,
|
main_action: Vec<Arc<Mutex<dyn MainAction + Send + Sync>>>,
|
||||||
release_action: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
release_action: Vec<Arc<Mutex<dyn ReleaseAction + Send + Sync>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CuddleCI {
|
impl CuddleCI {
|
||||||
@ -16,9 +16,9 @@ impl CuddleCI {
|
|||||||
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pr_action: pr,
|
pr_action: vec![pr],
|
||||||
main_action: main,
|
main_action: vec![main],
|
||||||
release_action: release,
|
release_action: vec![release],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,13 +26,13 @@ impl CuddleCI {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pr: Arc<Mutex<dyn PullRequestAction + Send + Sync>>,
|
pr: Arc<Mutex<dyn PullRequestAction + Send + Sync>>,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.pr_action = pr;
|
self.pr_action.push(pr);
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_main(&mut self, main: Arc<Mutex<dyn MainAction + Send + Sync>>) -> &mut Self {
|
pub fn with_main(&mut self, main: Arc<Mutex<dyn MainAction + Send + Sync>>) -> &mut Self {
|
||||||
self.main_action = main;
|
self.main_action.push(main);
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ impl CuddleCI {
|
|||||||
&mut self,
|
&mut self,
|
||||||
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
release: Arc<Mutex<dyn ReleaseAction + Send + Sync>>,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.release_action = release;
|
self.release_action.push(release);
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -62,17 +62,23 @@ impl CuddleCI {
|
|||||||
Some((name, args)) => match (name, args) {
|
Some((name, args)) => match (name, args) {
|
||||||
("pr", _args) => {
|
("pr", _args) => {
|
||||||
eprintln!("starting pr validate");
|
eprintln!("starting pr validate");
|
||||||
self.pr_action.lock().await.execute_pull_request().await?;
|
for pr_action in self.pr_action.iter() {
|
||||||
|
pr_action.lock().await.execute_pull_request().await?;
|
||||||
|
}
|
||||||
eprintln!("finished pr validate");
|
eprintln!("finished pr validate");
|
||||||
}
|
}
|
||||||
("main", _args) => {
|
("main", _args) => {
|
||||||
eprintln!("starting main validate");
|
eprintln!("starting main validate");
|
||||||
self.main_action.lock().await.execute_main().await?;
|
for main_action in self.main_action.iter() {
|
||||||
|
main_action.lock().await.execute_main().await?;
|
||||||
|
}
|
||||||
eprintln!("finished main validate");
|
eprintln!("finished main validate");
|
||||||
}
|
}
|
||||||
("release", _args) => {
|
("release", _args) => {
|
||||||
eprintln!("starting release validate");
|
eprintln!("starting release validate");
|
||||||
self.release_action.lock().await.execute_release().await?;
|
for release_action in self.release_action.iter() {
|
||||||
|
release_action.lock().await.execute_release().await?;
|
||||||
|
}
|
||||||
eprintln!("finished release validate");
|
eprintln!("finished release validate");
|
||||||
}
|
}
|
||||||
(command_name, _) => {
|
(command_name, _) => {
|
||||||
@ -110,15 +116,16 @@ impl PullRequestAction for DefaultPullRequestAction {}
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait MainAction {
|
pub trait MainAction {
|
||||||
async fn execute_main(&self) -> eyre::Result<()> {
|
async fn execute_main(&self) -> eyre::Result<()>;
|
||||||
eprintln!("validate main: noop");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DefaultMainAction {}
|
pub struct DefaultMainAction {}
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl MainAction for DefaultMainAction {}
|
impl MainAction for DefaultMainAction {
|
||||||
|
async fn execute_main(&self) -> eyre::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ReleaseAction {
|
pub trait ReleaseAction {
|
||||||
|
@ -6,3 +6,43 @@ pub mod dagger_middleware;
|
|||||||
pub mod node_service;
|
pub mod node_service;
|
||||||
pub mod rust_lib;
|
pub mod rust_lib;
|
||||||
pub mod rust_service;
|
pub mod rust_service;
|
||||||
|
pub mod cuddle_please {
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use dagger_cuddle_please::{
|
||||||
|
models::CuddlePleaseSrcArgs, DaggerCuddlePlease, DaggerCuddlePleaseAction,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{MainAction, PullRequestAction};
|
||||||
|
|
||||||
|
pub struct CuddlePlease {
|
||||||
|
client: dagger_sdk::Query,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CuddlePlease {
|
||||||
|
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||||
|
Self { client }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl MainAction for CuddlePlease {
|
||||||
|
async fn execute_main(&self) -> eyre::Result<()> {
|
||||||
|
let client = self.client.clone();
|
||||||
|
|
||||||
|
let action = DaggerCuddlePlease::new(client);
|
||||||
|
|
||||||
|
action
|
||||||
|
.cuddle_please_src(&CuddlePleaseSrcArgs {
|
||||||
|
cuddle_image: "kasperhermansen/cuddle-please:latest".into(),
|
||||||
|
server: dagger_cuddle_please::models::SrcServer::Gitea {
|
||||||
|
token: std::env::var("CUDDLE_PLEASE_TOKEN")
|
||||||
|
.expect("CUDDLE_PLEASE_TOKEN to be present"),
|
||||||
|
},
|
||||||
|
log_level: Some(dagger_cuddle_please::models::LogLevel::Debug),
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::sync::{Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs};
|
use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs};
|
||||||
use traits::CuddlePlease;
|
use traits::CuddlePlease;
|
||||||
@ -103,7 +103,7 @@ impl DaggerCuddlePleaseAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct DaggerCuddlePlease {
|
pub struct DaggerCuddlePlease {
|
||||||
client: dagger_sdk::Query,
|
client: dagger_sdk::Query,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user