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.
This commit is contained in:
parent
cc257387f1
commit
c9c0ee65d3
@ -80,9 +80,9 @@ jobs:
|
|||||||
check-lint:
|
check-lint:
|
||||||
executor: golang
|
executor: golang
|
||||||
resource_class: large
|
resource_class: large
|
||||||
working_directory: /go/src/github.com/hashicorp/packer
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
- run: git fetch --all
|
||||||
- run:
|
- run:
|
||||||
command: make ci-lint
|
command: make ci-lint
|
||||||
no_output_timeout: 30m
|
no_output_timeout: 30m
|
||||||
|
3
Makefile
3
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
|
ci-lint: install-lint-deps ## On ci only lint newly added Go source files
|
||||||
@echo "==> Running linter on 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
|
fmt: ## Format Go code
|
||||||
@go fmt ./...
|
@go fmt ./...
|
||||||
|
6
scripts/lint.sh
Executable file
6
scripts/lint.sh
Executable file
@ -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
|
Loading…
x
Reference in New Issue
Block a user