Skip to content

Commit 67dd999

Browse files
authored
Update monitor.yml
1 parent 702aed1 commit 67dd999

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

.github/workflows/monitor.yml

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,84 @@
33
name: Monitor Group Meeting Schedule
44

55
on:
6-
push:
7-
branches:
8-
- master # 监控 main 分支的更新,如果仓库使用 master,请修改为 master
6+
schedule:
7+
# 设置定时任务:这里设置为每隔6小时运行一次。
8+
# cron 语法: '分钟 小时 天 月 星期' (UTC时间)
9+
# '0 */6 * * *' 表示每隔6小时的0分执行一次。你可以根据需要调整频率。
10+
- cron: '0 */6 * * *'
11+
workflow_dispatch:
12+
# 允许你手动在 GitHub 仓库的 Actions 页面点击按钮来运行此工作流,方便测试。
913

1014
jobs:
1115
check-for-name-addition:
1216
runs-on: ubuntu-latest
1317
steps:
14-
# 步骤1:检出仓库代码,fetch-depth: 2 保证能获取到上一个提交进行对比
18+
# 步骤1:检出你自己的私有仓库代码
19+
# fetch-depth: 0 表示获取所有历史记录,以便能和上游仓库正确比较
1520
- name: Checkout repository content
1621
uses: actions/checkout@v4
1722
with:
18-
fetch-depth: 2
23+
ref: 'master' # 确保检出的是你私有仓库的 master 分支
24+
fetch-depth: 0
1925

20-
# 步骤2:检查特定名字是否在最近一次提交中被添加
21-
# - 替换 'schedule.md' 为实际包含日程安排的文件名。
22-
# - 替换 'SpecificNameToCheck' 为你要监控的具体名字。
26+
# 步骤2:关联上游公共仓库并拉取最新更改
27+
- name: Sync changes from upstream repository (ZJUNESA/SANDP)
28+
id: sync
29+
run: |
30+
# 设置上游仓库地址
31+
git remote add upstream https://github.com/ZJUNESA/SANDP.git
32+
33+
# 记录拉取前的 commit hash
34+
echo "OLD_HEAD=$(git rev-parse HEAD)" >> $GITHUB_ENV
35+
36+
# 尝试拉取上游仓库的 master 分支更新
37+
if git fetch upstream master; then
38+
# 将本地分支重置到上游分支的最新状态
39+
# 注意:这会丢弃你在自己私有仓库 master 分支上可能存在的本地修改,但对于纯监控任务来说这是最简洁的做法。
40+
git reset --hard upstream/master
41+
echo "New changes fetched from upstream."
42+
else
43+
echo "Failed to fetch upstream changes or no changes."
44+
fi
45+
46+
# 记录拉取后的 commit hash
47+
echo "NEW_HEAD=$(git rev-parse HEAD)" >> $GITHUB_ENV
48+
49+
# 步骤3:比较更新内容,检查特定名字是否被添加
2350
- name: Check for specific name addition in diff
2451
id: check_diff
52+
# 仅当拉取前后 commit hash 不同时(即有更新时)才运行检查
53+
if: env.OLD_HEAD != env.NEW_HEAD
2554
run: |
26-
# 使用 git diff 比较本次提交和上一次提交中 schedule.md 文件的差异
55+
echo "Comparing changes between old commit (${{ env.OLD_HEAD }}) and new commit (${{ env.NEW_HEAD }})..."
56+
# 使用 git diff 比较拉取前后的差异,检查 README.md 文件中新增的行
2757
# grep "^\+" 筛选出新增的行
28-
# grep -q "SpecificNameToCheck" 检查新增行中是否包含目标名字
29-
if git diff HEAD~1 HEAD -- "README.md" | grep "^\+" | grep -q "陈佳豪"; then
30-
echo "Name found in additions."
58+
# grep -q "陈佳豪" 检查新增行中是否包含目标名字
59+
if git diff ${{ env.OLD_HEAD }} ${{ env.NEW_HEAD }} -- "README.md" | grep "^\+" | grep -q "陈佳豪"; then
60+
echo "Name '陈佳豪' found in additions."
3161
echo "::set-output name=name_added::true"
3262
else
33-
echo "Target name not found in new additions."
63+
echo "Target name not found in new additions for this update cycle."
3464
echo "::set-output name=name_added::false"
3565
fi
3666
37-
# 步骤3:如果检测到名字被添加,则发送邮件
67+
# 步骤4:如果检测到名字被添加,则发送邮件
3868
- name: Send notification email if name added
3969
if: steps.check_diff.outputs.name_added == 'true'
4070
uses: dawidd6/action-send-mail@v3
4171
with:
42-
server_address: smtp.gmail.com # 使用你的邮箱SMTP服务器地址
72+
server_address: smtp.zju.edu.cn
4373
server_port: 994
44-
username: ${{ secrets.EMAIL_USERNAME }} # 邮箱账号,存储在 GitHub Secrets 中
45-
password: ${{ secrets.EMAIL_PASSWORD }} # 邮箱密码或应用专用密码,存储在 GitHub Secrets 中
74+
username: ${{ secrets.EMAIL_USERNAME }}
75+
password: ${{ secrets.EMAIL_PASSWORD }}
4676
subject: '组会提醒:轮到你准备了'
4777
body: |
4878
你好,
4979
50-
检测到组会安排更新,你的名字已被添加到日程中
80+
检测到 ZJUNESA/SANDP 组会安排更新,你的名字 "陈佳豪" 已被添加到日程中
5181
请提前至少一周开始准备组会内容。
5282
5383
仓库链接:https://github.com/ZJUNESA/SANDP
5484
55-
to: recipient-email@example.com # 接收提醒的邮箱地址
56-
from: Your Name <${{ secrets.EMAIL_USERNAME }}>
85+
to: xaddwell@qq.com # [重要] 替换为你自己的接收邮箱地址
86+
from: GitHub Monitor <${{ secrets.EMAIL_USERNAME }}> # 你可以修改 "GitHub Monitor" 为你喜欢的发件人昵称

0 commit comments

Comments
 (0)