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`.
This commit is contained in:
Cosmin Truta 2024-02-17 16:32:21 +02:00
parent 72c4520d3c
commit dddaf0c625

View File

@ -17,8 +17,8 @@ CI_SHELLCHECK="${CI_SHELLCHECK:-shellcheck}"
CI_EDITORCONFIG_CHECKER="${CI_EDITORCONFIG_CHECKER:-editorconfig-checker}" CI_EDITORCONFIG_CHECKER="${CI_EDITORCONFIG_CHECKER:-editorconfig-checker}"
CI_YAMLLINT="${CI_YAMLLINT:-yamllint}" CI_YAMLLINT="${CI_YAMLLINT:-yamllint}"
# Initialize the global lint counter. # Initialize the global lint status.
CI_LINT_COUNTER=0 CI_LINT_STATUS=0
function ci_init_lint { function ci_init_lint {
ci_info "## START OF LINTING ##" ci_info "## START OF LINTING ##"
@ -45,14 +45,13 @@ function ci_init_lint {
function ci_finish_lint { function ci_finish_lint {
ci_info "## END OF LINTING ##" ci_info "## END OF LINTING ##"
if [[ $CI_LINT_COUNTER -eq 0 ]] if [[ $CI_LINT_STATUS -eq 0 ]]
then then
ci_info "## SUCCESS ##" ci_info "## SUCCESS ##"
return 0
else else
ci_info "linting failed" ci_info "linting failed"
return 1
fi fi
return "$CI_LINT_STATUS"
} }
function ci_lint_ci_scripts { function ci_lint_ci_scripts {
@ -61,15 +60,17 @@ function ci_lint_ci_scripts {
return 0 return 0
} }
ci_info "## LINTING: CI scripts ##" ci_info "## LINTING: CI scripts ##"
{
local my_file
ci_spawn "$CI_SHELLCHECK" --version ci_spawn "$CI_SHELLCHECK" --version
find ./ci -maxdepth 1 -name "*.sh" | find ./ci -name "*.sh" -perm +111 | {
local my_file
while IFS="" read -r my_file while IFS="" read -r my_file
do do
ci_spawn "$CI_SHELLCHECK" -x "$my_file" ci_spawn "$CI_SHELLCHECK" -x "$my_file" || {
# Linting failed.
return 1
}
done done
} || CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1)) }
} }
function ci_lint_text_files { function ci_lint_text_files {
@ -80,7 +81,8 @@ function ci_lint_text_files {
ci_info "## LINTING: text files ##" ci_info "## LINTING: text files ##"
ci_spawn "$CI_EDITORCONFIG_CHECKER" --version ci_spawn "$CI_EDITORCONFIG_CHECKER" --version
ci_spawn "$CI_EDITORCONFIG_CHECKER" || { 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 return 0
} }
ci_info "## LINTING: YAML files ##" ci_info "## LINTING: YAML files ##"
{
local my_file
ci_spawn "$CI_YAMLLINT" --version ci_spawn "$CI_YAMLLINT" --version
find . \( -iname "*.yml" -o -iname "*.yaml" \) -not -path "./out/*" | find . \( -iname "*.yml" -o -iname "*.yaml" \) -not -path "./out/*" | {
local my_file
while IFS="" read -r my_file while IFS="" read -r my_file
do do
ci_spawn "$CI_YAMLLINT" --strict "$my_file" ci_spawn "$CI_YAMLLINT" --strict "$my_file" || {
# Linting failed.
return 1
}
done done
} || CI_LINT_COUNTER=$((CI_LINT_COUNTER + 1)) }
} }
function ci_lint { function ci_lint {
ci_init_lint ci_init_lint
ci_lint_ci_scripts ci_lint_ci_scripts || CI_LINT_STATUS=1
ci_lint_text_files ci_lint_text_files || CI_LINT_STATUS=1
ci_lint_yaml_files ci_lint_yaml_files || CI_LINT_STATUS=1
# TODO: ci_lint_png_files, etc. # TODO: ci_lint_png_files, etc.
ci_finish_lint ci_finish_lint
} }