forked from wildfly/wildfly
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bd64d0
commit d4def98
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Check non-i18n logging | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'test-2' | ||
|
||
jobs: | ||
check-logging: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Run logging check | ||
env: | ||
GITHUB_BASE_REF: '${{ github.event.pull_request.base.ref }}' | ||
shell: bash | ||
run: bash check_logging.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
# Determine the base branch for the PR using GITHUB_BASE_REF | ||
BASE_BRANCH="${GITHUB_BASE_REF:-main}" | ||
echo "Comparing against base branch: $BASE_BRANCH" | ||
# Fetch the PR diff against the correct base branch | ||
DIFF=$(git diff origin/"$BASE_BRANCH"...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="" | ||
|
||
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\///') | ||
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" | ||
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 |