|
| 1 | +# .github/workflows/monitor.yml |
| 2 | + |
| 3 | +name: Monitor Group Meeting Schedule |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - master # 监控 main 分支的更新,如果仓库使用 master,请修改为 master |
| 9 | + |
| 10 | +jobs: |
| 11 | + check-for-name-addition: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + # 步骤1:检出仓库代码,fetch-depth: 2 保证能获取到上一个提交进行对比 |
| 15 | + - name: Checkout repository content |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 2 |
| 19 | + |
| 20 | + # 步骤2:检查特定名字是否在最近一次提交中被添加 |
| 21 | + # - 替换 'schedule.md' 为实际包含日程安排的文件名。 |
| 22 | + # - 替换 'SpecificNameToCheck' 为你要监控的具体名字。 |
| 23 | + - name: Check for specific name addition in diff |
| 24 | + id: check_diff |
| 25 | + run: | |
| 26 | + # 使用 git diff 比较本次提交和上一次提交中 schedule.md 文件的差异 |
| 27 | + # grep "^\+" 筛选出新增的行 |
| 28 | + # grep -q "SpecificNameToCheck" 检查新增行中是否包含目标名字 |
| 29 | + if git diff HEAD~1 HEAD -- "README.md" | grep "^\+" | grep -q "陈佳豪"; then |
| 30 | + echo "Name found in additions." |
| 31 | + echo "::set-output name=name_added::true" |
| 32 | + else |
| 33 | + echo "Target name not found in new additions." |
| 34 | + echo "::set-output name=name_added::false" |
| 35 | + fi |
| 36 | +
|
| 37 | + # 步骤3:如果检测到名字被添加,则发送邮件 |
| 38 | + - name: Send notification email if name added |
| 39 | + if: steps.check_diff.outputs.name_added == 'true' |
| 40 | + uses: dawidd6/action-send-mail@v3 |
| 41 | + with: |
| 42 | + server_address: smtp.gmail.com # 使用你的邮箱SMTP服务器地址 |
| 43 | + server_port: 994 |
| 44 | + username: ${{ secrets.EMAIL_USERNAME }} # 邮箱账号,存储在 GitHub Secrets 中 |
| 45 | + password: ${{ secrets.EMAIL_PASSWORD }} # 邮箱密码或应用专用密码,存储在 GitHub Secrets 中 |
| 46 | + subject: '组会提醒:轮到你准备了' |
| 47 | + body: | |
| 48 | + 你好, |
| 49 | +
|
| 50 | + 检测到组会安排更新,你的名字已被添加到日程中。 |
| 51 | + 请提前至少一周开始准备组会内容。 |
| 52 | +
|
| 53 | + 仓库链接:https://github.com/ZJUNESA/SANDP |
| 54 | +
|
| 55 | + to: recipient-email@example.com # 接收提醒的邮箱地址 |
| 56 | + from: Your Name <${{ secrets.EMAIL_USERNAME }}> |
0 commit comments