2023-03-23 12:27:09 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-03-29 08:13:26 -04:00
|
|
|
###### script header ######
|
|
|
|
|
2023-03-23 12:27:09 -04:00
|
|
|
lib=$(realpath @@BASE_LIB@@) || exit 1
|
2023-03-29 08:13:26 -04:00
|
|
|
stat "${lib}" >> /dev/null || exit 1
|
2023-03-23 12:27:09 -04:00
|
|
|
|
|
|
|
# shellcheck source=../sh/lib.bash
|
|
|
|
if ! source "${lib}"; then
|
|
|
|
echo "Error: could not find import"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-03-29 08:13:26 -04:00
|
|
|
golangcilint=$(realpath @@GOLANGCI-LINT@@)
|
|
|
|
stat "${golangcilint}" >> /dev/null
|
|
|
|
go=$(realpath @@GO@@)
|
|
|
|
stat "${go}" >> /dev/null
|
|
|
|
|
|
|
|
cd "${BUILD_WORKSPACE_DIRECTORY}"
|
|
|
|
|
|
|
|
###### script body ######
|
2023-03-23 12:27:09 -04:00
|
|
|
|
|
|
|
readarray -t <<< "$(${go} list -f '{{.Dir}}' -m)"
|
|
|
|
modules=("${MAPFILE[@]}")
|
|
|
|
|
|
|
|
excludeMods=(
|
|
|
|
"hack/tools"
|
|
|
|
)
|
|
|
|
|
|
|
|
echo "The following Go modules are excluded and won't be linted with golangci-lint:"
|
|
|
|
for exclude in "${excludeMods[@]}"; do
|
|
|
|
for i in "${!modules[@]}"; do
|
|
|
|
if [[ ${modules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}" ]]; then
|
|
|
|
echo " ${modules[i]}"
|
|
|
|
unset 'modules[i]'
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
statuscode=0
|
|
|
|
|
|
|
|
echo "Linting the following Go modules with golangci-lint:"
|
|
|
|
for mod in "${modules[@]}"; do
|
|
|
|
echo " ${mod}"
|
|
|
|
GOROOT=$(${go} env GOROOT) ${golangcilint} run --timeout=15m "${mod}/..." || statuscode=$?
|
|
|
|
done
|
|
|
|
|
|
|
|
exit "${statuscode}"
|