From f6fd2def50f263bcd308f8c8dbf738e9c6af5d7c Mon Sep 17 00:00:00 2001 From: Harvey Lynden Date: Fri, 4 Oct 2024 15:43:31 +0200 Subject: [PATCH] Pylint Error Handling Corrected error handling, check-lint now displays correct exit codes on exit instead of only displaying the last executed commands exit code, keeps track of all failures and displays correct exit code if any failures were present. Reference: https://github.com/avocado-framework/avocado-static-checks/issues/11 Signed-off-by: Harvey Lynden --- check-lint | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/check-lint b/check-lint index 9721a2c..d22ad2a 100755 --- a/check-lint +++ b/check-lint @@ -14,6 +14,9 @@ ALL_FILES=$(git ls-files '*.py') # Initialize an array to store files checked with custom configs checked_files=() +# Initialize an overall exit status to track pylint failures +overall_exit_status=0 + # Check if the avocado-static-checks.conf file exists if [ -f "$CONFIG_FILE" ]; then echo "Found configuration file: $CONFIG_FILE" @@ -74,6 +77,12 @@ if [ -f "$CONFIG_FILE" ]; then echo "** Running $TOOL_NAME on directory '$DIRECTORY_PATH' with config from '$CONFIG_PATH'..." $TOOL_CMD --rcfile="$BASE_DIR/../$CONFIG_PATH" $FILES + # Capture the exit code + exit_code=$? + if [ $exit_code -ne 0 ]; then + overall_exit_status=1 # Set to 1 if there were any issues + fi + # Add the files to the custom config list for file in $FILES; do checked_files+=("$file") @@ -85,7 +94,14 @@ else # If the configuration file does not exist, print a message and use default config for all files echo "Configuration file '$CONFIG_FILE' not found. Running $TOOL_NAME with default config on all files..." $TOOL_CMD --rcfile="$DEFAULT_CONFIG_PATH" $ALL_FILES - exit 0 + + # Capture the exit code + exit_code=$? + if [ $exit_code -ne 0 ]; then + overall_exit_status=1 # Set to 1 if there were any issues + fi + + exit $overall_exit_status fi # Calculate remaining files that weren't checked with a custom config @@ -100,4 +116,13 @@ done if [ ${#remaining_files[@]} -gt 0 ]; then echo "** Running $TOOL_NAME with default config on remaining files..." $TOOL_CMD --rcfile="$DEFAULT_CONFIG_PATH" "${remaining_files[@]}" + + # Capture the exit code + exit_code=$? + if [ $exit_code -ne 0 ]; then + overall_exit_status=1 + fi fi + +# Exit with the overall exit status +exit $overall_exit_status