From e342b3b04ceef2f4a1f0cf313f8cb3a93163cff1 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 27 Dec 2024 16:24:03 +0100 Subject: [PATCH] feat: add optional publish Signed-off-by: kjuulh --- Cargo.lock | 10 +++-- crates/cuddle-rust-cli-plan/Cargo.toml | 2 + crates/cuddle-rust-cli-plan/src/main.rs | 58 ++++++++++++++----------- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6fe930..6e008af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -302,7 +302,7 @@ dependencies = [ [[package]] name = "cuddle-ci" version = "0.3.0" -source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#e1a2d03fbe7e158c597623670e5ae8e74b8f19c5" +source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#80a34851a60976707170910f0d0908d9d1360dc6" dependencies = [ "async-trait", "chrono", @@ -331,17 +331,19 @@ dependencies = [ "dagger-sdk", "eyre", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] name = "dagger-components" version = "0.1.0" -source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#e1a2d03fbe7e158c597623670e5ae8e74b8f19c5" +source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#80a34851a60976707170910f0d0908d9d1360dc6" [[package]] name = "dagger-cuddle-please" version = "0.3.0" -source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#e1a2d03fbe7e158c597623670e5ae8e74b8f19c5" +source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#80a34851a60976707170910f0d0908d9d1360dc6" dependencies = [ "async-trait", "dagger-sdk", @@ -351,7 +353,7 @@ dependencies = [ [[package]] name = "dagger-rust" version = "0.3.0" -source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#e1a2d03fbe7e158c597623670e5ae8e74b8f19c5" +source = "git+https://git.front.kjuulh.io/kjuulh/dagger-components?branch=main#80a34851a60976707170910f0d0908d9d1360dc6" dependencies = [ "async-trait", "dagger-sdk", diff --git a/crates/cuddle-rust-cli-plan/Cargo.toml b/crates/cuddle-rust-cli-plan/Cargo.toml index 9d0d7bf..4b948e9 100644 --- a/crates/cuddle-rust-cli-plan/Cargo.toml +++ b/crates/cuddle-rust-cli-plan/Cargo.toml @@ -13,3 +13,5 @@ dagger-components = { git = "https://git.front.kjuulh.io/kjuulh/dagger-component dagger-rust = { git = "https://git.front.kjuulh.io/kjuulh/dagger-components", branch = "main" } cuddle-ci = { git = "https://git.front.kjuulh.io/kjuulh/dagger-components", branch = "main" } async-trait = "0.1.80" +tracing.workspace = true +tracing-subscriber.workspace = true diff --git a/crates/cuddle-rust-cli-plan/src/main.rs b/crates/cuddle-rust-cli-plan/src/main.rs index 990ccee..5379dfc 100644 --- a/crates/cuddle-rust-cli-plan/src/main.rs +++ b/crates/cuddle-rust-cli-plan/src/main.rs @@ -8,6 +8,8 @@ use eyre::Context; #[tokio::main] async fn main() -> eyre::Result<()> { + tracing_subscriber::fmt::init(); + dagger_sdk::connect(|client| async move { let cuddle_file = CuddleFile::from_cuddle_file().await?; @@ -60,37 +62,43 @@ impl cuddle_ci::ReleaseAction for RustReleaser { let crates_token = std::env::var("CRATES_IO_TOKEN") .context("failed to find crates.io token (env: CRATES_IO_TOKEN)")?; - let rust_image = self.client.container().from("rustlang/rust:nightly"); + if let Some(cuddle_publish) = &cuddle_file.vars.rust { + if cuddle_publish.publish { + let rust_image = self.client.container().from("rustlang/rust:nightly"); - let src = self.client.host().directory_opts( - ".", - HostDirectoryOptsBuilder::default() - .exclude([".git/", ".cuddle/", "target/"]) - .build()?, - ); + let src = self.client.host().directory_opts( + ".", + HostDirectoryOptsBuilder::default() + .exclude([".git/", ".cuddle/", "target/"]) + .build()?, + ); - let service = &cuddle_file.vars.service; + let service = &cuddle_file.vars.service; - rust_image - .with_workdir("/mnt/src") - .with_directory("/mnt/src", src) - .with_new_file( - "/root/.cargo/credentials", - format!( - r#" + rust_image + .with_workdir("/mnt/src") + .with_directory("/mnt/src", src) + .with_new_file( + "/root/.cargo/credentials", + format!( + r#" [registry] token = "{}" "#, - crates_token - ), - ) - .with_secret_variable( - "CARGO_REGISTRY_TOKEN", - self.client.set_secret("CARGO_REGISTRY_TOKEN", crates_token), - ) - .with_exec(vec!["cargo", "publish", "-p", service, "--allow-dirty"]) - .sync() - .await?; + crates_token + ), + ) + .with_secret_variable( + "CARGO_REGISTRY_TOKEN", + self.client.set_secret("CARGO_REGISTRY_TOKEN", crates_token), + ) + .with_exec(vec!["cargo", "publish", "-p", service, "--allow-dirty"]) + .sync() + .await?; + } else { + tracing::info!("publish disabled"); + } + } Ok(()) }