kubernetes/hack/verify-golangci-lint-pr.sh
Patrick Ohly 04700e97d3 hack: prepare for strict golangci-lint in pull-verify-kubernetes
The long-term goal is that when "make verify" is invoked in pull job, it will
also run golangci-lint with the strict configuration and write an
$ARTIFACTS/golangci-lint-githubactions.log file with GitHub actions
annotations. How to get those published for the GitHub PR is open.

When "make verify" is invoked manually or in any other job, the stricter check
will be skipped. That works because "PR_NUMBER" is only set for pre-merge
jobs (https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md#job-environment-variables).

Because strict linting is still new and might not be useful without a better
UI (= GitHub annotations), this PR does not fully enable the integration into
"make verify". Instead, the new verify-golangci-lint-pr.sh is excluded from it
and needs to be run in a separate job.
2023-03-07 19:38:32 +01:00

38 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2022 The Kubernetes 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.
# This script checks a PR for the coding style for the Go language files using
# golangci-lint. It does nothing when invoked as part of a normal "make
# verify".
set -o errexit
set -o nounset
set -o pipefail
if [ ! "${PULL_NUMBER:-}" ]; then
echo 'Not testing anything because this is not a pull request.'
exit 0
fi
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
# TODO (https://github.com/kubernetes/test-infra/issues/17056):
# take this additional artifact and convert it to GitHub annotations
# to make it easier to see these problems during a PR review.
#
# -g "${ARTIFACTS}/golangci-lint-githubactions.log"
"${KUBE_ROOT}/hack/verify-golangci-lint.sh" -r "${PULL_BASE_SHA}" -s