From 9b28c4866e4a84e503e79bd76fc1ad055ef48332 Mon Sep 17 00:00:00 2001 From: refcell Date: Tue, 23 Jul 2024 20:37:01 -0400 Subject: [PATCH] feat: justfile with github actions --- .github/workflows/ci.yml | 100 ++++++++++++++++++++++++++++++++++++++ Justfile | 46 ++++++++++++++++++ crates/opt8n/src/main.rs | 2 +- crates/opt8n/src/opt8n.rs | 12 ++--- 4 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 Justfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6166d06 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,100 @@ +name: Rust CI + +on: + push: + branches: [main] + merge_group: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + cargo-tests: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - uses: taiki-e/install-action@nextest + - name: cargo nextest + run: cargo nextest run --release --workspace --all --locked + run: just test + cargo-lint: + runs-on: ubuntu-latest + timeout-minutes: 20 + name: lint + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@just + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt, clippy + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Log into ghcr + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: fmt + lint + run: just lint + - name: chown target + run: sudo chown -R $(id -u):$(id -g) ./target + cargo-build-benches: + runs-on: ubuntu-latest + timeout-minutes: 20 + name: build-benchmarks + continue-on-error: true + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@just + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: build benches + run: cargo bench --no-run --workspace --all + - name: chown target + run: sudo chown -R $(id -u):$(id -g) ./target + cargo-build: + runs-on: ubuntu-latest + timeout-minutes: 20 + name: build + continue-on-error: true + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@just + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Log into ghcr + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: build + run: just build + - name: chown target + run: sudo chown -R $(id -u):$(id -g) ./target + cargo-doc: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@just + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: doclint + run: just lint-docs + - name: doctest + run: just test-docs diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..a0f8446 --- /dev/null +++ b/Justfile @@ -0,0 +1,46 @@ +set positional-arguments +alias t := test +alias f := fmt +alias l := lint +alias b := build + +# default recipe to display help information +default: + @just --list + +# Run all tests +tests: test test-docs + +# Test for the native target with all features +test *args='': + cargo nextest run --workspace --all --all-features $@ + +# Test the Rust documentation +test-docs: + cargo test --doc --all --locked + +# Fixes and checks all workspace formatting +fmt: fmt-fix fmt-check + +# Fixes the formatting of the workspace +fmt-fix: + cargo +nightly fmt --all + +# Check the formatting of the workspace +fmt-check: + cargo +nightly fmt --all -- --check + +# Lint workspace and docs +lint: lint-docs clippy + +# Lint the Rust documentation +lint-docs: + RUSTDOCFLAGS="-D warnings" cargo doc --all --no-deps --document-private-items + +# Run clippy lints on the workspace +clippy: + cargo +nightly clippy --workspace --all --all-features --all-targets -- -D warnings + +# Build for the native target +build *args='': + cargo build --workspace --all $@ diff --git a/crates/opt8n/src/main.rs b/crates/opt8n/src/main.rs index 257228a..7bff7cd 100644 --- a/crates/opt8n/src/main.rs +++ b/crates/opt8n/src/main.rs @@ -31,7 +31,7 @@ pub enum Commands { #[command(visible_alias = "s")] Script { #[command(flatten)] - script_args: ScriptArgs, + script_args: Box, }, } diff --git a/crates/opt8n/src/opt8n.rs b/crates/opt8n/src/opt8n.rs index a63143d..73fd231 100644 --- a/crates/opt8n/src/opt8n.rs +++ b/crates/opt8n/src/opt8n.rs @@ -45,14 +45,10 @@ impl Opt8n { output_file: PathBuf, genesis: Option, ) -> Self { - let genesis = if let Some(path) = genesis.as_ref() { - Some( - serde_json::from_reader(File::open(path).expect("TODO: handle error Invalid path")) - .expect("TODO: handle error Invalid genesis"), - ) - } else { - None - }; + let genesis = genesis.as_ref().map(|path| { + serde_json::from_reader(File::open(path).expect("TODO: handle error Invalid path")) + .expect("TODO: handle error Invalid genesis") + }); let node_config = node_config .unwrap_or_default()