Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure golangci-lint for the correct OS #22

Merged
merged 3 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions boilerplate/_lib/ensure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ set -euo pipefail

GOLANGCI_LINT_VERSION="1.30.0"
DEPENDENCY=${1:-}
GOOS=$(go env GOOS)

case "${DEPENDENCY}" in
golangci-lint)
GOPATH=$(go env GOPATH)
if [ ! -f "${GOPATH}/bin/golangci-lint" ]; then
DOWNLOAD_URL="https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz"
curl -sfL "${DOWNLOAD_URL}" | tar -C "${GOPATH}/bin" -zx --strip-components=1 "golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint"
golangci-lint)
GOPATH=$(go env GOPATH)
if which golangci-lint ; then
exit
Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't ensure we're using $GOLANGCI_LINT_VERSION. As written, there are several ways that could go awry even when we're running the gocheck target in a container -- e.g. if the base container image we're using already has the binary (at the wrong version).

So IMO we really ought to include a version check here. Something like:

Suggested change
if which golangci-lint ; then
exit
if which golangci-lint && [[ $(golangci-lint --version) == *" v$GOLANGCI_LINT_VERSION "* ]]; then
exit

else
mkdir -p "${GOPATH}/bin"
echo "${PATH}" | grep -q "${GOPATH}/bin"
IN_PATH=$?
if [ $IN_PATH != 0 ]; then
echo "${GOPATH}/bin not in $$PATH"
exit 1
fi
DOWNLOAD_URL="https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-${GOOS}-amd64.tar.gz"
curl -sfL "${DOWNLOAD_URL}" | tar -C "${GOPATH}/bin" -zx --strip-components=1 "golangci-lint-${GOLANGCI_LINT_VERSION}-${GOOS}-amd64/golangci-lint"
Copy link
Member

@dustman9000 dustman9000 Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that GOOS is defined, default to go env GOOS if not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the amd64 bit also break on Mac? (ppc or something?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Macs have used intel x86 architecture for about 10 years now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL.

We're still totally screwing all the people trying to develop on AIX though.

fi
;;
*)
echo "Unknown dependency: ${DEPENDENCY}"
exit 1
*)
echo "Unknown dependency: ${DEPENDENCY}"
exit 1
;;
esac
8 changes: 5 additions & 3 deletions boilerplate/openshift/golang_osd_cluster_operator/standard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS=

GOBUILDFLAGS=-gcflags="all=-trimpath=${GOPATH}" -asmflags="all=-trimpath=${GOPATH}"

# GOLANGCI_LINT_CACHE needs to be set to a directory which is writeable
# Relevant issue - https://github.com/golangci/golangci-lint/issues/734
GOLANGCI_LINT_CACHE ?= /tmp/golangci-cache

TESTTARGETS := $(shell ${GOENV} go list -e ./... | egrep -v "/(vendor)/")
# ex, -v
TESTOPTS :=
Expand Down Expand Up @@ -72,9 +76,7 @@ docker-push: push
.PHONY: gocheck
gocheck: ## Lint code
boilerplate/_lib/ensure.sh golangci-lint
# GOLANGCI_LINT_CACHE needs to be set to a directory which is writeable
# Relevant issue - https://github.com/golangci/golangci-lint/issues/734
GOLANGCI_LINT_CACHE=/tmp/golangci-cache golangci-lint run -c boilerplate/openshift/golang_osd_cluster_operator/golangci.yml ./...
GOLANGCI_LINT_CACHE=${GOLANGCI_LINT_CACHE} golangci-lint run -c boilerplate/openshift/golang_osd_cluster_operator/golangci.yml ./...

.PHONY: gogenerate
gogenerate:
Expand Down