From ddfc1e31a74cc8dd88443590f6f4599bc1ee7847 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 11 May 2020 08:16:51 +0200 Subject: [PATCH] Running the linter on GitHub Actions Signed-off-by: David Gageot --- .github/workflows/PR.yaml | 10 +++++++ Makefile | 5 ++++ hack/checks.sh | 4 --- hack/{linter.sh => golangci-lint.sh} | 18 +++++------- hack/linters.sh | 44 ++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/PR.yaml rename hack/{linter.sh => golangci-lint.sh} (68%) create mode 100755 hack/linters.sh diff --git a/.github/workflows/PR.yaml b/.github/workflows/PR.yaml new file mode 100644 index 00000000000..7a6030f439e --- /dev/null +++ b/.github/workflows/PR.yaml @@ -0,0 +1,10 @@ +name: PR +on: pull_request +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: linters + run: make linters + continue-on-error: false \ No newline at end of file diff --git a/Makefile b/Makefile index 7dce01b47ed..feb9cc9ef09 100644 --- a/Makefile +++ b/Makefile @@ -103,6 +103,7 @@ $(BUILD_DIR): test: $(BUILD_DIR) @ ./hack/gotest.sh -count=1 -race -short -timeout=90s $(SKAFFOLD_TEST_PACKAGES) @ ./hack/checks.sh + @ ./hack/linters.sh .PHONY: coverage coverage: $(BUILD_DIR) @@ -113,6 +114,10 @@ coverage: $(BUILD_DIR) checks: $(BUILD_DIR) @ ./hack/checks.sh +.PHONY: linters +linters: $(BUILD_DIR) + @ ./hack/linters.sh + .PHONY: quicktest quicktest: @ ./hack/gotest.sh -short -timeout=60s $(SKAFFOLD_TEST_PACKAGES) diff --git a/hack/checks.sh b/hack/checks.sh index 487923fb968..da4bf578810 100755 --- a/hack/checks.sh +++ b/hack/checks.sh @@ -22,10 +22,6 @@ echo "Running validation scripts..." scripts=( "hack/check-schema-changes.sh" "hack/check-skaffold-builder.sh" - "hack/boilerplate.sh" - "hack/gofmt.sh" - "hack/pedantic-imports.sh" - "hack/linter.sh" "hack/check-samples.sh" "hack/check-docs.sh" "hack/test-generated-proto.sh" diff --git a/hack/linter.sh b/hack/golangci-lint.sh similarity index 68% rename from hack/linter.sh rename to hack/golangci-lint.sh index 05046df046b..73824e5ed32 100755 --- a/hack/linter.sh +++ b/hack/golangci-lint.sh @@ -17,31 +17,29 @@ set -e -o pipefail DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BIN=${DIR}/bin VERSION=1.26.0 function install_linter() { echo "Installing GolangCI-Lint" - ${DIR}/install_golint.sh -b $GOPATH/bin v$VERSION + ${DIR}/install_golint.sh -b ${BIN} v$VERSION } -if ! [ -x "$(command -v golangci-lint)" ] ; then +if ! [ -x "$(command -v ${BIN}/golangci-lint)" ] ; then install_linter -elif [[ $(golangci-lint --version | grep -c " $VERSION ") -eq 0 ]] +elif [[ $(${BIN}/golangci-lint --version | grep -c " $VERSION ") -eq 0 ]] then echo "required golangci-lint: v$VERSION" echo "current version: $(golangci-lint --version)" echo "reinstalling..." - rm $(which golangci-lint) + rm $(which ${BIN}/golangci-lint) install_linter fi FLAGS="" -if [[ "${TRAVIS}" == "true" ]]; then - # Use less memory on Travis - # See https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint - export GOGC=5 - FLAGS="-j1 -v --print-resources-usage" +if [[ "${CI}" == "true" ]]; then + FLAGS="-v --print-resources-usage" fi -$GOPATH/bin/golangci-lint run ${FLAGS} -c ${DIR}/golangci.yml \ +${BIN}/golangci-lint run ${FLAGS} -c ${DIR}/golangci.yml \ | awk '/out of memory/ || /Timeout exceeded/ {failed = 1}; {print}; END {exit failed}' diff --git a/hack/linters.sh b/hack/linters.sh new file mode 100755 index 00000000000..396f0f196e8 --- /dev/null +++ b/hack/linters.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Copyright 2019 The Skaffold Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +RED='\033[0;31m' +GREEN='\033[0;32m' +RESET='\033[0m' + +echo "Running linters..." +scripts=( + "hack/boilerplate.sh" + "hack/gofmt.sh" + "hack/pedantic-imports.sh" + "hack/golangci-lint.sh" +) +fail=0 +for s in "${scripts[@]}"; do + echo "RUN ${s}" + + start=$(date +%s) + ./$s + result=$? + end=$(date +%s) + + if [[ $result -eq 0 ]]; then + echo -e "${GREEN}PASSED${RESET} ${s} in $((end-start))s" + else + echo -e "${RED}FAILED${RESET} ${s}" + fail=1 + fi +done +exit $fail