From 490f3ae0668da97d907c0009b0c75b7e746111ae Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Tue, 21 Jan 2025 13:54:13 +0000 Subject: [PATCH] Update and integrate with hc-github-config (#1) * Update and integrate with hc-github-config * Verify integration * Refer to dev shell * Remove test trigger --- .github/workflows/check.yml | 27 ++++++++++++++++++ .github/workflows/integration.yml | 8 ++---- Cargo.lock | 10 +++---- src/app.rs | 39 ++++++++++++++++--------- src/main.rs | 3 +- src/parser.rs | 47 ++++++++++++++++--------------- 6 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..4f78752 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,27 @@ +name: Check + +on: + push: + branches: + - main + pull_request: {} + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - run: | + cargo fmt --check + cargo clippy --all-targets --all-features -- -D warnings + cargo test --all-targets --all-features + ci_pass: + if: always() + runs-on: ubuntu-latest + needs: [ check ] + steps: + - uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index d9227ce..4d1b2d2 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -9,13 +9,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v22 - - uses: cachix/cachix-action@v12 + - uses: cachix/install-nix-action@v30 + - uses: cachix/cachix-action@v15 with: name: holochain-ci - name: Test uses: ./ with: - derivation: github:holochain/holochain#devShells.x86_64-linux.holonix - extra_build_args: --refresh --override-input versions github:holochain/holochain?dir=versions/0_2 - permit_build_derivations: hn-introspect,nix-shell,rust-default-1.66.1,inheritCargoArtifactsHook,cargoHelperFunctionsHook + derivation: github:holochain/holonix?ref=main-0.4#devShells.x86_64-linux.default diff --git a/Cargo.lock b/Cargo.lock index 61cb4dc..1556a7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,18 +1,18 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" [[package]] name = "memchr" -version = "2.6.3" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "minimal-lexical" diff --git a/src/app.rs b/src/app.rs index dcecc26..524b005 100644 --- a/src/app.rs +++ b/src/app.rs @@ -9,14 +9,17 @@ use anyhow::anyhow; use crate::parser::{parse_log, CacheInfo}; fn from_csv(input: &str) -> anyhow::Result> { - Ok(input.split(",").filter_map(|v| { - let x = v.trim().to_owned(); - if !x.is_empty() { - Some(x) - } else { - None - } - }).collect()) + Ok(input + .split(",") + .filter_map(|v| { + let x = v.trim().to_owned(); + if !x.is_empty() { + Some(x) + } else { + None + } + }) + .collect()) } pub fn run_app() -> anyhow::Result<()> { @@ -41,9 +44,9 @@ pub fn run_app() -> anyhow::Result<()> { println!("Starting Nix build"); stdout().flush()?; - let output = cmd.output().map_err(|e| { - anyhow!("Failed to spawn the Nix build: {:?}", e) - })?; + let output = cmd + .output() + .map_err(|e| anyhow!("Failed to spawn the Nix build: {:?}", e))?; println!("Finished Nix build"); stdout().flush()?; @@ -73,7 +76,11 @@ pub fn run_app() -> anyhow::Result<()> { stdout().flush()?; if validate( - from_csv(std::env::var("PERMIT_BUILD_DERIVATIONS").unwrap_or_else(|_| "".to_string()).as_str())?, + from_csv( + std::env::var("PERMIT_BUILD_DERIVATIONS") + .unwrap_or_else(|_| "".to_string()) + .as_str(), + )?, &cache_info, )? { println!("Validation passed!"); @@ -93,14 +100,18 @@ pub fn run_app() -> anyhow::Result<()> { Ok(()) } -pub fn validate(permit_build_derivations: HashSet, cache_info: &CacheInfo) -> anyhow::Result { +pub fn validate( + permit_build_derivations: HashSet, + cache_info: &CacheInfo, +) -> anyhow::Result { let mut all_passed = true; let mut permits_used = HashSet::new(); for to_build in cache_info.get_derivations_to_build() { let to_build_name: String = to_build - .strip_suffix(".drv").ok_or(anyhow!("Not a derivation? {}", to_build))? + .strip_suffix(".drv") + .ok_or(anyhow!("Not a derivation? {}", to_build))? .split("-") .skip(1) .collect::>() diff --git a/src/main.rs b/src/main.rs index 4eb4b1e..de94ab9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ - use app::run_app; -mod parser; mod app; +mod parser; fn main() -> anyhow::Result<()> { run_app() diff --git a/src/parser.rs b/src/parser.rs index b9c6593..c28e67b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -59,39 +59,42 @@ where ), fold_many1( context("build-derivation-line", parse_line::), - || vec![], + Vec::new, + |mut acc, line| { + acc.push(line); + acc + }, + ), + )), + opt(preceded( + context( + "start-of-fetched-derivations", + tuple(( + take_until("these "), + take(6usize), + take_until("fetched"), + take(7usize), + take_until(":"), + take(1usize), + newline, + )), + ), + fold_many1( + context("fetch-derivation-line", parse_line::), + Vec::new, |mut acc, line| { acc.push(line); acc }, ), )), - opt(preceded(context( - "start-of-fetched-derivations", - tuple(( - take_until("these "), - take(6usize), - take_until("fetched"), - take(7usize), - take_until(":"), - take(1usize), - newline, - )), - ), fold_many1( - context("fetch-derivation-line", parse_line::), - || vec![], - |mut acc, line| { - acc.push(line); - acc - }, - ))), ))(input) { Ok((rest, (to_build, to_fetch))) => Ok(( rest, CacheInfo { - derivations_to_build: to_build.unwrap_or_else(|| vec![]), - derivations_to_fetch: to_fetch.unwrap_or_else(|| vec![]), + derivations_to_build: to_build.unwrap_or_else(Vec::new), + derivations_to_fetch: to_fetch.unwrap_or_else(Vec::new), }, )), Err(e) => Err(e),