Skip to content

Commit cac4da8

Browse files
committed
chore: Add hk git hook manager
This adds [hk](hk.jdx.dev) as a git hook manager and configures it to run for all Rust projects in `core/` as well as `foreign/python`.
1 parent 2371cb0 commit cac4da8

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ coming onto our [Discussions](https://github.com/apache/Iggy/discussions) and di
4747
This way we can talk through the solution and discuss if a change that large is even needed!
4848
This will produce a quicker response to the change and likely produce code that aligns better with our process.
4949

50+
### Hooks
51+
52+
Iggy uses [hk](hk.jdx.dev) for managing git hooks, these should be installed to make sure formatting is done, build works and tests passes before a pull request is opened. The hooks run conditionally depending on the changed files and will trigger tasks for any changed project. Tasks launched by hooks require tools to be installed and setup for each project they run for, i.e. virtualenv has to be setup and activated for `foreign/python`.
53+
5054
### CI
5155

5256
Currently, Iggy uses GitHub Actions to run tests. The workflows are defined in `.github/workflows`.

hk.pkl

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
amends "package://github.com/jdx/hk/releases/download/v1.2.0/hk@1.2.0#/Config.pkl"
2+
import "package://github.com/jdx/hk/releases/download/v1.2.0/hk@1.2.0#/Builtins.pkl"
3+
4+
local rust_steps = new Mapping<String, Step> {
5+
["cargo-fmt"] {
6+
workspace_indicator = "Cargo.toml"
7+
glob = "*.rs"
8+
check = "cargo fmt --check --manifest-path {{workspace_indicator}}"
9+
fix = "cargo fmt --manifest-path {{workspace_indicator}}"
10+
}
11+
["cargo-clippy"] {
12+
workspace_indicator = "Cargo.toml"
13+
glob = "*.rs"
14+
check = "cargo clippy --manifest-path {{workspace_indicator}}"
15+
fix = "cargo clippy --fix --manifest-path {{workspace_indicator}}"
16+
}
17+
["cargo-check"] {
18+
workspace_indicator = "Cargo.toml"
19+
glob = "*.rs"
20+
check = "cargo check --manifest-path {{workspace_indicator}}"
21+
}
22+
["cargo-test"] {
23+
workspace_indicator = "Cargo.toml"
24+
glob = "*.rs"
25+
check = "cargo test --manifest-path {{workspace_indicator}}"
26+
}
27+
}
28+
29+
local python_steps = new Mapping<String, Step> {
30+
["python-maturin-develop"] {
31+
glob = "foreign/python/*"
32+
dir = "foreign/python"
33+
check = "maturin develop"
34+
exclusive = true
35+
}
36+
["python-cargo-run-stub-gen"] {
37+
glob = "foreign/python/*"
38+
dir = "foreign/python"
39+
check = "cargo run --bin stub_gen"
40+
exclusive = true
41+
}
42+
["python-pytest"] {
43+
glob = "foreign/python/*"
44+
dir = "foreign/python"
45+
check = "pytest -v"
46+
exclusive = true
47+
}
48+
}
49+
50+
local all_steps = new Mapping<String, Step> {
51+
...rust_steps
52+
...python_steps
53+
}
54+
55+
hooks {
56+
["pre-commit"] {
57+
fix = true
58+
stash = "git"
59+
steps = all_steps
60+
}
61+
["pre-push"] {
62+
steps = all_steps
63+
}
64+
["fix"] {
65+
fix = true
66+
steps = all_steps
67+
}
68+
["check"] {
69+
steps = all_steps
70+
}
71+
}

0 commit comments

Comments
 (0)