Skip to content

Commit

Permalink
Add CI workflow (#14)
Browse files Browse the repository at this point in the history
* Add CI workflows for clippy, fmt and test.

* Fix cargo format and clippy errors

* Fix clippy errors.
  • Loading branch information
jimmygchen authored Jun 29, 2023
1 parent 8ea9432 commit e30719a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
Cargo.lock

/proptest-regressions

# IntelliJ / Clion
.idea
1 change: 1 addition & 0 deletions src/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl<'a, T: Clone> Cow<'a, T> {
}

pub trait CowTrait<'a, T: Clone>: Deref<Target = T> {
#[allow(clippy::wrong_self_convention)]
fn to_mut(self) -> &'a mut T;
}

Expand Down
5 changes: 3 additions & 2 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl<T: TreeHash + Clone, N: Unsigned, U: UpdateMap<T>> List<T, N, U> {
impl<T: TreeHash + Clone, N: Unsigned> ImmList<T> for ListInner<T, N> {
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
}
Expand Down Expand Up @@ -298,7 +299,7 @@ impl<'a, T: TreeHash + Clone, N: Unsigned, U: UpdateMap<T>> IntoIterator for &'a
}
}

impl<'a, T: TreeHash + Clone, N: Unsigned, U: UpdateMap<T>> Serialize for List<T, N, U>
impl<T: TreeHash + Clone, N: Unsigned, U: UpdateMap<T>> Serialize for List<T, N, U>
where
T: Serialize,
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn u64_packed_vector_tree_hash() {
let len = 16;
let vec = (0..len).map(|i| 2 * i).collect::<Vec<u64>>();
let vector = Vector::<u64, U16>::new(vec.clone()).unwrap();
let fixed_vector = FixedVector::<u64, U16>::new(vec.clone()).unwrap();
let fixed_vector = FixedVector::<u64, U16>::new(vec).unwrap();

assert_eq!(vector.tree_hash_root(), fixed_vector.tree_hash_root());
}
Expand Down
3 changes: 2 additions & 1 deletion src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ impl<T: TreeHash + Clone, N: Unsigned, U: UpdateMap<T>> From<Vector<T, N, U>> fo
impl<T: TreeHash + Clone, N: Unsigned> ImmList<T> for VectorInner<T, N> {
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
}
Expand Down

0 comments on commit e30719a

Please sign in to comment.