ci: speed up lint job (backport #17071) (#17076)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
mergify[bot]
2023-07-20 18:58:54 +02:00
committed by GitHub
co-authored by Julien Robert
parent 75501a16e1
commit ab140e5a56
5 changed files with 54 additions and 11 deletions
+25 -3
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -eu -o pipefail
set -e -o pipefail
REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
export REPO_ROOT
@@ -14,5 +14,27 @@ lint_module() {
}
export -f lint_module
find "${REPO_ROOT}" -type f -name go.mod -print0 |
xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@" # Prepend go.mod file before command-line args.
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 "$@"
fi