Skip to content

Commit

Permalink
Update and integrate with hc-github-config (#1)
Browse files Browse the repository at this point in the history
* Update and integrate with hc-github-config

* Verify integration

* Refer to dev shell

* Remove test trigger
  • Loading branch information
ThetaSinner authored Jan 21, 2025
1 parent 240802b commit 490f3ae
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 48 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -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) }}

8 changes: 3 additions & 5 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 25 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ use anyhow::anyhow;
use crate::parser::{parse_log, CacheInfo};

fn from_csv(input: &str) -> anyhow::Result<HashSet<String>> {
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<()> {
Expand All @@ -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()?;
Expand Down Expand Up @@ -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!");
Expand All @@ -93,14 +100,18 @@ pub fn run_app() -> anyhow::Result<()> {
Ok(())
}

pub fn validate(permit_build_derivations: HashSet<String>, cache_info: &CacheInfo) -> anyhow::Result<bool> {
pub fn validate(
permit_build_derivations: HashSet<String>,
cache_info: &CacheInfo,
) -> anyhow::Result<bool> {
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::<Vec<&str>>()
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

use app::run_app;

mod parser;
mod app;
mod parser;

fn main() -> anyhow::Result<()> {
run_app()
Expand Down
47 changes: 25 additions & 22 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,42 @@ where
),
fold_many1(
context("build-derivation-line", parse_line::<E>),
|| 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::<E>),
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::<E>),
|| 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),
Expand Down

0 comments on commit 490f3ae

Please sign in to comment.