feat: add optional publish
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-12-27 16:24:03 +01:00
parent 48b9e8ff1f
commit e342b3b04c
3 changed files with 41 additions and 29 deletions

10
Cargo.lock generated
View File

@ -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",

View File

@ -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

View File

@ -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(())
}