From 982f5c015ad5fb98bb61935f8021871101ae88a1 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 29 Jun 2023 12:17:08 +1000 Subject: [PATCH 1/3] Add CI workflows for clippy, fmt and test. --- .github/workflows/release.yml | 24 +++++++++++++++++ .github/workflows/test-suite.yml | 44 ++++++++++++++++++++++++++++++++ .gitignore | 3 +++ 3 files changed, 71 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test-suite.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fb5a015 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,24 @@ +name: release +on: + push: + tags: + - v* +jobs: + check-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Check version + run: | + TAG_VERSION=$(echo ${GITHUB_REF#refs/tags/v}) + CRATE_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') + test "$TAG_VERSION" = "$CRATE_VERSION" + publish: + runs-on: ubuntu-latest + needs: check-version + env: + CARGO_REGISTRY_TOKEN: "${{ secrets.CARGO_REGISTRY_TOKEN }}" + steps: + - uses: actions/checkout@v3 + - name: Publish crate + run: cargo publish -p milhouse diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml new file mode 100644 index 0000000..6edb232 --- /dev/null +++ b/.github/workflows/test-suite.yml @@ -0,0 +1,44 @@ +name: test-suite + +on: + push: + branches: + - main + - 'pr/*' + pull_request: +env: + # Deny warnings in CI + RUSTFLAGS: "-D warnings" +jobs: + cargo-fmt: + name: cargo-fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get latest version of stable Rust + run: rustup update stable + - name: Check formatting with cargo fmt + run: cargo fmt --all -- --check + clippy: + name: clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get latest version of stable Rust + run: rustup update stable + - name: Lint code for quality and style with Clippy + run: cargo clippy --all + test: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + name: test-${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Get latest version of stable Rust + run: rustup update stable + - name: Run tests + run: cargo test --release + - name: Check all examples, binaries, etc + run: cargo check --all-targets diff --git a/.gitignore b/.gitignore index 01db944..a963a38 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ Cargo.lock /proptest-regressions + +# IntelliJ / Clion +.idea From da8bf6246c39eef328c338b2b714e94590765f7f Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 29 Jun 2023 12:19:45 +1000 Subject: [PATCH 2/3] Fix cargo format and clippy errors --- src/list.rs | 3 ++- src/tests/packed.rs | 2 +- src/vector.rs | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/list.rs b/src/list.rs index 3a6df97..583923e 100644 --- a/src/list.rs +++ b/src/list.rs @@ -176,7 +176,8 @@ impl> List { impl ImmList for ListInner { fn get(&self, index: usize) -> Option<&T> { if index < self.len().as_usize() { - self.tree.get_recursive(index, self.depth, self.packing_depth) + self.tree + .get_recursive(index, self.depth, self.packing_depth) } else { None } diff --git a/src/tests/packed.rs b/src/tests/packed.rs index 08ef370..5351b38 100644 --- a/src/tests/packed.rs +++ b/src/tests/packed.rs @@ -49,7 +49,7 @@ fn u64_packed_vector_tree_hash() { let len = 16; let vec = (0..len).map(|i| 2 * i).collect::>(); let vector = Vector::::new(vec.clone()).unwrap(); - let fixed_vector = FixedVector::::new(vec.clone()).unwrap(); + let fixed_vector = FixedVector::::new(vec).unwrap(); assert_eq!(vector.tree_hash_root(), fixed_vector.tree_hash_root()); } diff --git a/src/vector.rs b/src/vector.rs index d4d53ed..c57189e 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -174,7 +174,8 @@ impl> From> fo impl ImmList for VectorInner { fn get(&self, index: usize) -> Option<&T> { if index < self.len().as_usize() { - self.tree.get_recursive(index, self.depth, self.packing_depth) + self.tree + .get_recursive(index, self.depth, self.packing_depth) } else { None } From f5e29b62f1e8bdc82cf6822350ba8f74df8be53f Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 29 Jun 2023 12:37:24 +1000 Subject: [PATCH 3/3] Fix clippy errors. --- src/cow.rs | 1 + src/list.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cow.rs b/src/cow.rs index ff61f26..ccdd53b 100644 --- a/src/cow.rs +++ b/src/cow.rs @@ -27,6 +27,7 @@ impl<'a, T: Clone> Cow<'a, T> { } pub trait CowTrait<'a, T: Clone>: Deref { + #[allow(clippy::wrong_self_convention)] fn to_mut(self) -> &'a mut T; } diff --git a/src/list.rs b/src/list.rs index 583923e..0504546 100644 --- a/src/list.rs +++ b/src/list.rs @@ -299,7 +299,7 @@ impl<'a, T: TreeHash + Clone, N: Unsigned, U: UpdateMap> IntoIterator for &'a } } -impl<'a, T: TreeHash + Clone, N: Unsigned, U: UpdateMap> Serialize for List +impl> Serialize for List where T: Serialize, {