From 53b37e2beb6111780096c84221379800898c03c3 Mon Sep 17 00:00:00 2001 From: Medya Ghazizadeh <medyagh@users.noreply.github.com> Date: Wed, 24 Jul 2019 10:34:53 -0700 Subject: [PATCH] Separate make lint targets for developers vs travis (#4852) * Lowering memory for golangci-lint * ci 2 jobs , gogc 5 * change ci jobs number * added a new make target for ci and for developers * reuse golint options for two targets --- Makefile | 24 ++++++++++++++++-------- test.sh | 14 +++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 3499b752b4..8b61f2bca6 100755 --- a/Makefile +++ b/Makefile @@ -48,9 +48,15 @@ KERNEL_VERSION ?= 4.16.14 GO_VERSION ?= $(shell go version | cut -d' ' -f3 | sed -e 's/go//') GOLINT_VERSION ?= v1.17.1 # Limit number of default jobs, to avoid the CI builds running out of memory -GOLINT_JOBS ?= 1 +GOLINT_JOBS ?= 4 # see https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint -GOLINT_GOGC ?= 10 +GOLINT_GOGC ?= 8 +# options for lint (golangci-lint) +GOLINT_OPTIONS = --deadline 4m \ + --build-tags "${MINIKUBE_INTEGRATION_BUILD_TAGS}" \ + --enable goimports,gocritic,golint,gocyclo,interfacer,misspell,nakedret,stylecheck,unconvert,unparam \ + --exclude 'variable on range scope.*in function literal|ifElseChain' + export GO111MODULE := on @@ -80,6 +86,7 @@ MINIKUBE_TEST_FILES := ./cmd/... ./pkg/... # npm install -g markdownlint-cli MARKDOWNLINT ?= markdownlint + MINIKUBE_MARKDOWN_FILES := README.md docs CONTRIBUTING.md CHANGELOG.md MINIKUBE_BUILD_TAGS := container_image_ostree_stub containers_image_openpgp @@ -278,15 +285,16 @@ out/linters/golangci-lint: mkdir -p out/linters curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION) +# this one is meant for local use .PHONY: lint lint: pkg/minikube/assets/assets.go pkg/minikube/translate/translations.go out/linters/golangci-lint + ./out/linters/golangci-lint run ${GOLINT_OPTIONS} ./... + +# lint-ci is slower version of lint and is meant to be used in ci (travis) to avoid out of memory leaks. +.PHONY: lint-ci +lint-ci: pkg/minikube/assets/assets.go pkg/minikube/translate/translations.go out/linters/golangci-lint GOGC=${GOLINT_GOGC} ./out/linters/golangci-lint run \ - --concurrency ${GOLINT_JOBS} \ - --deadline 4m \ - --build-tags "${MINIKUBE_INTEGRATION_BUILD_TAGS}" \ - --enable goimports,gocritic,golint,gocyclo,interfacer,misspell,nakedret,stylecheck,unconvert,unparam \ - --exclude 'variable on range scope.*in function literal|ifElseChain' \ - ./... + --concurrency ${GOLINT_JOBS} ${GOLINT_OPTIONS} ./... .PHONY: reportcard reportcard: diff --git a/test.sh b/test.sh index 75d119acba..4ea7852c6f 100755 --- a/test.sh +++ b/test.sh @@ -20,10 +20,10 @@ exitcode=0 echo "= go mod ================================================================" go mod download 2>&1 | grep -v "go: finding" || true -go mod tidy -v && echo ok || ((exitcode+=2)) +go mod tidy -v && echo ok || ((exitcode += 2)) echo "= make lint =============================================================" -make -s lint && echo ok || ((exitcode+=4)) +make -s lint-ci && echo ok || ((exitcode += 4)) echo "= boilerplate ===========================================================" readonly PYTHON=$(type -P python || echo docker run --rm -it -v $(pwd):/minikube -w /minikube python python) @@ -32,24 +32,24 @@ missing="$($PYTHON ${BDIR}/boilerplate.py --rootdir . --boilerplate-dir ${BDIR} if [[ -n "${missing}" ]]; then echo "boilerplate missing: $missing" echo "consider running: ${BDIR}/fix.sh" - ((exitcode+=4)) + ((exitcode += 4)) else echo "ok" fi echo "= schema_check ==========================================================" -go run deploy/minikube/schema_check.go >/dev/null && echo ok || ((exitcode+=8)) +go run deploy/minikube/schema_check.go >/dev/null && echo ok || ((exitcode += 8)) echo "= go test ===============================================================" cov_tmp="$(mktemp)" readonly COVERAGE_PATH=./out/coverage.txt -echo "mode: count" > "${COVERAGE_PATH}" +echo "mode: count" >"${COVERAGE_PATH}" pkgs=$(go list -f '{{ if .TestGoFiles }}{{.ImportPath}}{{end}}' ./cmd/... ./pkg/... | xargs) go test \ -tags "container_image_ostree_stub containers_image_openpgp" \ -covermode=count \ -coverprofile="${cov_tmp}" \ - ${pkgs} && echo ok || ((exitcode+=16)) -tail -n +2 "${cov_tmp}" >> "${COVERAGE_PATH}" + ${pkgs} && echo ok || ((exitcode += 16)) +tail -n +2 "${cov_tmp}" >>"${COVERAGE_PATH}" exit "${exitcode}"