From 45d646203704aed317ee2273b825ae708e83ca32 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 19 Feb 2023 22:51:34 +0100 Subject: [PATCH] chore(ci): with async/await --- Cargo.lock | 37 +++++++++++++++++++------------------ ci/Cargo.toml | 3 ++- ci/src/main.rs | 45 +++++++++++++++++++++++---------------------- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 528226e..b473ea7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,8 +114,9 @@ version = "0.1.0" dependencies = [ "clap", "color-eyre", - "dagger-sdk 0.2.6", + "dagger-sdk 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "eyre", + "tokio", ] [[package]] @@ -328,23 +329,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "dagger-sdk" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "654625e954f59d70eb897bb681936c3e8b69c5f6e528f85c0b307554883db63f" -dependencies = [ - "base64", - "dagger-core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_builder", - "eyre", - "futures", - "gql_client", - "serde", - "serde_json", - "tokio", -] - [[package]] name = "dagger-sdk" version = "0.2.8" @@ -363,6 +347,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "dagger-sdk" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e90636d5b74ce8a62e8507a8d075c4d997c3123a1709596d0f97c3070f993b2d" +dependencies = [ + "base64", + "dagger-core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_builder", + "eyre", + "futures", + "gql_client", + "serde", + "serde_json", + "tokio", +] + [[package]] name = "darling" version = "0.14.3" diff --git a/ci/Cargo.toml b/ci/Cargo.toml index a3cc2f4..f463ea8 100644 --- a/ci/Cargo.toml +++ b/ci/Cargo.toml @@ -8,5 +8,6 @@ edition = "2021" [dependencies] clap = "4.1.6" color-eyre = "0.6.2" -dagger-sdk = "0.2.6" +dagger-sdk = "0.2.8" eyre = "0.6.8" +tokio = { version = "1.25.0", features = ["full"] } diff --git a/ci/src/main.rs b/ci/src/main.rs index cdb93d3..d2a177d 100644 --- a/ci/src/main.rs +++ b/ci/src/main.rs @@ -2,7 +2,8 @@ use std::sync::Arc; use dagger_sdk::{Container, HostDirectoryOpts, Query}; -fn main() -> eyre::Result<()> { +#[tokio::main] +async fn main() -> eyre::Result<()> { color_eyre::install().unwrap(); let matches = clap::Command::new("ci") @@ -15,10 +16,10 @@ fn main() -> eyre::Result<()> { match matches.subcommand() { Some(("pr", _)) => { - let base = select_base_image(client.clone())?; - return validate_pr(client, base); + let base = select_base_image(client.clone()).await?; + return validate_pr(client, base).await; } - Some(("release", subm)) => return release(client, subm), + Some(("release", subm)) => return release(client, subm).await, Some(_) => { panic!("invalid subcommand selected!") } @@ -28,7 +29,7 @@ fn main() -> eyre::Result<()> { } } -fn release(client: Arc, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> { +async fn release(client: Arc, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> { let src_dir = client.host().directory_opts( ".", HostDirectoryOpts { @@ -40,7 +41,7 @@ fn release(client: Arc, _subm: &clap::ArgMatches) -> Result<(), color_eyr .container() .from("rust:latest") .with_workdir("app") - .with_mounted_directory("/app/", src_dir.id()?); + .with_mounted_directory("/app/", src_dir.id().await?); let container = base_image .with_exec(vec!["cargo", "install", "cargo-smart-release"]) @@ -53,7 +54,7 @@ fn release(client: Arc, _subm: &clap::ArgMatches) -> Result<(), color_eyr "dagger-rs", "dagger-sdk", ]); - let exit = container.exit_code()?; + let exit = container.exit_code().await?; if exit != 0 { eyre::bail!("container failed with non-zero exit code"); } @@ -63,7 +64,7 @@ fn release(client: Arc, _subm: &clap::ArgMatches) -> Result<(), color_eyr Ok(()) } -fn get_dependencies(client: Arc) -> eyre::Result { +async fn get_dependencies(client: Arc) -> eyre::Result { let cargo_dir = client.host().directory_opts( ".", HostDirectoryOpts { @@ -121,16 +122,16 @@ fn get_dependencies(client: Arc) -> eyre::Result { .with_env_variable("SCCACHE_BUCKET", "sccache") .with_env_variable("SCCACHE_REGION", "auto") .with_env_variable("SCCACHE_ENDPOINT", "https://api-minio.front.kjuulh.io") - .with_mounted_cache("~/.cargo/bin", cache_cargo_bin.id()?) - .with_mounted_cache("~/.cargo/registry/index", cache_cargo_bin.id()?) - .with_mounted_cache("~/.cargo/registry/cache", cache_cargo_bin.id()?) - .with_mounted_cache("~/.cargo/git/db", cache_cargo_bin.id()?) - .with_mounted_cache("target/", cache_cargo_bin.id()?) + .with_mounted_cache("~/.cargo/bin", cache_cargo_bin.id().await?) + .with_mounted_cache("~/.cargo/registry/index", cache_cargo_bin.id().await?) + .with_mounted_cache("~/.cargo/registry/cache", cache_cargo_bin.id().await?) + .with_mounted_cache("~/.cargo/git/db", cache_cargo_bin.id().await?) + .with_mounted_cache("target/", cache_cargo_bin.id().await?) .with_exec(vec!["cargo", "install", "cargo-chef"]); let recipe = base_image - .with_mounted_directory(".", cargo_dir.id()?) - .with_mounted_cache("~/.cargo/.package-cache", cache_cargo_index_dir.id()?) + .with_mounted_directory(".", cargo_dir.id().await?) + .with_mounted_cache("~/.cargo/.package-cache", cache_cargo_index_dir.id().await?) .with_exec(vec![ "cargo", "chef", @@ -141,7 +142,7 @@ fn get_dependencies(client: Arc) -> eyre::Result { .file("/app/recipe.json"); let builder_start = base_image - .with_mounted_file("/app/recipe.json", recipe.id()?) + .with_mounted_file("/app/recipe.json", recipe.id().await?) .with_exec(vec![ "cargo", "chef", @@ -151,23 +152,23 @@ fn get_dependencies(client: Arc) -> eyre::Result { "--recipe-path", "recipe.json", ]) - .with_mounted_cache("/app/", cache_cargo_deps.id()?) - .with_mounted_directory("/app/", src_dir.id()?) + .with_mounted_cache("/app/", cache_cargo_deps.id().await?) + .with_mounted_directory("/app/", src_dir.id().await?) .with_exec(vec!["cargo", "build", "--all", "--release"]); return Ok(builder_start); } -fn select_base_image(client: Arc) -> eyre::Result { - let src_dir = get_dependencies(client.clone()); +async fn select_base_image(client: Arc) -> eyre::Result { + let src_dir = get_dependencies(client.clone()).await; src_dir } -fn validate_pr(_client: Arc, container: Container) -> eyre::Result<()> { +async fn validate_pr(_client: Arc, container: Container) -> eyre::Result<()> { //let container = container.with_exec(vec!["cargo", "test", "--all"], None); - let exit = container.exit_code()?; + let exit = container.exit_code().await?; if exit != 0 { eyre::bail!("container failed with non-zero exit code"); }