Rust checks for http://pre-commit.com/
Make sure pre-commit is installed.
Create a blank configuration file at the root of your repo, if needed:
touch .pre-commit-config.yamlAdd a new repo entry in your configuration file:
repos:
- repo: https://github.com/tobinjt/rust-pre-commit-checks
rev: v1.0.0
hooks:
# See below for hook documentation, in particular the binaries you need
# to install for each hook.
- id: cargo-check
- id: cargo-clippy
- id: cargo-fmt
- id: cargo-llvm-cov
- id: cargo-test
- id: check-tag-versionInstall the pre-commit script:
pre-commit install --install-hooksIf you're using check-tag-version you'll also need to run:
pre-commit install --hook-type pre-pushYou need to install the tools used for each hook and ensure they're in $PATH
for the checks to work. The required tool and brief installation instructions,
if any, is documented below beside each hook.
I haven't used cargo workspaces so these hooks don't support them because I have no way to test the config. PRs adding workspaces support are welcome.
Runs cargo check.
cargo check should be installed by default with your Rust installation.
Runs cargo clippy. The default
args passed are --deny warnings to fail on warnings.
Install with:
rustup component add clippyRuns cargo fmt. cargo fmt should be
installed by default with your Rust installation.
Runs cargo llvm-cov test. The
default args passed are --quiet to reduce output; consider using
--fail-uncovered-lines=X and --fail-uncovered-functions=X to require high
test coverage.
Install with (see https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#from-source). :
cargo +stable install cargo-llvm-cov --lockedConfigure with:
repos:
- repo: https://github.com/tobinjt/rust-pre-commit-checks
rev: v1.0.0
hooks:
- id: cargo-llvm-cov
args:
[
"--fail-uncovered-lines=5",
"--fail-uncovered-functions=1",
"--quiet",
"--show-missing-lines",
]Runs cargo test.
cargo test should be installed by default with your Rust installation.
This runs on push, not on commit. If a Git tag is being pushed, and it
doesn't match the version in Cargo.toml, this check will fail. The intent is
to prevent mismatches between the two, because you generally want them to be in
sync.
You might want to consider using https://github.com/crate-ci/cargo-release to streamline the release process, but johntobin doesn't have any experience with that tooling.
Apache 2.0; see LICENSE for details.