-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-hook.sh
81 lines (68 loc) · 2.32 KB
/
commit-hook.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
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
#!/usr/bin/env sh
# Verify commit message conforms to the guidelines
# see .conform.yaml for the current settings
docker run --rm -v "${PWD}":/src -w /src \
ghcr.io/siderolabs/conform:v0.1.0-alpha.22 enforce --commit-msg-file "$1"
CONFORM_RESULT=$?
if [ $CONFORM_RESULT -ne 0 ]; then
echo Check Failed for commit message
exit $CONFORM_RESULT;
fi
# stash any unstaged changes because we don't want to check any changes that are not part of this commit
git stash -q --keep-index --include-untracked
# Lint markdown files
docker run -v "${PWD}":/workdir davidanson/markdownlint-cli2 "**/*.md"
MD_RESULT=$?
# Lint shell scripts
git ls-files | grep ".*\.sh$" | xargs docker run --rm \
-v "${PWD}":/mnt koalaman/shellcheck:stable
SHELLCHECK_RESULT=$?
# Lint yaml files
docker run --rm -v "${PWD}:/data" cytopia/yamllint:latest --strict .
YAML_RESULT=$?
# Lint docker files
git ls-files | \
grep '.*Dockerfile.*' | \
xargs -I'{}' docker run --rm -i -v "${PWD}"/{}:/{} -e HADOLINT_FAILURE_THRESHOLD=style hadolint/hadolint hadolint {}
HADOLINT_RESULT=$?
# Check backend code
# run spotlessCheck via gradle
echo Checking api code in "${PWD}"
cd api && ./gradlew spotlessCheck --daemon
SPOTLESS_RESULT=$?
# Now run detekt
./gradlew detekt
DETEKT_RESULT=$?
# Check client code with golangi
cd ../client || exit 1
echo Checking client code in "${PWD}"
docker run --rm -v "${PWD}:/workspace" -w "/workspace/." \
golangci/golangci-lint golangci-lint run
GOLANGCI_RESULT=$?
cd ..
# unstash the stashed changes
git stash pop -q
# Check exit codes
RED='\033[0;31m'
if [ $MD_RESULT -ne 0 ]; then
printf "%bCheck Failed for markdown\n" "${RED}"
exit $MD_RESULT;
elif [ $SHELLCHECK_RESULT -ne 0 ]; then
printf "%bCheck Failed for shellcheck\n" "${RED}"
exit $SHELLCHECK_RESULT;
elif [ $HADOLINT_RESULT -ne 0 ]; then
printf "%bCheck Failed for hadolint\n" "${RED}"
exit $HADOLINT_RESULT;
elif [ $SPOTLESS_RESULT -ne 0 ]; then
printf "%bCheck Failed for spotless\n" "${RED}"
exit $SPOTLESS_RESULT;
elif [ $DETEKT_RESULT -ne 0 ]; then
printf "%bCheck Failed for detekt\n" "${RED}"
exit $DETEKT_RESULT;
elif [ $GOLANGCI_RESULT -ne 0 ]; then
printf "%bCheck Failed for golangci\n" "${RED}"
exit $GOLANGCI_RESULT;
elif [ $YAML_RESULT -ne 0 ]; then
printf "%bCheck Failed for yml\n" "${RED}"
exit $YAML_RESULT;
fi