Skip to content

Commit 19ed0d2

Browse files
committed
Bash script to run local checks, replaces pre-commit hook
This functionality is additionally available via CI.
1 parent 9eabb7f commit 19ed0d2

File tree

3 files changed

+107
-75
lines changed

3 files changed

+107
-75
lines changed

check.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Small utility to run tests locally
2+
# Similar to minimal-ci
3+
4+
# No args specified: do everything
5+
if [ "$#" -eq 0 ]; then
6+
args=("fmt" "clippy" "test" "itest")
7+
else
8+
args=("$@")
9+
fi
10+
11+
# --help menu
12+
for arg in "${args[@]}"; do
13+
if [ "$arg" == "--help" ]; then
14+
echo "Usage: check.sh [<commands>]"
15+
echo ""
16+
echo "Each specified command will be run (until one fails)."
17+
echo "If no commands are specified, all checks are run (no doc; may take several minutes)."
18+
echo ""
19+
echo "Commands:"
20+
echo " fmt format code, fail if bad"
21+
echo " clippy validate clippy lints"
22+
echo " test run unit tests (no Godot)"
23+
echo " itest run integration tests (Godot)"
24+
echo " doc generate docs for 'gdnative' crate"
25+
echo ""
26+
echo "Examples:"
27+
echo " check.sh fmt clippy"
28+
echo " check.sh"
29+
exit 0
30+
fi
31+
done
32+
33+
# For integration tests
34+
function findGodot() {
35+
# User-defined GODOT_BIN
36+
if [ -n "$GODOT_BIN" ]; then
37+
echo "Found GODOT_BIN env var ($GODOT_BIN)"
38+
godotBin="$GODOT_BIN"
39+
40+
# Executable in path
41+
elif command -v godot &>/dev/null; then
42+
echo "Found 'godot' executable"
43+
godotBin="godot"
44+
45+
# Special case for Windows when there is a .bat file
46+
# Also consider that 'cmd /c' would need 'cmd //c' (https://stackoverflow.com/q/21357813)
47+
elif
48+
# Don't ask me why Godot returns 255 instead of 0
49+
godot.bat --version
50+
[ $? -eq 255 ]
51+
then
52+
echo "Found 'godot.bat' script"
53+
godotBin="godot.bat"
54+
55+
# Error case
56+
else
57+
echo "Godot executable not found"
58+
exit 2
59+
fi
60+
}
61+
62+
features="gdnative/async,gdnative/serde"
63+
cmds=()
64+
65+
for arg in "${args[@]}"; do
66+
case "$arg" in
67+
fmt)
68+
cmds+=("cargo fmt --all -- --check")
69+
;;
70+
clippy)
71+
cmds+=("cargo clippy --workspace --features $features -- -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented")
72+
;;
73+
test)
74+
cmds+=("cargo test --features $features")
75+
;;
76+
itest)
77+
findGodot
78+
cmds+=("cargo build --manifest-path test/Cargo.toml --features $features")
79+
cmds+=("cp target/debug/gdnative_test* test/project/lib/")
80+
cmds+=("$godotBin --path test/project")
81+
;;
82+
doc)
83+
cmds+=("cargo doc --lib -p gdnative --no-deps --features $features")
84+
;;
85+
*)
86+
echo "Unrecognized command '$arg'"
87+
exit 2
88+
;;
89+
esac
90+
done
91+
92+
RED='\033[1;31m'
93+
GREEN='\033[1;36m'
94+
END='\033[0m'
95+
for cmd in "${cmds[@]}"; do
96+
echo "> $cmd"
97+
$cmd || {
98+
printf "$RED\n=========================="
99+
printf "\ngodot-rust checker FAILED."
100+
printf "\n==========================\n$END"
101+
exit 1
102+
}
103+
done
104+
105+
printf "$GREEN\n=============================="
106+
printf "\ngodot-rust checker SUCCESSFUL."
107+
printf "\n==============================\n$END"

hooks/pre-commit.sh

Lines changed: 0 additions & 74 deletions
This file was deleted.

test/project/project.godot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ config_version=4
1010

1111
_global_script_classes=[ ]
1212
_global_script_class_icons={
13-
1413
}
1514

1615
[application]

0 commit comments

Comments
 (0)