From b71542f20185d19d4857c1c4248be5fa0652c67c Mon Sep 17 00:00:00 2001 From: Conor Schaefer Date: Thu, 5 Sep 2024 12:28:09 -0700 Subject: [PATCH] ci: add nix env and gha workflows First pass at a dev env, which pulls in the usual Rust deps, as well as go, which is required to build `penumbra-indexer`. The go-linking functionality isn't well supported yet: within the devShell, `cargo build` works, but `nix build` does not. CI cache timing info: * First run of cargo-check: 3m13s * First run of cargo-fmt: 1m57s --- .envrc.example | 1 + .github/workflows/rust.yml | 80 ++++++++++++++++++++++++++++++ .gitignore | 4 ++ Cargo.toml | 4 ++ build.rs | 2 +- flake.lock | 99 ++++++++++++++++++++++++++++++++++++++ flake.nix | 96 ++++++++++++++++++++++++++++++++++++ justfile | 13 +++++ src/storage.rs | 12 ++--- 9 files changed, 304 insertions(+), 7 deletions(-) create mode 100644 .envrc.example create mode 100644 .github/workflows/rust.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 justfile diff --git a/.envrc.example b/.envrc.example new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc.example @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..1bf29d0 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,80 @@ +name: rust +on: + pull_request: + +jobs: + test: + name: cargo test + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: actions/checkout@v4 + with: + lfs: true + + - name: install nix + uses: nixbuild/nix-quick-install-action@v28 + + - name: setup nix cache + uses: nix-community/cache-nix-action@v5 + with: + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }} + restore-prefixes-first-match: nix-${{ runner.os }}- + backend: buildjet + + - name: Load rust cache + uses: astriaorg/buildjet-rust-cache@v2.5.1 + + - name: run cargo test + run: >- + nix develop --command + + just test + check: + name: cargo check + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: actions/checkout@v4 + with: + lfs: true + + - name: install nix + uses: nixbuild/nix-quick-install-action@v28 + + - name: setup nix cache + uses: nix-community/cache-nix-action@v5 + with: + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }} + restore-prefixes-first-match: nix-${{ runner.os }}- + backend: buildjet + + - name: load rust cache + uses: astriaorg/buildjet-rust-cache@v2.5.1 + + - name: run cargo check, failing on warnings + run: >- + nix develop --command + just check + + fmt: + name: cargo fmt + runs-on: buildjet-8vcpu-ubuntu-2204 + steps: + - uses: actions/checkout@v4 + + - name: install nix + uses: nixbuild/nix-quick-install-action@v28 + + - name: setup nix cache + uses: nix-community/cache-nix-action@v5 + with: + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }} + restore-prefixes-first-match: nix-${{ runner.os }}- + backend: buildjet + + - name: load rust cache + uses: astriaorg/buildjet-rust-cache@v2.5.1 + + - name: run cargo fmt, failing on reformatting + run: >- + nix develop --command + just fmt diff --git a/.gitignore b/.gitignore index 2ef8b81..283711f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ # Rust / Cargo /target + +# Ignore .envrc; copy from .envrc.example to get started +.envrc +.direnv/ diff --git a/Cargo.toml b/Cargo.toml index d22f6bf..2d6248d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,9 @@ [package] name = "penumbra-reindexer" +authors = ["Penumbra Labs anyhow::Result<()> { assert_eq!( Storage::new(None, Some(CHAIN_ID)) @@ -314,7 +314,7 @@ mod test { Ok(()) } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn test_storage_can_get_chain_id() -> anyhow::Result<()> { assert_eq!( Storage::new(None, Some(CHAIN_ID)) @@ -327,7 +327,7 @@ mod test { Ok(()) } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn test_put_then_get_block() -> anyhow::Result<()> { let in_block = Block::test_value(); let height = in_block.height(); @@ -340,14 +340,14 @@ mod test { Ok(()) } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn test_bad_height_returns_no_block() -> anyhow::Result<()> { let storage = Storage::new(None, Some(CHAIN_ID)).await?; assert!(storage.get_block(100).await?.is_none()); Ok(()) } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn test_put_twice() -> anyhow::Result<()> { let storage = Storage::new(None, Some(CHAIN_ID)).await?; let block = Block::test_value(); @@ -356,7 +356,7 @@ mod test { Ok(()) } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn test_put_then_get_genesis() -> anyhow::Result<()> { let storage = Storage::new(None, Some(CHAIN_ID)).await?; let genesis = Genesis::test_value();