From c9c0ee65d318e5da4ed79a38eef0d269029cde80 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Tue, 14 Apr 2020 06:03:22 -0400 Subject: [PATCH] circle-ci: update ci-lint steps (#9043) * new-from-rev option is showing inconsistent results on circle and locally. This change moves to a custom command `script/lint.sh` that gets a list of added go files and pipes them to golangci-lint for testing. * Add a git fetch as a step before retrieving merge-base changes to fix the issue described at https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194/2 * Moved source code out of GOPATH to ensure go mod support and reduce the risk of having golangci-lint trying to scan all of the files within GOPATH. This was an issue in the past, in changing it I found less OOM issues on circle. --- .circleci/config.yml | 2 +- Makefile | 3 +-- scripts/lint.sh | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100755 scripts/lint.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index ed11fcc5a..27884d8cb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,9 +80,9 @@ jobs: check-lint: executor: golang resource_class: large - working_directory: /go/src/github.com/hashicorp/packer steps: - checkout + - run: git fetch --all - run: command: make ci-lint no_output_timeout: 30m diff --git a/Makefile b/Makefile index 96494ebf6..23872ac41 100644 --- a/Makefile +++ b/Makefile @@ -84,8 +84,7 @@ lint: install-lint-deps ## Lint Go code ci-lint: install-lint-deps ## On ci only lint newly added Go source files @echo "==> Running linter on newly added Go source files..." - GO111MODULE=on golangci-lint run --new-from-rev=`git merge-base master HEAD` ./... - + @GO111MODULE=on sh -c "$(CURDIR)/scripts/lint.sh" fmt: ## Format Go code @go fmt ./... diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100755 index 000000000..cfe0e6baa --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +CHANGED_FILES=$(git diff --name-status `git merge-base origin/master HEAD`...HEAD | grep '^A.*\.go$'| awk '{print $2}') +if [ ! -z "${CHANGED_FILES}" ]; then + echo $CHANGED_FILES | xargs -n1 golangci-lint run +fi