mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2024-11-25 16:32:42 +01:00
add ci (#7)
* add ci * with description * fix warnings * with actual test * leave out tests for now as they rely on dind
This commit is contained in:
parent
468bca4a69
commit
4ce58a418c
15
.github/workflows/ci.yaml
vendored
Normal file
15
.github/workflows/ci.yaml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
name: ci
|
||||
on:
|
||||
pull_request:
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Update rust toolchain
|
||||
run: rustup update stable && rustup default stable
|
||||
- name: Run dagger [CI]
|
||||
run: cargo run -p ci -- pr
|
183
Cargo.lock
generated
183
Cargo.lock
generated
@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
@ -33,6 +42,21 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.0"
|
||||
@ -84,6 +108,16 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "ci"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"dagger-sdk 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"eyre",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.1.6"
|
||||
@ -106,6 +140,33 @@ dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-eyre"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"color-spantrace",
|
||||
"eyre",
|
||||
"indenter",
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-spantrace"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-core",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "3.8.1"
|
||||
@ -187,7 +248,7 @@ name = "dagger-codegen"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"convert_case",
|
||||
"dagger-core",
|
||||
"dagger-core 0.2.0",
|
||||
"eyre",
|
||||
"genco",
|
||||
"itertools",
|
||||
@ -218,13 +279,37 @@ dependencies = [
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dagger-core"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02a16b0e83ae5b88a3d4e2f3cf5149932cfcb3113e67f5579372e25d5dab5b53"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dirs",
|
||||
"eyre",
|
||||
"flate2",
|
||||
"genco",
|
||||
"graphql-introspection-query",
|
||||
"graphql_client",
|
||||
"hex",
|
||||
"hex-literal",
|
||||
"platform-info",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"tar",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dagger-rs"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dagger-codegen",
|
||||
"dagger-core",
|
||||
"dagger-core 0.2.0",
|
||||
"dirs",
|
||||
"eyre",
|
||||
"flate2",
|
||||
@ -247,7 +332,7 @@ name = "dagger-sdk"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"dagger-core",
|
||||
"dagger-core 0.2.0",
|
||||
"eyre",
|
||||
"futures",
|
||||
"genco",
|
||||
@ -259,6 +344,24 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e454c49b81feeb5c4057f54223cb8d7618e5d015ed835c3f3fa231fefa04e833"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"dagger-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"eyre",
|
||||
"futures",
|
||||
"genco",
|
||||
"gql_client",
|
||||
"pretty_assertions",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
@ -535,6 +638,12 @@ dependencies = [
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
|
||||
|
||||
[[package]]
|
||||
name = "gql_client"
|
||||
version = "1.0.7"
|
||||
@ -925,6 +1034,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.30.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.0"
|
||||
@ -991,6 +1109,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
@ -1189,6 +1313,12 @@ dependencies = [
|
||||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.36.7"
|
||||
@ -1301,6 +1431,15 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.0"
|
||||
@ -1406,6 +1545,16 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
@ -1500,6 +1649,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-error"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
|
||||
dependencies = [
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
||||
dependencies = [
|
||||
"sharded-slab",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1561,6 +1732,12 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
|
@ -6,3 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "4.1.6"
|
||||
color-eyre = "0.6.2"
|
||||
dagger-sdk = "0.2.0"
|
||||
eyre = "0.6.8"
|
||||
|
127
ci/src/main.rs
127
ci/src/main.rs
@ -1,3 +1,126 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::sync::Arc;
|
||||
|
||||
use dagger_sdk::gen::{Container, HostDirectoryOpts, Query};
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
color_eyre::install().unwrap();
|
||||
|
||||
let matches = clap::Command::new("ci")
|
||||
.subcommand_required(true)
|
||||
.subcommand(clap::Command::new("pr"))
|
||||
.get_matches();
|
||||
|
||||
let client = dagger_sdk::client::connect()?;
|
||||
|
||||
let base = select_base_image(client.clone());
|
||||
|
||||
match matches.subcommand() {
|
||||
Some(("pr", _)) => return validate_pr(client, base),
|
||||
Some(_) => {
|
||||
panic!("invalid subcommand selected!")
|
||||
}
|
||||
None => {
|
||||
panic!("no command selected!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_dependencies(client: Arc<Query>) -> Container {
|
||||
let cargo_dir = client.host().directory(
|
||||
".".into(),
|
||||
Some(HostDirectoryOpts {
|
||||
exclude: None,
|
||||
include: Some(vec![
|
||||
"**/Cargo.lock".into(),
|
||||
"**/Cargo.toml".into(),
|
||||
"**/main.rs".into(),
|
||||
"**/lib.rs".into(),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
|
||||
let src_dir = client.host().directory(
|
||||
".".into(),
|
||||
Some(HostDirectoryOpts {
|
||||
exclude: Some(vec!["target/".into()]),
|
||||
include: None,
|
||||
}),
|
||||
);
|
||||
|
||||
let cache_cargo_index_dir = client.cache_volume("cargo_index".into());
|
||||
let cache_cargo_deps = client.cache_volume("cargo_deps".into());
|
||||
|
||||
let base_image = client
|
||||
.container(None)
|
||||
.from("rust:latest".into())
|
||||
.with_workdir("app".into())
|
||||
.with_exec(
|
||||
vec!["cargo".into(), "install".into(), "cargo-chef".into()],
|
||||
None,
|
||||
);
|
||||
|
||||
let recipe = base_image
|
||||
.with_mounted_directory(".".into(), cargo_dir.id())
|
||||
.with_mounted_cache(
|
||||
"~/.cargo/.package-cache".into(),
|
||||
cache_cargo_index_dir.id(),
|
||||
None,
|
||||
)
|
||||
.with_exec(
|
||||
vec![
|
||||
"cargo".into(),
|
||||
"chef".into(),
|
||||
"prepare".into(),
|
||||
"--recipe-path".into(),
|
||||
"recipe.json".into(),
|
||||
],
|
||||
None,
|
||||
)
|
||||
.file("/app/recipe.json".into());
|
||||
|
||||
let builder_start = base_image
|
||||
.with_mounted_file("/app/recipe.json".into(), recipe.id())
|
||||
.with_exec(
|
||||
vec![
|
||||
"cargo".into(),
|
||||
"chef".into(),
|
||||
"cook".into(),
|
||||
"--release".into(),
|
||||
"--recipe-path".into(),
|
||||
"recipe.json".into(),
|
||||
],
|
||||
None,
|
||||
)
|
||||
.with_mounted_cache("/app/".into(), cache_cargo_deps.id(), None)
|
||||
.with_mounted_directory("/app/".into(), src_dir.id())
|
||||
.with_exec(
|
||||
vec![
|
||||
"cargo".into(),
|
||||
"build".into(),
|
||||
"--all".into(),
|
||||
"--release".into(),
|
||||
],
|
||||
None,
|
||||
);
|
||||
|
||||
return builder_start;
|
||||
}
|
||||
|
||||
fn select_base_image(client: Arc<Query>) -> Container {
|
||||
let src_dir = get_dependencies(client.clone());
|
||||
|
||||
src_dir
|
||||
}
|
||||
|
||||
fn validate_pr(_client: Arc<Query>, container: Container) -> eyre::Result<()> {
|
||||
//let container = container.with_exec(vec!["cargo".into(), "test".into(), "--all".into()], None);
|
||||
|
||||
let exit = container.exit_code();
|
||||
if exit != 0 {
|
||||
eyre::bail!("container failed with non-zero exit code");
|
||||
}
|
||||
|
||||
println!("validating pr succeeded!");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user