forked from private-attribution/ipa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pre-commit
executable file
·109 lines (90 loc) · 3.03 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
# This is a pre-commit hook that validates code formatting.
#
# Install this by running the script with an argument of "install",
# which installs a symlink to .git/hooks/precommit:
# $ ln -s ../../hooks/pre-commit .git/hooks/pre-commit
root="$(git rev-parse --show-toplevel 2>/dev/null)"
set -e
# Some sanity checking.
hash cargo
[[ -n "$root" ]]
# Installation.
if [[ "$1" == "install" ]]; then
hook="$root"/.git/hooks/pre-commit
if [[ ! -e "$hook" ]]; then
ln -s ../../pre-commit "$hook"
echo "Installed git pre-commit hook at $hook"
else
echo "Hook already installed"
fi
exit
fi
save_merge_files() {
# Move MERGE_[HEAD|MODE|MSG] files to the root directory, and let `git stash push` save them.
for f in "$root"/.git/MERGE_*; do
if [[ -e "$f" ]]; then
t=$(basename $f)
mv -f "$f" "$t"
fi
done
}
restore_merge_files() {
# Moves MERGE files restored by `git stash pop` back into .git/ directory.
for f in MERGE_*; do
if [[ -e "$f" ]]; then
if [[ -e "${root}/.git/${f}" ]]; then
echo "Failed to restore ${f}. File already exists" 1>&2
else
mv -f "$f" "${root}/.git/${f}"
fi
fi
done
}
# Check formatting.
stashfile=$(mktemp .pre-commit.stashXXXXXX)
trap 'set +e;git stash pop -q; rm -f "$stashfile"; restore_merge_files' EXIT
save_merge_files
git stash push -k -u -q -m "pre-commit stash"
fmtconfig="imports_granularity=Crate,group_imports=StdExternalCrate"
if ! errors=($(cargo fmt --all -- --check --config "$fmtconfig" -l)); then
echo "Formatting errors found."
echo "Run \`cargo fmt --all -- --config \"$fmtconfig\"\` to fix the following files:"
for err in "${errors[@]}"; do
echo " $err"
done
exit 1
fi
check() {
msg="$1"
shift
if "$@"; then
echo "$msg: OK"
else
res=$?
echo "-----------------------"
echo "$msg: FAILED ($res)"
echo " ${@@Q}"
exit $res
fi
}
check "Benchmark compilation" \
cargo build --benches --no-default-features --features "enable-benches descriptive-gate"
check "Clippy checks" \
cargo clippy --tests -- -D warnings
check "Clippy concurrency checks" \
cargo clippy --tests --features shuttle -- -D warnings
check "Tests" \
cargo test
check "Web tests" \
cargo test --no-default-features --features "cli web-app real-world-infra test-fixture descriptive-gate"
check "Concurrency tests" \
cargo test --release --features shuttle
check "IPA benchmark" \
cargo bench --bench oneshot_ipa --no-default-features --features="enable-benches descriptive-gate" -- -n 62
check "IPA OPRF benchmark" \
cargo bench --bench oneshot_ipa --no-default-features --features="enable-benches descriptive-gate" -- -n 62 --oprf -c 16
check "Arithmetic circuit benchmark" \
cargo bench --bench oneshot_arithmetic --no-default-features --features "enable-benches descriptive-gate"
check "Sort benchmark" \
cargo bench --bench oneshot_sort --no-default-features --features="enable-benches descriptive-gate"