From f94677d78f220e8816ba8db9bfd06ca7fdd8c2fe Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 4 Aug 2023 01:10:10 +0200 Subject: [PATCH] feat(ci): with pr Signed-off-by: kjuulh --- ci/src/main.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++++-- scripts/ci:pr.sh | 1 - 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/ci/src/main.rs b/ci/src/main.rs index 1d64265..a27bcc1 100644 --- a/ci/src/main.rs +++ b/ci/src/main.rs @@ -35,7 +35,14 @@ pub enum Commands { #[command(subcommand)] command: LocalCommands, }, - PullRequest, + PullRequest { + #[arg(long)] + image: String, + #[arg(long)] + tag: String, + #[arg(long)] + bin_name: String, + }, Main { #[arg(long)] image: String, @@ -163,7 +170,48 @@ async fn main() -> eyre::Result<()> { .await?; } }, - Commands::PullRequest => todo!(), + Commands::PullRequest { + image, + tag, + bin_name, + } => { + async fn test(client: Arc, cli: &Command, bin_name: &String) { + let args = &cli.global; + + let base_image = + base_rust_image(client.clone(), &args, &None, bin_name, &"debug".into()) + .await + .unwrap(); + test::execute(client.clone(), &args, base_image) + .await + .unwrap(); + } + async fn build( + client: Arc, + cli: &Command, + bin_name: &String, + image: &String, + tag: &String, + ) { + let args = &cli.global; + + build::build(client.clone(), &args, bin_name, image, tag) + .await + .unwrap(); + } + + async fn cuddle_please(client: Arc, cli: &Command) { + run_release_please(client.clone(), &cli.global) + .await + .unwrap(); + } + + tokio::join!( + test(client.clone(), &cli, &bin_name), + build(client.clone(), &cli, &bin_name, &image, &tag), + cuddle_please(client.clone(), &cli) + ); + } Commands::Main { image, tag, @@ -442,6 +490,44 @@ mod build { .await?; Ok(()) } + pub async fn build( + client: Arc, + args: &GlobalArgs, + bin_name: &String, + image: &String, + tag: &String, + ) -> eyre::Result<()> { + // let containers = vec!["linux/amd64", "linux/arm64"]; + + let base_image = get_base_debian_image( + client.clone(), + &args.clone(), + Some("linux/amd64".to_string()), + ) + .await?; + + let container = base_rust_image( + client.clone(), + &args, + &Some("linux/amd64".to_string()), + &bin_name.clone(), + &"release".into(), + ) + .await?; + let build_image = execute( + client.clone(), + &args, + &container, + &base_image, + &bin_name, + &Some("linux/amd64".to_string()), + ) + .await?; + + build_image.exit_code().await?; + + Ok(()) + } pub async fn execute( _client: Arc, _args: &GlobalArgs, diff --git a/scripts/ci:pr.sh b/scripts/ci:pr.sh index d9ab5db..e77746e 100755 --- a/scripts/ci:pr.sh +++ b/scripts/ci:pr.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash set -e