travis: replace golangci.com service with travis-local golangci-lint

This commit is contained in:
Dan Kortschak
2020-03-14 22:07:35 +10:30
parent 9d7b98d9e6
commit 054b6072ef
3 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1 @@
../../script.d/check-lint.sh

47
.travis/script.d/check-lint.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
if [ "${TRAVIS_CPU_ARCH}" != "amd64" ]; then
# TODO(kortschak): Remove this when git fetch --shallow-exclude is supported by git on arm64.
# See https://travis-ci.community/t/git-fetch-shallow-exclude-does-not-work-on-arm64-architecture/7583
echo "Skip lint check on arm64"
exit 0
fi
if [ -n "${TAGS}" ]; then
echo "Skip redundant lint check"
exit 0
fi
BRANCH=${TRAVIS_BRANCH}
if [ "${BRANCH}" == "master" ] && [ -n "${TRAVIS_PULL_REQUEST_BRANCH}" ]; then
BRANCH=${TRAVIS_PULL_REQUEST_BRANCH}
fi
if [ "${BRANCH}" == "master" ]; then
# Don't run linter on master; it's too late by then.
exit 0
fi
if [ "${TRAVIS_COMMIT}" == "${TRAVIS_TAG}" ]; then
# Don't run linter on tag pushes.
exit 0
fi
set -xe
# Get all the commits on the branch, and the base commit.
git fetch --shallow-exclude=master origin ${BRANCH}
git log --oneline
if [ -z "${TRAVIS_PULL_REQUEST_BRANCH}" ]; then
# Get the previous commit as well if we are not in a pull request build.
# Otherwise we already have the base commit.
COMMITS=$(git log --oneline | wc -l)
git fetch --depth=$((COMMITS+1)) origin ${BRANCH}
fi
# Travis does not correctly report the branch commit range in ${TRAVIS_COMMIT_RANGE}
# if there has been an amended commit, so just get it from the git log.
SINCE=$(git log --oneline --reverse | head -n1 | cut -f1 -d' ')
# Lint changes since we were on master.
golangci-lint run --new-from-rev=${SINCE}

View File

@@ -9,6 +9,8 @@ pushd $WORK
# Required for format check.
go get golang.org/x/tools/cmd/goimports
# Required for linting check: apparently golangci-lint should not be installed using go get (https://github.com/golangci/golangci-lint#go).
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.8
# Required for imports check.
go get gonum.org/v1/tools/cmd/check-imports
# Required for copyright header check.