forked from kyma-project/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-lint.sh
executable file
·65 lines (49 loc) · 1.73 KB
/
verify-lint.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
#!/usr/bin/env bash
# standard bash error handling
set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.
set -E # needs to be set if we want the ERR trap
readonly CURRENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
readonly ROOT_PATH=$( cd "${CURRENT_DIR}/.." && pwd )
readonly TMP_DIR=$(mktemp -d)
readonly GOLANGCI_LINT_VERSION="v1.49.0"
source "${CURRENT_DIR}/utilities.sh" || { echo 'Cannot load CI utilities.'; exit 1; }
cleanup() {
rm -rf "${TMP_DIR}" || true
}
trap cleanup EXIT SIGINT
golangci::install() {
export PATH="${INSTALL_DIR}:${PATH}"
shout "Install the golangci-lint in version ${GOLANGCI_LINT_VERSION}"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b "${INSTALL_DIR}" ${GOLANGCI_LINT_VERSION}
echo -e "${GREEN}√ install golangci-lint${NC}"
}
golangci::run_checks() {
shout "Run golangci-lint checks"
LINTS=(
# default golangci-lint lints
errcheck gosimple govet ineffassign staticcheck \
typecheck unused \
# additional lints
revive gofmt misspell gochecknoinits unparam exportloopref gosec
)
ENABLE=$(sed 's/ /,/g' <<< "${LINTS[@]}")
echo "Checks: ${LINTS[*]}"
cd ${ROOT_PATH}
golangci-lint --disable-all --enable="${ENABLE}" --timeout=10m run --config $CURRENT_DIR/.golangci.yml
echo -e "${GREEN}√ run golangci-lint${NC}"
}
main() {
result=$(git status --porcelain)
if [[ "${result}" != "" ]]; then
echo "ERROR: git is currently in a dirty state:"
echo "${result}"
exit 1
fi
if [[ "${SKIP_INSTALL:-x}" != "true" ]]; then
export INSTALL_DIR=${TMP_DIR}
golangci::install
fi
golangci::run_checks
}
main