Skip to content

Commit

Permalink
chore: Use justfile scripts for pre-commit/pre-push hooks (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski authored Nov 3, 2024
1 parent e0d5638 commit 1898312
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .cargo-husky/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Exit immediately if any command returns non-zero exit status.
set -e

cargo fmt --all --check
just pre-commit
49 changes: 1 addition & 48 deletions .cargo-husky/hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,4 @@
# Exit immediately if any command returns non-zero exit status.
set -e

# `fmt` doesn't depend on which features are enabled
echo "### fmt --all --check ###"
cargo fmt --all --check

# With no features
echo "### build --no-default-features ###"
RUSTFLAGS="-D warnings" cargo build --no-default-features
echo "### nextest run --no-default-features ###"
cargo nextest run --no-default-features --no-fail-fast
# Nextest doesn't support doc tests, run those separately
echo "### test --doc --no-default-features ###"
cargo test --doc --no-default-features --no-fail-fast
echo "### check --no-default-features ###"
cargo check --no-default-features
echo "### clippy --all-targets --no-default-features -- -D warnings ###"
cargo clippy --all-targets --no-default-features -- -D warnings

# With default features
echo "### build ###"
cargo build
echo "### nextest run ###"
cargo nextest run --no-fail-fast
# Nextest doesn't support doc tests, run those separately
echo "### test --doc ###"
cargo test --doc --no-fail-fast
echo "### check ###"
cargo check
echo "### clippy --all-targets -- -D warnings ###"
cargo clippy --all-targets -- -D warnings

# With all features
echo "### build --all-features ###"
cargo build --all-features
echo "### nextest run --all-features ###"
cargo nextest run --all-features --no-fail-fast
# Nextest doesn't support doc tests, run those separately
echo "### test --doc --all-features ###"
cargo test --doc --all-features --no-fail-fast
echo "### check --all-features ###"
cargo check --all-features
echo "### clippy --all-targets --all-features -- -D warnings ###"
cargo clippy --all-targets --all-features -- -D warnings

echo "### cargo doc --all-features --no-deps ###"
RUSTDOCFLAGS="-D rustdoc::all -A rustdoc::private_intra_doc_links" cargo doc --all-features --no-deps

echo "### cargo minimal-versions check --direct --all-features ###"
cargo minimal-versions check --direct --all-features --no-dev-deps
just pre-push
41 changes: 39 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ test-all: test-unit test-book-all
test-watch:
cargo watch -s 'just test'

insta:
cargo insta review --workspace

serve-book:
mdbook serve book

Expand Down Expand Up @@ -65,9 +68,43 @@ alias fmt := format
format:
cargo fmt

check-fmt:
cargo fmt --all --check

pre-commit: check-fmt
pre-push: check-fmt

check-no-features:
cargo nextest run --no-default-features --no-fail-fast
# Nextest doesn't support doc tests, run those separately
cargo test --doc --no-default-features --no-fail-fast
cargo check --no-default-features
cargo clippy --all-targets --no-default-features -- -D warnings

check-default-features:
# With default features
cargo nextest run --no-fail-fast
# Nextest doesn't support doc tests, run those separately
cargo test --doc --no-fail-fast
cargo check
cargo clippy --all-targets -- -D warnings

check-all-features:
# With all features
cargo nextest run --all-features --no-fail-fast
# Nextest doesn't support doc tests, run those separately
cargo test --doc --all-features --no-fail-fast
cargo check --all-features
cargo clippy --all-targets --all-features -- -D warnings

check-docs:
RUSTDOCFLAGS="-D rustdoc::all -A rustdoc::private_intra_doc_links" cargo doc --all-features --no-deps

check-msrv:
cargo minimal-versions check --direct --all-features --no-dev-deps

# Run a suite of checks. These checks are fairly comprehensive and will catch most issues. However, they are still less than what is run in CI.
check:
.cargo-husky/hooks/pre-push
check: check-fmt check-no-features check-default-features check-all-features check-docs check-msrv

# Check if the Codecov config is valid
validate-codecov-config:
Expand Down

0 comments on commit 1898312

Please sign in to comment.