Skip to content

Commit

Permalink
ci: fix lint script (#17080)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Jul 20, 2023
1 parent 3bbc370 commit 3ad0ca5
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions scripts/go-lint-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@ lint_module() {
}
export -f lint_module

lint_files() {
local go_files="$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$)"
if [[ -z "$go_files" && $GIT_DIFF ]]; then
go_files="$(echo $GIT_DIFF | grep \.go$ | grep -v \.pb\.go$)"
elif [[ -z "$go_files" ]]; then
echo "no files to lint"
exit 0
fi

for f in $go_files; do
local dir_name="$(dirname $f)"
echo "linting ${dir_name} [$(date -Iseconds -u)]"
golangci-lint run "${dir_name}" -c "${REPO_ROOT}/.golangci.yml" "$@"
done
}
export -f lint_files

# if LINT_DIFF env is set, only lint the files in the current commit otherwise lint all files
if [[ -z "${LINT_DIFF:-}" ]]; then
find "${REPO_ROOT}" -type f -name go.mod -print0 |
xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@"
else
lint_files "$@"
if [[ -z $GIT_DIFF ]]; then
GIT_DIFF=$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$) || true
fi

if [[ -z "$GIT_DIFF" ]]; then
echo "no files to lint"
exit 0
fi

for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do
echo "linting $f [$(date -Iseconds -u)]" &&
cd $f &&
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" &&
cd $REPO_ROOT
done
fi

0 comments on commit 3ad0ca5

Please sign in to comment.