diff --git a/tools/golangci-lint.sh b/tools/golangci-lint.sh index f28a089815..e14c8aa767 100755 --- a/tools/golangci-lint.sh +++ b/tools/golangci-lint.sh @@ -6,8 +6,13 @@ BUILD_ROOT="${REPO_ROOT}/build" BUILD_BIN="${BUILD_ROOT}/bin" NAME=golangci-lint -RELEASE=v1.47.3 -RELEASE_BINARY="${BUILD_BIN}/${NAME}" +RELEASE=v1.50.1 +OSX_RELEASE_256=0f615fb8c364f6e4a213f2ed2ff7aa1fc2b208addf29511e89c03534067bbf57 +LINUX_RELEASE_256=4ba1dc9dbdf05b7bdc6f0e04bdfe6f63aa70576f51817be1b2540bbce017b69a + +ARCH=amd64 + +RELEASE_BINARY="${BUILD_BIN}/${NAME}-${RELEASE}" main() { cd "${REPO_ROOT}/backend" @@ -21,7 +26,31 @@ ensure_binary() { echo "info: Downloading ${NAME} ${RELEASE} to build environment" mkdir -p "${BUILD_BIN}" - env GOBIN="${BUILD_BIN}" go install github.com/golangci/golangci-lint/cmd/golangci-lint@"${RELEASE}" + + case "${OSTYPE}" in + "darwin"*) os_type="darwin"; sum="${OSX_RELEASE_256}" ;; + "linux"*) os_type="linux"; sum="${LINUX_RELEASE_256}" ;; + *) echo "error: Unsupported OS '${OSTYPE}' for shellcheck install, please install manually" && exit 1 ;; + esac + + release_archive="/tmp/${NAME}-${RELEASE}.tar.gz" + + URL="https://github.com/golangci/golangci-lint/releases/download/${RELEASE}/golangci-lint-${RELEASE:1}-${os_type}-${ARCH}.tar.gz" + curl -sSL -o "${release_archive}" "${URL}" + echo ${sum} ${release_archive} | sha256sum --check --quiet - + + release_tmp_dir="/tmp/${NAME}-${RELEASE}" + mkdir -p "${release_tmp_dir}" + tar -xzf "${release_archive}" --strip=1 -C "${release_tmp_dir}" + + if [[ ! -f "${RELEASE_BINARY}" ]]; then + find "${BUILD_BIN}" -maxdepth 0 -regex '.*/'${NAME}'-[A-Za-z0-9\.]+$' -exec rm {} \; # cleanup older versions + mv "${release_tmp_dir}/${NAME}" "${RELEASE_BINARY}" + fi + + # Cleanup stale resources. + rm "${release_archive}" + rm -rf "${release_tmp_dir}" fi }