From 4a7709c42fc5b798d4ef0036125c6cef037ca945 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Mon, 9 Jun 2025 10:26:18 +0200 Subject: [PATCH 1/3] tests: lint: print versions The linters might show different results depending on the version. Then, it looks interesting to print these versions to help people reproducing issues on their side. If there is an issue to print the version, exit with an error: this will also help to identify if the linter is missing or if there is something wrong with it. Signed-off-by: Matthieu Baerts (NGI0) --- tests/patch/pylint/pylint.sh | 2 ++ tests/patch/shellcheck/shellcheck.sh | 2 ++ tests/patch/yamllint/yamllint.sh | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/patch/pylint/pylint.sh b/tests/patch/pylint/pylint.sh index f8b3980..e50e83f 100755 --- a/tests/patch/pylint/pylint.sh +++ b/tests/patch/pylint/pylint.sh @@ -15,6 +15,8 @@ then exit 0 fi +pylint --version || exit 1 + tmpfile_o=$(mktemp) tmpfile_n=$(mktemp) diff --git a/tests/patch/shellcheck/shellcheck.sh b/tests/patch/shellcheck/shellcheck.sh index 1d647a0..54b6b70 100755 --- a/tests/patch/shellcheck/shellcheck.sh +++ b/tests/patch/shellcheck/shellcheck.sh @@ -15,6 +15,8 @@ then exit 0 fi +shellcheck --version || exit 1 + tmpfile_o=$(mktemp) tmpfile_n=$(mktemp) diff --git a/tests/patch/yamllint/yamllint.sh b/tests/patch/yamllint/yamllint.sh index 2688ccc..dd25314 100755 --- a/tests/patch/yamllint/yamllint.sh +++ b/tests/patch/yamllint/yamllint.sh @@ -15,6 +15,8 @@ then exit 0 fi +yamllint --version || exit 1 + tmpfile_o=$(mktemp) tmpfile_n=$(mktemp) From c69c54ed2363b7ac844a4b257ef668a410283361 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Mon, 9 Jun 2025 10:41:44 +0200 Subject: [PATCH 2/3] tests: shellcheck: log shellcheck compliant files To be clearer and to make sure the script is working properly. Signed-off-by: Matthieu Baerts (NGI0) --- tests/patch/shellcheck/shellcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/patch/shellcheck/shellcheck.sh b/tests/patch/shellcheck/shellcheck.sh index 54b6b70..d6fe83c 100755 --- a/tests/patch/shellcheck/shellcheck.sh +++ b/tests/patch/shellcheck/shellcheck.sh @@ -73,9 +73,9 @@ current_w=$(grep -c " (warning):" "$tmpfile_n") # if a file was compliant before or is new, mark everything as error to keep it good. for f in "${tmpfile_n}_"*; do - [ ! -s "${f}" ] && continue # still compliant - sha="${f:${#tmpfile_n}+1}" + [ ! -s "${f}" ] && echo "${sha} is shellcheck compliant" && continue + old="${tmpfile_o}_${sha}" [ -s "${old}" ] && continue # wasn't compliant From 75292acdf74e823405203e75056b5e1a2c333f11 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Mon, 9 Jun 2025 10:52:25 +0200 Subject: [PATCH 3/3] tests: shellcheck: print full path in logs It is clearer, and helpful when multiple files have the same base name. Even more when we only have the SHA to print. To get that, we can simply use an associative array variable. While at it, move some code out of the sub-shells, the same way before and after the patch, to only use these sub-shells when changing directories. Signed-off-by: Matthieu Baerts (NGI0) --- tests/patch/shellcheck/shellcheck.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/patch/shellcheck/shellcheck.sh b/tests/patch/shellcheck/shellcheck.sh index d6fe83c..328fd64 100755 --- a/tests/patch/shellcheck/shellcheck.sh +++ b/tests/patch/shellcheck/shellcheck.sh @@ -32,11 +32,11 @@ 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 "\.sh$"); do - ( - sha=$(echo "$f" | sha256sum | awk '{print $1}') - echo "Checking $f - $sha" - echo + sha=$(echo "$f" | sha256sum | awk '{print $1}') + echo "Checking $f - $sha" + echo + ( cd "$(dirname "$f")" || exit 1 sha="${tmpfile_o}_${sha}" rm -f "${sha}" @@ -53,12 +53,14 @@ incumbent_w=$(grep -c " (warning):" "$tmpfile_o") pr "Checking the tree with the patch" git checkout -q "$HEAD" +declare -A files for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do - ( - sha=$(echo "$f" | sha256sum | awk '{print $1}') - echo "Checking $f - $sha" - echo + sha=$(echo "$f" | sha256sum | awk '{print $1}') + files[${sha}]="${f}" + echo "Checking $f - $sha" + echo + ( cd "$(dirname "$f")" || exit 1 sha="${tmpfile_n}_${sha}" rm -f "${sha}" @@ -74,16 +76,16 @@ current_w=$(grep -c " (warning):" "$tmpfile_n") # if a file was compliant before or is new, mark everything as error to keep it good. for f in "${tmpfile_n}_"*; do sha="${f:${#tmpfile_n}+1}" - [ ! -s "${f}" ] && echo "${sha} is shellcheck compliant" && continue + fpath="${files[${sha}]}" + [ ! -s "${f}" ] && echo "${fpath} is shellcheck compliant" && continue old="${tmpfile_o}_${sha}" [ -s "${old}" ] && continue # wasn't compliant - fname=$(head -n2 "${f}" | tail -n1 | sed "s/^In \(\S\+\.sh\) line [0-9]\+:/\1/g") if [ -f "${old}" ]; then - echo "${fname} was shellcheck compliant, not anymore" 1>&2 + echo "${fpath} was shellcheck compliant, not anymore" 1>&2 else - echo "${fname} is a new file, but not shellcheck compliant" 1>&2 + echo "${fpath} is a new file, but not shellcheck compliant" 1>&2 fi extra=$(grep -c -E " \((warning|info|style)\):" "${f}")