Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add weekly report PR check workflows #11

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/weekly-report-pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Weekly Report Mentor Comment Check

on:
pull_request:
branches:
- main

permissions:
contents: write

jobs:
check-mentor-comment:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check Filenames without White Space
run: |
# Find all files with spaces in their names
files_with_spaces=$(find . -name "* *" -type f)

# If any files with spaces are found, output an error message and fail the job
if [ -n "$files_with_spaces" ]; then
echo "Error: The following files have spaces in their names:"
echo "$files_with_spaces"
exit 1
fi

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v14.6

- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done

- name: Check Weekly Report
run: |
DEFAULT_VALUE="待填写"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c5df4e79b8e47f1bd4041625f4a741d0

周报模板中的DEFAULT_VALUE好像不是"待填写"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到。我统一了以下两处的 DEFAULT_VALUE 为 "请联系导师填写" :

  1. 周报提交指南issue
  2. ./WeeklyReports/ 文件下的 readme 文档


weeklyReports=()
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
file_basename=$(basename $file)
echo "file_basename="${file_basename}
if [[ "$file_basename" =~ \[WeeklyReport\] ]]; then
weeklyReports+=("$file")
fi
done

if [ ${#weeklyReports[@]} -eq 0 ]; then
echo "没有周报文件, 或周报文件不符合命名要求: ${{ steps.changed-files.outputs.all_changed_files }}"
exit 0
fi

# 检查文件是否包含 "### 导师点评" 字段以及该字段所在行下面的内容是否为空或者为 ${DEFAULT_VALUE}
function check_tutor_review() {
if grep -q "### 导师点评" "$1"; then
line_number=$(grep -n "### 导师点评" "$1" | cut -d ":" -f 1)

count=1
while [ $count -le 5 ]
do
next_line=$(($line_number + $count))
next_line_content=$(sed -n "${next_line}p" "$1" | tr -d '[:space:]')
if [[ -n "$next_line_content" && "$next_line_content" != ${DEFAULT_VALUE} ]]; then
return 0
fi

count=$((count+1))
done

echo "failed: $1 \"### 导师点评\" 字段下面${count}行内容为空"
return 1
else
echo "failed: $1 没有字段 \"### 导师点评\""
return 1
fi
}


# 检查所有文件
for file in ${weeklyReports}; do
if check_tutor_review "$file"; then
echo "$file 符合要求"
else
echo "$file 导师点评内容缺失."
echo "如有疑问, 请联系助教 MarioLulab"
exit 1
fi
done

echo "所有文件都符合要求"
exit 0