[CI][BugFix] ShellCheck cleanup to remove baseline and preserve runtime behavior (#34514)

Signed-off-by: junuxyz <216036880+junuxyz@users.noreply.github.com>
This commit is contained in:
junuxyz
2026-02-17 21:22:56 +09:00
committed by GitHub
parent 28bffe9466
commit c61a98f529
55 changed files with 338 additions and 464 deletions

View File

@@ -2,7 +2,6 @@
set -euo pipefail
scversion="stable"
baseline="tools/pre_commit/shellcheck.baseline"
if [ -d "shellcheck-${scversion}" ]; then
export PATH="$PATH:$(pwd)/shellcheck-${scversion}"
@@ -20,38 +19,6 @@ if ! [ -x "$(command -v shellcheck)" ]; then
fi
# TODO - fix warnings in .buildkite/scripts/hardware_ci/run-amd-test.sh
# collects warnings as "file:SCcode" pairs for baseline comparison.
collect() {
find . -path ./.git -prune -o -name "*.sh" \
-not -path "./.buildkite/scripts/hardware_ci/run-amd-test.sh" -print0 | \
xargs -0 sh -c 'for f in "$@"; do git check-ignore -q "$f" || shellcheck -s bash -f gcc "$f" || true; done' -- | \
sed -nE 's|^\./||; s|^([^:]+):[0-9]+:[0-9]+:.*\[(SC[0-9]+)\]$|\1:\2|p' | \
sort -u
}
if [[ "${1:-}" == "--generate-baseline" ]]; then
collect > "$baseline"
echo "Wrote baseline to $baseline"
exit 0
fi
if [[ ! -f "$baseline" ]]; then
echo "Baseline not found: $baseline (run: $0 --generate-baseline)"
exit 1
fi
current="$(mktemp)"
trap 'rm -f "$current"' EXIT
collect > "$current"
# finds new warnings not in baseline
new_errors="$(comm -23 "$current" <(sort -u "$baseline") || true)"
if [ -n "$new_errors" ]; then
echo "$new_errors" | cut -d: -f1 | sort -u | while IFS= read -r file; do
if [[ -f "$file" ]]; then
codes=$(echo "$new_errors" | awk -F: -v f="$file" '$1==f {print $2}' | paste -sd ',' -)
shellcheck -s bash --include="$codes" "$file" 2>&1 || true
fi
done
exit 1
fi
find . -path ./.git -prune -o -name "*.sh" \
-not -path "./.buildkite/scripts/hardware_ci/run-amd-test.sh" -print0 | \
xargs -0 sh -c "for f in \"\$@\"; do git check-ignore -q \"\$f\" || shellcheck -s bash \"\$f\"; done" --