From 3c10907eec8359256424a78a08f3bc3d0f8f90e3 Mon Sep 17 00:00:00 2001 From: Sneha Datta Date: Sun, 22 Sep 2024 12:11:40 +0530 Subject: [PATCH 1/3] Add color formatting to Static Checks messages. --- scripts/buf_lint_check.sh | 6 +++--- scripts/buildifier_lint_check.sh | 4 ++-- scripts/checkstyle_lint_check.sh | 6 ++++-- scripts/feature_flags_check.sh | 8 ++++---- scripts/formatting.sh | 20 ++++++++++++++++++++ scripts/ktlint_lint_check.sh | 8 +++++--- scripts/pre-push.sh | 2 +- scripts/static_checks.sh | 7 +++++-- 8 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 scripts/formatting.sh diff --git a/scripts/buf_lint_check.sh b/scripts/buf_lint_check.sh index c5cbfed35ec..b3c6d66cac4 100644 --- a/scripts/buf_lint_check.sh +++ b/scripts/buf_lint_check.sh @@ -15,11 +15,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 +57,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..d53e6ae324e 100644 --- a/scripts/buildifier_lint_check.sh +++ b/scripts/buildifier_lint_check.sh @@ -19,12 +19,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..0c6f9c95e84 100644 --- a/scripts/feature_flags_check.sh +++ b/scripts/feature_flags_check.sh @@ -120,7 +120,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 +128,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..96989318a00 --- /dev/null +++ b/scripts/formatting.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +function echo_error() { + echo -e "${RED}$1${NC}" +} + +function echo_success() { + echo -e "${GREEN}$1${NC}" +} + +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..52f80ad560f 100755 --- a/scripts/pre-push.sh +++ b/scripts/pre-push.sh @@ -7,7 +7,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 diff --git a/scripts/static_checks.sh b/scripts/static_checks.sh index 0a0d08206cb..3fe243d4517 100644 --- a/scripts/static_checks.sh +++ b/scripts/static_checks.sh @@ -1,5 +1,7 @@ #!/bin/bash + + # INSTRUCTIONS # This script will run all script checks locally to make # sure that all script checks will still pass when run on @@ -27,6 +29,8 @@ echo "" bash scripts/buf_lint_check.sh echo "" + + # Download Buildifier in oppia-android-tools folder (pre-requisite for buildifier checks) echo "********************************" echo "Downloading buildifier" @@ -40,7 +44,6 @@ echo "" bash scripts/buildifier_lint_check.sh echo "" - # SCRIPT CHECKS # These checks run on Bazel. Ensure Bazel is installed and configured correctly. @@ -105,7 +108,7 @@ bazel run //scripts:maven_dependencies_list_check -- $(pwd) third_party/maven_in echo "" # License Texts Check -echo "********************************" +echo_success "********************************" echo "Running license texts checks" echo "********************************" bazel run //scripts:license_texts_check -- $(pwd)/app/src/main/res/values/third_party_dependencies.xml From a1efbc1927e150296bba7403f72a12194639de39 Mon Sep 17 00:00:00 2001 From: Sneha Datta Date: Sun, 22 Sep 2024 14:09:01 +0530 Subject: [PATCH 2/3] Fix minor errors --- scripts/buf_lint_check.sh | 2 ++ scripts/buildifier_lint_check.sh | 2 ++ scripts/feature_flags_check.sh | 2 ++ scripts/pre-push.sh | 2 ++ 4 files changed, 8 insertions(+) diff --git a/scripts/buf_lint_check.sh b/scripts/buf_lint_check.sh index b3c6d66cac4..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=$? diff --git a/scripts/buildifier_lint_check.sh b/scripts/buildifier_lint_check.sh index d53e6ae324e..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 "********************************" diff --git a/scripts/feature_flags_check.sh b/scripts/feature_flags_check.sh index 0c6f9c95e84..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 "********************************" diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh index 52f80ad560f..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 From 5d10817cb697ea3b5f634f5fee2217e010a72344 Mon Sep 17 00:00:00 2001 From: Sneha Datta Date: Fri, 27 Sep 2024 20:14:21 +0530 Subject: [PATCH 3/3] Fix minor issues --- scripts/formatting.sh | 1 - scripts/static_checks.sh | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/formatting.sh b/scripts/formatting.sh index 96989318a00..8a45f318fa5 100644 --- a/scripts/formatting.sh +++ b/scripts/formatting.sh @@ -17,4 +17,3 @@ function echo_warning() { echo -e "${YELLOW}$1${NC}" } - diff --git a/scripts/static_checks.sh b/scripts/static_checks.sh index 3fe243d4517..0a0d08206cb 100644 --- a/scripts/static_checks.sh +++ b/scripts/static_checks.sh @@ -1,7 +1,5 @@ #!/bin/bash - - # INSTRUCTIONS # This script will run all script checks locally to make # sure that all script checks will still pass when run on @@ -29,8 +27,6 @@ echo "" bash scripts/buf_lint_check.sh echo "" - - # Download Buildifier in oppia-android-tools folder (pre-requisite for buildifier checks) echo "********************************" echo "Downloading buildifier" @@ -44,6 +40,7 @@ echo "" bash scripts/buildifier_lint_check.sh echo "" + # SCRIPT CHECKS # These checks run on Bazel. Ensure Bazel is installed and configured correctly. @@ -108,7 +105,7 @@ bazel run //scripts:maven_dependencies_list_check -- $(pwd) third_party/maven_in echo "" # License Texts Check -echo_success "********************************" +echo "********************************" echo "Running license texts checks" echo "********************************" bazel run //scripts:license_texts_check -- $(pwd)/app/src/main/res/values/third_party_dependencies.xml