diff --git a/tests/patch/ruff/info.json b/tests/patch/ruff/info.json new file mode 100644 index 0000000..03f4d40 --- /dev/null +++ b/tests/patch/ruff/info.json @@ -0,0 +1,3 @@ +{ + "run": ["ruff.sh"] +} diff --git a/tests/patch/ruff/ruff.sh b/tests/patch/ruff/ruff.sh new file mode 100755 index 0000000..fa25fde --- /dev/null +++ b/tests/patch/ruff/ruff.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +HEAD=$(git rev-parse HEAD) +rc=0 + +pr() { + echo " ====== $* ======" | tee -a /dev/stderr +} + +# If it doesn't touch .py files, don't bother. Ignore deleted. +if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.py$" +then + echo "No python scripts touched, skip" >&"$DESC_FD" + exit 0 +fi + +ruff --version || exit 1 + +tmpfile_o=$(mktemp) +tmpfile_n=$(mktemp) + +echo "Redirect to $tmpfile_o and $tmpfile_n" + +echo "Tree base:" +git log -1 --pretty='%h ("%s")' HEAD~ +echo "Now at:" +git log -1 --pretty='%h ("%s")' HEAD + +pr "Checking before the patch" +git checkout -q HEAD~ + +# Also ignore created, as not present in the parent commit +for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do + ruff check --output-format pylint "$f" | tee -a "$tmpfile_o" +done + +incumbent=$(wc -l < "$tmpfile_o") + +pr "Checking the tree with the patch" +git checkout -q "$HEAD" + +for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do + ruff check --output-format pylint "$f" | tee -a "$tmpfile_n" +done + +current=$(wc -l < "$tmpfile_n") + +echo "Errors before: $incumbent ; this patch: $current" >&"$DESC_FD" + +if [ "$current" -gt "$incumbent" ]; then + echo "New errors added" 1>&2 + diff -U 0 "$tmpfile_o" "$tmpfile_n" 1>&2 + + rc=1 +fi + +rm "$tmpfile_o" "$tmpfile_n" + +exit $rc