Skip to content

Commit

Permalink
feat: automatically run checks before commit
Browse files Browse the repository at this point in the history
  • Loading branch information
philpax committed Jun 22, 2023
1 parent 7927d0d commit f9f4775
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --all --verbose
fmt:
name: Clippy, formatting and docs
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hooks]
pre-commit = "cargo run -p precommit-check"

[logging]
verbose = true
66 changes: 66 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions binaries/llm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ num_cpus = "1.15.0"
color-eyre = { version = "0.6.2", default-features = false }
zstd = { version = "0.12", default-features = false }

[dev-dependencies]
rusty-hook = "^0.11.2"

[features]
cublas = ["llm/cublas"]
clblast = ["llm/clblast"]
Expand Down
8 changes: 8 additions & 0 deletions binaries/precommit-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "precommit-check"
version = "0.1.0"
edition = "2021"
publish = false

[package.metadata.release]
release = false
3 changes: 3 additions & 0 deletions binaries/precommit-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# precommit-check

Helper script to run pre-commit checks on a repository. Used with `rusty-hook` to execute all of the checks and early exit if any of them fail.
16 changes: 16 additions & 0 deletions binaries/precommit-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn main() {
// Ensure that these match `.github/workflows/rust.yml`.
cmd("cargo", &["check"]);
cmd("cargo", &["test", "--all"]);
cmd("cargo", &["fmt", "--check", "--all"]);
cmd("cargo", &["doc", "--workspace", "--exclude", "llm-cli"]);
cmd("cargo", &["clippy", "--", "-Dclippy::all"]);
}

fn cmd(cmd: &str, args: &[&str]) {
println!("=== Running command: {cmd} {args:?}");
let mut child = std::process::Command::new(cmd).args(args).spawn().unwrap();
if !child.wait().unwrap().success() {
panic!("Failed to run command: {} {:?}", cmd, args);
}
}
12 changes: 3 additions & 9 deletions doc/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ or on [Discord](https://discord.gg/YB9WaXYAWU)!
## Checking Changes

This project uses a [GitHub workflow](../.github/workflows/rust.yml) to enforce
code standards - it will execute the following commands, which can be performed
locally for faster turnaround and a better developer experience:
code standards.

```shell
cargo check
cargo test
cargo fmt --all
cargo doc --workspace --exclude llm-cli
cargo clippy --fix --allow-dirty -- -Dclippy::all
```
The `rusty-hook` project is used to run a similar set of checks automatically before committing.
If you would like to run these checks locally, use `cargo run -p precommit-check`.

## Regenerating GGML Bindings

Expand Down

0 comments on commit f9f4775

Please sign in to comment.