-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
1 changed file
with
37 additions
and
71 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 |
---|---|---|
@@ -1,78 +1,44 @@ | ||
name: Reopen and Update Stale Issues | ||
name: Check for Chinese Comments | ||
|
||
on: | ||
workflow_dispatch: # 手动触发 | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
reopen_stale_issues: | ||
check_chinese_comments: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Fetch Closed Issues with lifecycle/stale Label | ||
id: fetch_issues | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const issues = await github.paginate(github.rest.issues.listForRepo, { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
state: 'closed', | ||
labels: 'lifecycle/stale', | ||
per_page: 100 | ||
}); | ||
const issueNumbers = issues | ||
.filter(issue => !issue.pull_request) // 排除PR | ||
.map(issue => issue.number); | ||
console.log(`Fetched issues: ${issueNumbers}`); | ||
return issueNumbers; | ||
- name: Set issue numbers | ||
id: set_issue_numbers | ||
run: | | ||
echo "ISSUE_NUMBERS=${{ steps.fetch_issues.outputs.result }}" >> $GITHUB_ENV | ||
echo "Issue numbers: ${{ steps.fetch_issues.outputs.result }}" | ||
- name: Reopen Issues | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const issueNumbers = JSON.parse(process.env.ISSUE_NUMBERS); | ||
console.log(`Reopening issues: ${issueNumbers}`); | ||
env: | ||
# 定义要排除的目录 | ||
EXCLUDE_DIRS: '.git,docs,tests,scripts,assets,node_modules,build' | ||
# 定义要排除的文件类型 | ||
EXCLUDE_FILES: '*.md,*.txt,*.html,*.css,*.min.js' | ||
|
||
for (const issue_number of issueNumbers) { | ||
// Reopen the issue | ||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue_number, | ||
state: 'open' | ||
}); | ||
console.log(`Reopened issue #${issue_number}`); | ||
} | ||
- name: Remove lifecycle/stale Label | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const issueNumbers = JSON.parse(process.env.ISSUE_NUMBERS); | ||
console.log(`Removing 'lifecycle/stale' label from issues: ${issueNumbers}`); | ||
for (const issue_number of issueNumbers) { | ||
// Remove the lifecycle/stale label | ||
await github.rest.issues.removeLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue_number, | ||
name: 'lifecycle/stale' | ||
}); | ||
console.log(`Removed label 'lifecycle/stale' from issue #${issue_number}`); | ||
} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Search for Chinese comments | ||
run: | | ||
set -e | ||
# 定义正则表达式模式匹配中文字符 | ||
pattern='[\p{Han}]' | ||
# 将 EXCLUDE_DIRS 和 EXCLUDE_FILES 分别处理为 grep 的参数 | ||
exclude_dir_args=$(echo $EXCLUDE_DIRS | sed 's/,/ --exclude-dir=/g' | sed 's/^/--exclude-dir=/') | ||
exclude_file_args=$(echo $EXCLUDE_FILES | sed 's/,/ --exclude=/g' | sed 's/^/--exclude=/') | ||
# 使用 grep 查找所有包含中文字符的注释并保存到文件 | ||
grep -Pnr "$pattern" . $exclude_dir_args $exclude_file_args > chinese_comments.txt || true | ||
- name: Output and fail if Chinese comments are found | ||
run: | | ||
if [ -s chinese_comments.txt ]; then | ||
echo "Chinese comments found in the following locations:" | ||
cat chinese_comments.txt | ||
exit 1 # 标记为失败并终止整个工作流 | ||
else | ||
echo "No Chinese comments found." | ||
fi |