From dddaf0c625a8daea4d027cb57380b7fac6f58285 Mon Sep 17 00:00:00 2001 From: Cosmin Truta Date: Sat, 17 Feb 2024 16:32:21 +0200 Subject: [PATCH] ci: Fix the reporting in ci_lint.sh The variable `CI_LINT_COUNTER` was incremented inside subshells, but remained unchanged in the main shell process. The errors detected by the internal linters remained unreported by the main script. (Oopsie!) Besides fixing this defect, considering that only a pass/fail status is needed, we are replacing `CI_LINT_COUNTER` with `CI_LINT_STATUS`. --- ci/ci_lint.sh | 54 +++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/ci/ci_lint.sh b/ci/ci_lint.sh index 2efe3714dd..bce220214e 100755 --- a/ci/ci_lint.sh +++ b/ci/ci_lint.sh @@ -17,8 +17,8 @@ CI_SHELLCHECK="${CI_SHELLCHECK:-shellcheck}" CI_EDITORCONFIG_CHECKER="${CI_EDITORCONFIG_CHECKER:-editorconfig-checker}" CI_YAMLLINT="${CI_YAMLLINT:-yamllint}" -# Initialize the global lint counter. -CI_LINT_COUNTER=0 +# Initialize the global lint status. +CI_LINT_STATUS=0 function ci_init_lint { ci_info "## START OF LINTING ##" @@ -45,14 +45,13 @@ function ci_init_lint { function ci_finish_lint { ci_info "## END OF LINTING ##" - if [[ $CI_LINT_COUNTER -eq 0 ]] + if [[ $CI_LINT_STATUS -eq 0 ]] then ci_info "## SUCCESS ##" - return 0 else ci_info "linting failed" - return 1 fi + return "$CI_LINT_STATUS" } function ci_lint_ci_scripts { @@ -61,15 +60,17 @@ function ci_lint_ci_scripts { return 0 } ci_info "## LINTING: CI scripts ##" - { + ci_spawn "$CI_SHELLCHECK" --version + find ./ci -name "*.sh" -perm +111 | { local my_file - ci_spawn "$CI_SHELLCHECK" --version - find ./ci -maxdepth 1 -name "*.sh" | - while IFS="" read -r my_file - do - ci_spawn "$CI_SHELLCHECK" -x "$my_file" - done - } || CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1)) + while IFS="" read -r my_file + do + ci_spawn "$CI_SHELLCHECK" -x "$my_file" || { + # Linting failed. + return 1 + } + done + } } function ci_lint_text_files { @@ -80,7 +81,8 @@ function ci_lint_text_files { ci_info "## LINTING: text files ##" ci_spawn "$CI_EDITORCONFIG_CHECKER" --version ci_spawn "$CI_EDITORCONFIG_CHECKER" || { - CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1)) + # Linting failed. + return 1 } } @@ -90,22 +92,24 @@ function ci_lint_yaml_files { return 0 } ci_info "## LINTING: YAML files ##" - { + ci_spawn "$CI_YAMLLINT" --version + find . \( -iname "*.yml" -o -iname "*.yaml" \) -not -path "./out/*" | { local my_file - ci_spawn "$CI_YAMLLINT" --version - find . \( -iname "*.yml" -o -iname "*.yaml" \) -not -path "./out/*" | - while IFS="" read -r my_file - do - ci_spawn "$CI_YAMLLINT" --strict "$my_file" - done - } || CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1)) + while IFS="" read -r my_file + do + ci_spawn "$CI_YAMLLINT" --strict "$my_file" || { + # Linting failed. + return 1 + } + done + } } function ci_lint { ci_init_lint - ci_lint_ci_scripts - ci_lint_text_files - ci_lint_yaml_files + ci_lint_ci_scripts || CI_LINT_STATUS=1 + ci_lint_text_files || CI_LINT_STATUS=1 + ci_lint_yaml_files || CI_LINT_STATUS=1 # TODO: ci_lint_png_files, etc. ci_finish_lint }