2023-08-11 17:05:05 +02:00
|
|
|
use std::path::PathBuf;
|
2023-11-25 23:14:38 +01:00
|
|
|
|
2023-08-11 17:05:05 +02:00
|
|
|
use clap::Args;
|
|
|
|
use clap::Parser;
|
|
|
|
use clap::Subcommand;
|
|
|
|
use clap::ValueEnum;
|
|
|
|
|
|
|
|
use crate::please_release::run_release_please;
|
|
|
|
|
|
|
|
#[derive(Parser, Clone)]
|
|
|
|
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
|
|
|
pub struct Command {
|
|
|
|
#[command(subcommand)]
|
|
|
|
commands: Commands,
|
|
|
|
|
|
|
|
#[command(flatten)]
|
|
|
|
global: GlobalArgs,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand, Clone)]
|
|
|
|
pub enum Commands {
|
|
|
|
#[command(subcommand_required = true)]
|
|
|
|
Local {
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: LocalCommands,
|
|
|
|
},
|
2023-08-11 17:23:57 +02:00
|
|
|
PullRequest {},
|
|
|
|
Main {},
|
2023-08-11 17:05:05 +02:00
|
|
|
Release,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand, Clone)]
|
|
|
|
pub enum LocalCommands {
|
|
|
|
Test,
|
|
|
|
PleaseRelease,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, ValueEnum)]
|
|
|
|
pub enum BuildProfile {
|
|
|
|
Debug,
|
|
|
|
Release,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Args)]
|
|
|
|
pub struct GlobalArgs {
|
|
|
|
#[arg(long, global = true, help_heading = "Global")]
|
|
|
|
dry_run: bool,
|
|
|
|
|
|
|
|
#[arg(long, global = true, help_heading = "Global")]
|
|
|
|
rust_builder_image: Option<String>,
|
|
|
|
|
2023-08-12 12:25:31 +02:00
|
|
|
#[arg(long, global = true, help_heading = "Global")]
|
|
|
|
cuddle_please_image: Option<String>,
|
|
|
|
|
2023-08-11 17:05:05 +02:00
|
|
|
#[arg(long, global = true, help_heading = "Global")]
|
|
|
|
source: Option<PathBuf>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> eyre::Result<()> {
|
|
|
|
let _ = dotenv::dotenv();
|
|
|
|
let _ = color_eyre::install();
|
|
|
|
|
|
|
|
let cli = Command::parse();
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
let client = dagger_sdk::connect().await?;
|
|
|
|
|
2023-08-11 17:05:05 +02:00
|
|
|
match &cli.commands {
|
|
|
|
Commands::Local { command } => match command {
|
|
|
|
LocalCommands::Test => {
|
2023-08-12 20:05:27 +02:00
|
|
|
test::execute(client, &cli.global).await?;
|
2023-08-11 17:05:05 +02:00
|
|
|
}
|
|
|
|
LocalCommands::PleaseRelease => todo!(),
|
|
|
|
},
|
2023-08-11 17:23:57 +02:00
|
|
|
Commands::PullRequest {} => {
|
2023-10-21 12:45:33 +02:00
|
|
|
async fn test(client: dagger_sdk::Query, cli: &Command) {
|
2023-08-11 17:05:05 +02:00
|
|
|
let args = &cli.global;
|
|
|
|
|
2023-08-12 20:05:27 +02:00
|
|
|
test::execute(client.clone(), args).await.unwrap();
|
2023-08-11 17:05:05 +02:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:23:57 +02:00
|
|
|
tokio::join!(test(client.clone(), &cli),);
|
2023-08-11 17:05:05 +02:00
|
|
|
}
|
2023-08-11 17:23:57 +02:00
|
|
|
Commands::Main {} => {
|
2023-10-21 12:45:33 +02:00
|
|
|
async fn test(client: dagger_sdk::Query, cli: &Command) {
|
2023-08-11 17:05:05 +02:00
|
|
|
let args = &cli.global;
|
|
|
|
|
2023-08-12 20:05:27 +02:00
|
|
|
test::execute(client.clone(), args).await.unwrap();
|
2023-08-11 17:05:05 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 12:45:33 +02:00
|
|
|
async fn cuddle_please(client: dagger_sdk::Query, cli: &Command) {
|
2023-08-11 17:05:05 +02:00
|
|
|
run_release_please(client.clone(), &cli.global)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
tokio::join!(
|
2023-08-11 17:23:57 +02:00
|
|
|
test(client.clone(), &cli),
|
2023-08-11 17:05:05 +02:00
|
|
|
cuddle_please(client.clone(), &cli)
|
|
|
|
);
|
|
|
|
}
|
2023-08-12 21:22:47 +02:00
|
|
|
Commands::Release => {}
|
2023-08-11 17:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
mod please_release {
|
|
|
|
|
2023-08-11 20:22:07 +02:00
|
|
|
use dagger_cuddle_please::{models::CuddlePleaseSrcArgs, DaggerCuddlePleaseAction};
|
|
|
|
|
2023-08-11 19:08:48 +02:00
|
|
|
use crate::GlobalArgs;
|
2023-08-11 17:05:05 +02:00
|
|
|
|
|
|
|
pub async fn run_release_please(
|
2023-10-21 12:45:33 +02:00
|
|
|
client: dagger_sdk::Query,
|
2023-08-11 17:05:05 +02:00
|
|
|
args: &GlobalArgs,
|
|
|
|
) -> eyre::Result<()> {
|
2023-08-11 20:22:07 +02:00
|
|
|
DaggerCuddlePleaseAction::dagger(client)
|
|
|
|
.execute_src(&CuddlePleaseSrcArgs {
|
2023-08-12 12:25:31 +02:00
|
|
|
cuddle_image: args
|
|
|
|
.cuddle_please_image
|
|
|
|
.clone()
|
2023-12-29 19:55:10 +01:00
|
|
|
.unwrap_or("kasperhermansen/cuddle-please:latest".into()),
|
2023-08-11 20:22:07 +02:00
|
|
|
server: dagger_cuddle_please::models::SrcServer::Gitea {
|
|
|
|
token: std::env::var("CUDDLE_PLEASE_TOKEN")
|
|
|
|
.expect("CUDDLE_PLEASE_TOKEN to be present"),
|
2023-08-11 17:05:05 +02:00
|
|
|
},
|
2023-08-11 20:22:07 +02:00
|
|
|
log_level: Some(dagger_cuddle_please::models::LogLevel::Debug),
|
|
|
|
})
|
|
|
|
.await?;
|
2023-08-11 17:05:05 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod test {
|
2023-11-26 22:19:34 +01:00
|
|
|
use std::path::PathBuf;
|
2023-08-11 17:05:05 +02:00
|
|
|
|
2023-08-12 20:05:27 +02:00
|
|
|
use dagger_rust::build::RustVersion;
|
2023-08-11 17:05:05 +02:00
|
|
|
|
2023-08-12 20:05:27 +02:00
|
|
|
use crate::GlobalArgs;
|
2023-08-11 17:23:57 +02:00
|
|
|
|
2023-10-21 12:45:33 +02:00
|
|
|
pub async fn execute(client: dagger_sdk::Query, _args: &GlobalArgs) -> eyre::Result<()> {
|
2023-08-12 20:05:27 +02:00
|
|
|
dagger_rust::test::RustTest::new(client)
|
|
|
|
.test(
|
|
|
|
None::<PathBuf>,
|
|
|
|
RustVersion::Nightly,
|
|
|
|
&["crates/*", "examples/*", "ci"],
|
|
|
|
&[],
|
|
|
|
)
|
|
|
|
.await?;
|
2023-08-11 17:05:05 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|