-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit-test-hook
More file actions
executable file
·41 lines (35 loc) · 1.1 KB
/
unit-test-hook
File metadata and controls
executable file
·41 lines (35 loc) · 1.1 KB
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
#!/usr/bin/env bash
set -e
# ######################################
# Ensure that a go module is initialized if not, skip the tests
# #######################################
ensure_go_module_initialized() {
if [[ ! -f go.mod ]]; then
echo "go.mod file not found, skipping the tests..."
exit 0
fi
}
# #######################################
# Run the pre-commit
# #######################################
hook() {
ensure_go_module_initialized
# get the root of the project
local root_dir
root_dir=$(git rev-parse --show-toplevel)
local toolchain_version="1.26.1"
if [[ -f "${root_dir}/.project-settings.env" ]]; then
# shellcheck disable=SC1090
source "${root_dir}/.project-settings.env"
toolchain_version="${GO_VERSION:-${toolchain_version}}"
fi
# run the pre-commit hook
pushd "${root_dir}" || exit
GOTOOLCHAIN=go${toolchain_version}+auto go test -v -cover ./... || exit 1
popd >/dev/null || exit
}
# #######################################
# Run the pre-commit if the ensure_go_module_initialized() function returns 0
# #######################################
ensure_go_module_initialized
hook