-
Notifications
You must be signed in to change notification settings - Fork 3
/
pr_check.sh
executable file
·40 lines (29 loc) · 967 Bytes
/
pr_check.sh
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
#!/bin/bash
set -exvo pipefail -o nounset
# utilize local go 1.19 version if available
GO_1_20="/opt/go/1.20.6/bin"
if [ -d "${GO_1_20}" ]; then
PATH="${GO_1_20}:${PATH}"
fi
PROJECT_ROOT=$(git rev-parse --show-toplevel)
DEPENDENCY_BIN="${PROJECT_ROOT}/.cache/dependencies/bin"
PRECOMMIT="${DEPENDENCY_BIN}/pre-commit"
function install_precommit() {
if [ -f "${PRECOMMIT}" ]; then
echo "pre-commit already installed"
return
fi
version=$1
url="https://github.com/pre-commit/pre-commit/releases/download/v${version}/pre-commit-${version}.pyz"
setup_dependencies && curl -sL "${url}" -o "${PRECOMMIT}" && chmod +x "${PRECOMMIT}"
}
function setup_dependencies() {
mkdir -p "${DEPENDENCY_BIN}"
}
function run-hooks() {
${PRECOMMIT} run \
--from-ref origin/main \
--to-ref HEAD \
--show-diff-on-failure
}
install_precommit "2.17.0" && run-hooks && go test -v -cover -race -count=1 ./...