From 20e836b2889643363d59b1ace1b0211259a3e363 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Wed, 12 Apr 2023 10:11:32 -0400 Subject: [PATCH] ci: lint all modules even if one module fails The previous implementation stopped linting when it encountered its first module that failed the linter. Now, use a more idiomatic find|xargs pattern, which will run every module and exit non-zero if any module fails to lint. This will speed up the feedback cycle on CI in the event that multiple modules fail linting. --- scripts/go-lint-all.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/go-lint-all.sh b/scripts/go-lint-all.sh index 4518046191ede..6d1c7c20fdb66 100644 --- a/scripts/go-lint-all.sh +++ b/scripts/go-lint-all.sh @@ -1,11 +1,24 @@ #!/usr/bin/env bash -set -eu +set -eu -o pipefail -export pwd=$(pwd) +if [ $# -ne 0 ]; then + >&2 echo "USAGE: $0 -for modfile in $(find . -name go.mod); do - echo "linting $(dirname $modfile)" - DIR=$(dirname $modfile) - (cd $DIR; golangci-lint run ./... -c $pwd/.golangci.yml $@) -done +Runs golang-ci lint against all modules in the cosmos-sdk git repository" + + exit 1 +fi + +REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" +export REPO_ROOT + +lint_module() { + cd "$(dirname "$1")" && + echo "linting $(grep "^module" go.mod)" && + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" +} +export -f lint_module + +find "${REPO_ROOT}" -type f -name go.mod -print0 | + xargs -0 -I{} bash -c 'lint_module "$1"' _ {}