Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
RanabirChakraborty committed Aug 19, 2024
1 parent 9441016 commit eec60ad
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/check_logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check non-i18n logging

on:
push:
branches:
- 'test-1'

jobs:
check-logging:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run logging check
shell: bash
run: bash check_logging.sh
61 changes: 61 additions & 0 deletions check_logging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

DIFF=$(git diff origin/main...HEAD || true)

if [ -z "$DIFF" ]; then
echo "No diff found to analyze."
exit 0
fi

PATTERNS=(
".info("
".infof("
".warn("
".warnf("
".error("
".errorf("
".fatal("
".fatalf("
"System.out.print"
"System.err.print"
".printStackTrace"
)

ERRORS=""
CURRENT_FILE=""

echo "Processing diff..." # Debug line

while IFS= read -r line; do
# Update the current file if a new diff starts
if [[ "$line" =~ ^diff\ --git\ a\/.*\ b\/.* ]]; then
CURRENT_FILE=$(echo "$line" | awk '{print $3}' | sed 's/^a\///')
echo "Current file: $CURRENT_FILE" # Debug line
fi

if [[ "$line" =~ ^\+[^+] ]]; then
# Ignore lines in the test directories
if [[ "$CURRENT_FILE" != *"src/test/"* && "$CURRENT_FILE" != *"testsuite/"* && "$CURRENT_FILE" != *"check_logging.sh"* ]]; then
# Check for any of the patterns, ensuring "//" doesn't precede them
for pattern in "${PATTERNS[@]}"; do
if [[ "$line" == *"$pattern"* ]]; then
# Ensure the pattern is not commented out with "//"
if [[ "$line" != *"//"*"$pattern"* ]]; then
# Capture the error line and its context
ERRORS+="$line\nFile: $CURRENT_FILE\n\n"
echo "Pattern matched: $pattern" # Debug line
fi
fi
done
fi
fi
done <<< "$DIFF"

if [ -n "$ERRORS" ]; then
echo -e "Logging statements found that should be internationalized or converted to a lower log level:\n"
echo -e "$ERRORS"
exit 1
else
echo "No problematic logging statements found."
exit 0
fi

0 comments on commit eec60ad

Please sign in to comment.