diff --git a/.cargo-husky/hooks/pre-push b/.cargo-husky/hooks/pre-push new file mode 100755 index 00000000..3c6555fa --- /dev/null +++ b/.cargo-husky/hooks/pre-push @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +if !(command cargo-make >/dev/null 2>&1); then # Check if cargo-make is installed + echo Attempting to run cargo-make as part of the pre-push hook but it\'s not installed. + echo Please install it by running the following command: + echo + echo " cargo install --force cargo-make" + echo + echo If you don\'t want to run cargo-make as part of the pre-push hook, you can run + echo the following command instead of git push: + echo + echo " git push --no-verify" + exit 1 +fi + +cargo make ci diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 693fdc8b..10931b19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: run: cargo make ci env: RUST_BACKTRACE: full + CARGO_HUSKY_DONT_INSTALL_HOOKS: true lint: runs-on: ubuntu-latest @@ -71,6 +72,8 @@ jobs: uses: taiki-e/install-action@cargo-llvm-cov - name: cargo llvm-cov run: cargo llvm-cov --all-features --lcov --output-path lcov.info + env: + CARGO_HUSKY_DONT_INSTALL_HOOKS: true - name: Upload to codecov.io uses: codecov/codecov-action@v3 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a162361..cf176eb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,6 +48,8 @@ Any idea with a large scale impact on the crate or its users should ideally be d To avoid any issues that may arrise with the CI/CD by not following the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) syntax, we recommend to install [Commitizen](https://commitizen-tools.github.io/commitizen/).\ By using this tool you automatically follow the configuration defined in [.cz.toml](.cz.toml). +Additionally, we're using [cargo-husky](https://github.com/rhysd/cargo-husky) to automatically load pre-push hook, which will run `cargo make ci` before each push. It will load the hook automatically when you run `cargo test`. If `cargo-make` is not installed, it will install it for you.\ +This will ensure that your code is formatted, compiles and passes all tests before you push. If you want to skip this check, you can use `git push --no-verify`. ## Continuous Integration diff --git a/Cargo.toml b/Cargo.toml index 854e1456..82d3fead 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,10 +48,11 @@ unicode-width = "0.1" [dev-dependencies] anyhow = "1.0.71" -rand = "0.8" argh = "0.1" +cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] } criterion = { version = "0.5", features = ["html_reports"] } fakeit = "1.1" +rand = "0.8" [[bench]] name = "paragraph"