Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Sep 19, 2024
1 parent 16ae6c7 commit bc91372
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions .github/workflows/comment-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,52 +103,12 @@ jobs:
with:
fetch-depth: 0 # Ensure the full history is fetched so git diff can work properly

- name: Search for Non-English comments
run: |
set -e
# Define the regex pattern to match Chinese characters
pattern='[\p{Han}]'
# Process the directories to be excluded
exclude_dirs=""
for dir in $EXCLUDE_DIRS; do
exclude_dirs="$exclude_dirs --exclude-dir=$dir"
done
# Process the file types to be excluded
exclude_files=""
for file in $EXCLUDE_FILES; do
exclude_files="$exclude_files --exclude=$file"
done
# Use grep to find all comments containing Non-English characters
# Check if the file contains '.md' and skip if it does
grep -Pnr "$pattern" . $exclude_dirs $exclude_files | while read -r line ; do
# If the filename contains '.md', skip it
if echo "$line" | grep -q '\.md'; then
continue
fi
# Write the result to the non_english_comments.txt file
echo "$line" >> non_english_comments.txt
done || true
# Store the entire content of non_english_comments.txt into an environment variable
if [ -f non_english_comments.txt ]; then
NON_ENGLISH_COMMENTS=$(cat non_english_comments.txt)
echo "NON_ENGLISH_COMMENTS<<EOF" >> $GITHUB_ENV
echo "$NON_ENGLISH_COMMENTS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
# - name: Search for Non-English comments in PR diff files
# - name: Search for Non-English comments in the repository
# run: |
# set -e
# # Define the regex pattern to match Chinese characters
# pattern='[\p{Han}]'

# # Get the list of files changed in this PR compared to the base branch
# changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }})

# # Process the directories to be excluded
# exclude_dirs=""
# for dir in $EXCLUDE_DIRS; do
Expand All @@ -161,33 +121,16 @@ jobs:
# exclude_files="$exclude_files --exclude=$file"
# done

# # Initialize the variable for storing the grep output
# NON_ENGLISH_COMMENTS=""

# # Check only the files modified in this PR for non-English comments
# for file in $changed_files; do
# # Skip files matching excluded patterns
# skip_file=false
# for file_pattern in $EXCLUDE_FILES; do
# if echo "$file" | grep -q "$file_pattern"; then
# skip_file=true
# break
# fi
# done

# # If the file matches an exclude pattern, skip it
# if [ "$skip_file" = true ]; then
# # Use grep to find all comments containing Non-English characters
# # Check if the file contains '.md' and skip if it does
# grep -Pnr "$pattern" . $exclude_dirs $exclude_files | while read -r line ; do
# # If the filename contains '.md', skip it
# if echo "$line" | grep -q '\.md'; then
# continue
# fi

# # Use grep to find all comments containing Non-English characters, including file path and line numbers
# grep_output=$(grep -PnH "$pattern" "$file" || true)
# if [ -n "$grep_output" ]; then
# # Insert a tab after the line number, keeping the colon between the file path and line number
# formatted_output=$(echo "$grep_output" | sed 's/^\(.*:[0-9]\+\):/\1\t/')
# echo "$formatted_output" >> non_english_comments.txt # Save to file
# fi
# done
# # Write the result to the non_english_comments.txt file
# echo "$line" >> non_english_comments.txt
# done || true

# # Store the entire content of non_english_comments.txt into an environment variable
# if [ -f non_english_comments.txt ]; then
Expand All @@ -197,6 +140,63 @@ jobs:
# echo "EOF" >> $GITHUB_ENV
# fi

- name: Search for Non-English comments in PR diff files
run: |
set -e
# Define the regex pattern to match Chinese characters
pattern='[\p{Han}]'
# Get the list of files changed in this PR compared to the base branch
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }})
# Process the directories to be excluded
exclude_dirs=""
for dir in $EXCLUDE_DIRS; do
exclude_dirs="$exclude_dirs --exclude-dir=$dir"
done
# Process the file types to be excluded
exclude_files=""
for file in $EXCLUDE_FILES; do
exclude_files="$exclude_files --exclude=$file"
done
# Initialize the variable for storing the grep output
NON_ENGLISH_COMMENTS=""
# Check only the files modified in this PR for non-English comments
for file in $changed_files; do
# Skip files matching excluded patterns
skip_file=false
for file_pattern in $EXCLUDE_FILES; do
if echo "$file" | grep -q "$file_pattern"; then
skip_file=true
break
fi
done
# If the file matches an exclude pattern, skip it
if [ "$skip_file" = true ]; then
continue
fi
# Use grep to find all comments containing Non-English characters, including file path and line numbers
grep_output=$(grep -PnH "$pattern" "$file" || true)
if [ -n "$grep_output" ]; then
# Insert a tab after the line number, keeping the colon between the file path and line number
formatted_output=$(echo "$grep_output" | sed 's/^\(.*:[0-9]\+\):/\1\t/')
echo "$formatted_output" >> non_english_comments.txt # Save to file
fi
done
# Store the entire content of non_english_comments.txt into an environment variable
if [ -f non_english_comments.txt ]; then
NON_ENGLISH_COMMENTS=$(cat non_english_comments.txt)
echo "NON_ENGLISH_COMMENTS<<EOF" >> $GITHUB_ENV
echo "$NON_ENGLISH_COMMENTS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
- name: Output non-English comments if found
run: |
if [ -s non_english_comments.txt ]; then
Expand Down

0 comments on commit bc91372

Please sign in to comment.