From b04549026c48d4bb0f26454db2178359ac743c39 Mon Sep 17 00:00:00 2001 From: Ranabir Chakraborty Date: Thu, 8 Aug 2024 19:06:58 +0530 Subject: [PATCH] WFLY-19605 Add a CI job to check for non-i18n INFO/WARN/ERROR logging --- .github/workflows/check_logging.yml | 19 +++++++++++ check_logging.sh | 49 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/check_logging.yml create mode 100644 check_logging.sh diff --git a/.github/workflows/check_logging.yml b/.github/workflows/check_logging.yml new file mode 100644 index 000000000000..ae1b60666874 --- /dev/null +++ b/.github/workflows/check_logging.yml @@ -0,0 +1,19 @@ +name: Check PR Logging + +on: + push: + branches: + - WFLY-19605 + +jobs: + check-logging: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set execute permission + run: chmod +x check_logging.sh + + - name: Run logging check + run: ./check_logging.sh \ No newline at end of file diff --git a/check_logging.sh b/check_logging.sh new file mode 100644 index 000000000000..cef75a84561e --- /dev/null +++ b/check_logging.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Fetch the PR diff +DIFF=$(git diff origin/WFLY-19605...HEAD) + +# Define the patterns to search for +PATTERNS=( + ".info(" + ".infof(" + ".warn(" + ".warnf(" + ".error(" + ".errorf(" + ".fatal(" + ".fatalf(" + "System.out.print" + "System.err.print" + ".printStackTrace" +) + +# Loop through the diff and check for patterns +ERROR_FOUND=0 +while IFS= read -r line; do + # Check if the line is an added line + if [[ "$line" =~ ^\+[^+] ]]; then + # Ignore test directories + if [[ "$line" != *"src/test/"* ]] && [[ "$line" != *"testsuite/"* ]]; then + # Ignore comments + if [[ "$line" != *"//"* ]]; then + # Check for any of the patterns + for pattern in "${PATTERNS[@]}"; do + if [[ "$line" == *"$pattern"* ]]; then + ERROR_FOUND=1 + break 2 + fi + done + fi + fi + fi +done <<< "$DIFF" + +# Fail if any patterns are found +if [ "$ERROR_FOUND" -eq 1 ]; then + echo "Logging statements found that should be internationalized or converted to a lower log level." + exit 1 +else + echo "No problematic logging statements found." + exit 0 +fi