forked from red-hat-storage/ocs-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
golangci_lint.sh
executable file
·50 lines (37 loc) · 1.42 KB
/
golangci_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
#!/usr/bin/env bash
source hack/common.sh
# check for golangci-lint in *.go files
mkdir -p ${OUTDIR_TOOLS}
LINT_BIN="${OUTDIR_TOOLS}/golangci-lint"
LINT_VER="1.49.0"
check_bin_exists() {
which "${LINT_BIN}" >/dev/null 2>&1 && [[ "$(${LINT_BIN} --version)" == *"${LINT_VER}"* ]]
}
install_from_github() {
SCRIPT="${OUTDIR_TOOLS}/golangci-lint_install.sh"
URL="https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
echo ""; echo "Downloading golangci-lint installation script: ${URL}"
curl -JL -o "${SCRIPT}" "${URL}"
chmod +x "${SCRIPT}"
echo "Installing golangci-lint"
"${SCRIPT}" -db "${OUTDIR_TOOLS}" "v${LINT_VER}"; RET=$?
rm -f "${SCRIPT}"
return ${RET}
}
install_from_downstream() {
TGZ="${OUTDIR_TOOLS}/golangci-lint.tgz"
URL="https://mirror2.openshift.com/pub/ci/x86_64/golangci-lint/golangci-lint-${LINT_VER}/golangci-lint-${LINT_VER}-linux-amd64.tar.gz"
echo ""; echo "Upstream installation failed, trying downstream fallback: ${URL}"
curl -JL -o "${TGZ}" "${URL}"
tar -xzf "${TGZ}" -C "${OUTDIR_TOOLS}" --strip-components=1 "*/golangci-lint"; RET=$?
rm -f "${TGZ}"
return ${RET}
}
if ! (check_bin_exists || install_from_github || install_from_downstream); then
echo "Failed to install golangci-lint"
exit 1
fi
chmod +x "${OUTDIR_TOOLS}"/golangci-lint
echo ""; echo "Running golangci-lint"
GOLANGCI_LINT_CACHE=/tmp/golangci-cache "${OUTDIR_TOOLS}"/golangci-lint run ./...
exit