Skip to content

Commit

Permalink
Update comment-check.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et authored Sep 21, 2024
1 parent 6567df7 commit 289fb11
Showing 1 changed file with 53 additions and 52 deletions.
105 changes: 53 additions & 52 deletions .github/workflows/comment-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,60 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0

# - name: Search for Non-English comments in the entire repository
- name: Search for Non-English comments in the entire repository
run: |
set -e
# Define the regex pattern to match Chinese characters
pattern='[\p{Han}]'
# Use find to get all files in the repository
all_files=$(find . -type f)

# Loop over each file in the repository
for file in $all_files; do
# Skip files in excluded directories
skip_file=false
for dir in ${EXCLUDE_DIRS}; do
if [[ "$file" == ./$dir/* ]]; then
skip_file=true
break
fi
done

# Skip files matching excluded patterns
for file_pattern in ${EXCLUDE_FILES}; do
if [[ "$file" == *$file_pattern ]]; then
skip_file=true
break
fi
done

# If the file matches any exclude pattern, skip it
if [ "$skip_file" = true ]; then
continue
fi

# Use grep to find all comments containing Non-English characters in filtered files
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

# - name: Search for Non-English comments in PR diff files
# run: |
# set -e
# # Define the regex pattern to match Chinese characters
# pattern='[\p{Han}]'

# # Use find to get all files in the repository
# all_files=$(find . -type f)

# # Loop over each file in the repository
# for file in $all_files; do

# # 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 }} ${{ github.event.pull_request.head.sha }})


# # Loop over each changed file
# for file in $changed_files; do
# # Skip files in excluded directories
# skip_file=false
# for dir in ${EXCLUDE_DIRS}; do
Expand All @@ -48,20 +91,20 @@ jobs:
# break
# fi
# done

# # Skip files matching excluded patterns
# for file_pattern in ${EXCLUDE_FILES}; do
# if [[ "$file" == *$file_pattern ]]; then
# skip_file=true
# break
# fi
# done

# # If the file matches any exclude pattern, skip it
# if [ "$skip_file" = true ]; then
# continue
# fi

# # Use grep to find all comments containing Non-English characters in filtered files
# grep_output=$(grep -PnH "$pattern" "$file" || true)
# if [ -n "$grep_output" ]; then
Expand All @@ -71,48 +114,6 @@ jobs:
# fi
# done

- 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 }} ${{ github.event.pull_request.head.sha }})
# Loop over each changed file
for file in $changed_files; do
# Skip files in excluded directories
skip_file=false
for dir in ${EXCLUDE_DIRS}; do
if [[ "$file" == ./$dir/* ]]; then
skip_file=true
break
fi
done
# Skip files matching excluded patterns
for file_pattern in ${EXCLUDE_FILES}; do
if [[ "$file" == *$file_pattern ]]; then
skip_file=true
break
fi
done

# If the file matches any exclude pattern, skip it
if [ "$skip_file" = true ]; then
continue
fi

# Use grep to find all comments containing Non-English characters in filtered files
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

- name: Store non-English comments in ENV
run: |
Expand Down

0 comments on commit 289fb11

Please sign in to comment.