diff --git a/scripts/buf_lint_check.sh b/scripts/buf_lint_check.sh index c5cbfed35ec..b355f2af16b 100644 --- a/scripts/buf_lint_check.sh +++ b/scripts/buf_lint_check.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/formatting.sh + jar_file_path=$? config_file_path=$? os_type=$? @@ -15,11 +17,11 @@ lint_protobuf_files() { status=$? if [ "$status" = 0 ] ; then - echo "Protobuf lint check completed successfully" + echo_success "Protobuf lint check completed successfully" exit 0 else echo "********************************" - echo "Protobuf lint check issues found. Please fix them before pushing your code." + echo_error "Protobuf lint check issues found. Please fix them before pushing your code." echo "********************************" exit 1 fi @@ -57,7 +59,7 @@ check_os_type() { elif [[ "$OSTYPE" == "darwin"* ]]; then os_type="Darwin" else - echo "Protobuf lint check not available on $OSTYPE" + echo_error "Protobuf lint check not available on $OSTYPE" exit 0 fi } diff --git a/scripts/buildifier_lint_check.sh b/scripts/buildifier_lint_check.sh index 52e0857468e..b56487f6b2f 100644 --- a/scripts/buildifier_lint_check.sh +++ b/scripts/buildifier_lint_check.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/formatting.sh + echo "********************************" echo "Checking Bazel file formatting" echo "********************************" @@ -19,12 +21,12 @@ $buildifier_file_path --lint=warn --mode=check --warnings=-native-android,+out-o status=$? if [ "$status" = 0 ] ; then - echo "Buildifier lint check completed successfully" + echo_success "Buildifier lint check completed successfully" exit 0 else # Assume any lint output or non-zero exit code is a failure. echo "********************************" - echo "Buildifier issue found." + echo_error "Buildifier issue found." echo "Please fix the above issues." echo "********************************" exit 1 diff --git a/scripts/checkstyle_lint_check.sh b/scripts/checkstyle_lint_check.sh index 668be1ba670..1b682d8b615 100644 --- a/scripts/checkstyle_lint_check.sh +++ b/scripts/checkstyle_lint_check.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/formatting.sh + echo "********************************" echo "Checking Java file formatting" echo "********************************" @@ -23,11 +25,11 @@ echo $lint_results if [ "$lint_command_result" -ne 0 ] || [ -z "$lint_results" ] || [[ ${lint_results} == *"[WARN]"* ]]; then # Assume any lint output or non-zero exit code is a failure. echo "********************************" - echo "Checkstyle issue found." + echo_error "Checkstyle issue found." echo "Please fix the above issues." echo "********************************" exit 1 else - echo "Checkstyle lint check completed successfully" + echo_success "Checkstyle lint check completed successfully" exit 0 fi diff --git a/scripts/feature_flags_check.sh b/scripts/feature_flags_check.sh index 48e61153a70..92b0e07a10e 100644 --- a/scripts/feature_flags_check.sh +++ b/scripts/feature_flags_check.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/formatting.sh + echo "********************************" echo "Running feature flag checks" echo "********************************" @@ -120,7 +122,7 @@ function perform_checks_on_feature_flags() { in_array=$(item_in_array "$element" "${imported_classes[@]}") if [[ $in_array -ne 1 ]]; then failed_checks=$((failed_checks + 1)) - echo "$element is not imported in the constructor argument in $file_path at line $imports_line_number" + echo_error "$element is not imported in the constructor argument in $file_path at line $imports_line_number" fi done @@ -128,16 +130,16 @@ function perform_checks_on_feature_flags() { in_array=$(item_in_array "$element" "${flags_added_to_map[@]}") if [[ $in_array -ne 1 ]]; then failed_checks=$((failed_checks + 1)) - echo "$element is not added to the logging map in $file_path at line $flags_map_line_number" + echo_error "$element is not added to the logging map in $file_path at line $flags_map_line_number" fi done if [[ $failed_checks -eq 0 ]]; then - echo "Feature flag checks completed successfully" + echo_success "Feature flag checks completed successfully" exit 0 else echo "********************************" - echo "Feature flag issues found." + echo_error "Feature flag issues found." echo "Please fix the above issues." echo "********************************" exit 1 diff --git a/scripts/formatting.sh b/scripts/formatting.sh new file mode 100644 index 00000000000..0fd2c2dac94 --- /dev/null +++ b/scripts/formatting.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +#Defines color codes for output formatting + +# Red color for error messages +RED='\033[0;31m' + +# Green color for success messages +GREEN='\033[0;32m' + +# Yellow color for warnings messages +YELLOW='\033[0;33m' + +# No color, used to reset the color after each message +NC='\033[0m' + +# Function to print an error message in red +function echo_error() { + echo -e "${RED}$1${NC}" +} + +# Function to print a success message in green +function echo_success() { + echo -e "${GREEN}$1${NC}" +} + +# Function to print a warning message in yellow +function echo_warning() { + echo -e "${YELLOW}$1${NC}" +} diff --git a/scripts/ktlint_lint_check.sh b/scripts/ktlint_lint_check.sh index 2713b88d0e0..dab25e7bd64 100755 --- a/scripts/ktlint_lint_check.sh +++ b/scripts/ktlint_lint_check.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/formatting.sh + echo "********************************" echo "Checking code formatting" echo "********************************" @@ -19,15 +21,15 @@ java -jar $jar_file_path --android app/src/**/*.kt data/src/**/*.kt domain/src/* status=$? if [ "$status" = 0 ] ; then - echo "Lint completed successfully." + echo_success "Lint completed successfully." exit 0 else echo "********************************" - echo "Ktlint issue found." + echo_error "Ktlint issue found." echo "Please fix the above issues. You can also use the java -jar $jar_file_path -F --android domain/src/**/*.kt utility/src/**/*.kt data/src/**/*.kt app/src/**/*.kt testing/src/**/*.kt scripts/src/**/*.kt instrumentation/src/**/*.kt command to fix the most common issues." - echo "Please note, there might be a possibility where the above command will not fix the issue. + echo_warning "Please note, there might be a possibility where the above command will not fix the issue. In that case, you will have to fix it yourself." echo "********************************" exit 1 diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh index 13d37eeb20e..ea2878926de 100755 --- a/scripts/pre-push.sh +++ b/scripts/pre-push.sh @@ -1,5 +1,7 @@ #!/bin/bash +source scripts/formatting.sh + # This script will run the pre-push checks in the given order # - ktlint # - checkstyle @@ -7,7 +9,7 @@ # - (others in the future) if bash scripts/ktlint_lint_check.sh && bash scripts/checkstyle_lint_check.sh && bash scripts/buf_lint_check.sh ; then - echo "All checks passed successfully" + echo_success "All checks passed successfully" exit 0 else exit 1