diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 06bd981..02b05ac 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -49,61 +49,6 @@ jobs: run: | bash scripts/deploy.sh --source="$GITHUB_WORKSPACE" --target="$HOME/.sanguo_projects/sanguo_moziplus_v2" --health-check - - name: Notify deploy success - if: always() - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - if [ "${{ needs.deploy.result }}" != "success" ]; then - echo "Deploy did not succeed, skipping success notification." - exit 0 - fi - - echo "Deploy succeeded, sending notification..." - - API_URL="${{ gitea.api_url }}" - REPO="${{ gitea.repository }}" - COMMIT_SHA="${{ gitea.sha }}" - PR_AUTHOR="" - NOTIFY_TO="pangtong-fujunshi" - - # 查询关联的 merged PR 作者 - PR_AUTHOR=$(curl --max-time 5 -sf \ - -H "Authorization: token $GITEA_TOKEN" \ - "$API_URL/repos/$REPO/pulls?state=closed&sort=updated&order=desc&limit=10" | \ - python3 -c " -import json, sys -sha = '$COMMIT_SHA' -for pr in json.load(sys.stdin): - merge_sha = pr.get('merge_commit_sha', '') or '' - if merge_sha.startswith(sha) or sha.startswith(merge_sha): - print(pr['user']['login']) - break -" 2>/dev/null || echo "") - - if [ -n "$PR_AUTHOR" ] && [ "$PR_AUTHOR" != "pangtong-fujunshi" ]; then - NOTIFY_TO="$PR_AUTHOR" - fi - - # 发送 Mail 通知 - MAIL_TITLE="[CD] 部署成功: $(echo $COMMIT_SHA | cut -c1-8)" - MAIL_TEXT="部署成功。Commit: ${COMMIT_SHA}" - - curl --max-time 5 -s -X POST http://localhost:8083/api/mail \ - -H "Content-Type: application/json" \ - -d "{\"from\":\"system\",\"to\":\"$NOTIFY_TO\",\"title\":\"$MAIL_TITLE\",\"text\":\"$MAIL_TEXT\",\"type\":\"inform\"}" \ - || echo "Mail notification failed (non-blocking)" - - # 同时通知 pangtong-fujunshi(如果 PR 作者不是 pangtong) - if [ "$NOTIFY_TO" != "pangtong-fujunshi" ]; then - curl --max-time 5 -s -X POST http://localhost:8083/api/mail \ - -H "Content-Type: application/json" \ - -d "{\"from\":\"system\",\"to\":\"pangtong-fujunshi\",\"title\":\"$MAIL_TITLE\",\"text\":\"$MAIL_TEXT\",\"type\":\"inform\"}" \ - || echo "Mail notification failed (non-blocking)" - fi - - echo "Deploy success notification sent to: $NOTIFY_TO" - # 回滚由 notify-deploy-failure job 检测失败后通知人工介入 # ── Job 3: 部署失败通知 ────────────────────────────── @@ -138,3 +83,66 @@ for pr in json.load(sys.stdin): else echo "Deploy succeeded." fi + + # ── Job 4: 部署成功通知 ────────────────────────────── + notify-deploy-success: + runs-on: macos-arm64 + needs: [ci, deploy] + if: always() + steps: + - name: Notify deploy success + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + DEPLOY_RESULT: ${{ needs.deploy.result }} + run: | + if [ "$DEPLOY_RESULT" != "success" ]; then + echo "Deploy did not succeed (result: $DEPLOY_RESULT), skipping success notification." + exit 0 + fi + + echo "Deploy succeeded, sending notification..." + + API_URL="${{ gitea.api_url }}" + REPO="${{ gitea.repository }}" + COMMIT_SHA="${{ gitea.sha }}" + + # 查询关联的 merged PR 作者 + PR_AUTHOR=$(curl --max-time 5 -sf \ + -H "Authorization: token $GITEA_TOKEN" \ + "$API_URL/repos/$REPO/pulls?state=closed&sort=updated&order=desc&limit=10" | \ + python3 -c " +import json, sys +sha = '$COMMIT_SHA' +for pr in json.load(sys.stdin): + merge_sha = pr.get('merge_commit_sha', '') or '' + if merge_sha.startswith(sha) or sha.startswith(merge_sha): + print(pr['user']['login']) + break +" 2>/dev/null || echo "") + + # 确定通知对象 + if [ -n "$PR_AUTHOR" ]; then + NOTIFY_TO="$PR_AUTHOR" + else + # direct push 场景通知 jiangwei-infra + NOTIFY_TO="jiangwei-infra" + fi + + # 发送 Mail 通知 + MAIL_TITLE="[CD] 部署成功: $(echo $COMMIT_SHA | cut -c1-8)" + MAIL_TEXT="部署成功。Commit: ${COMMIT_SHA}" + + curl --max-time 5 -s -X POST http://localhost:8083/api/mail \ + -H "Content-Type: application/json" \ + -d "{\"from\":\"system\",\"to\":\"$NOTIFY_TO\",\"title\":\"$MAIL_TITLE\",\"text\":\"$MAIL_TEXT\",\"type\":\"inform\"}" \ + || echo "Mail notification failed (non-blocking)" + + # 同时通知 pangtong-fujunshi(如果 PR 作者不是 pangtong) + if [ "$NOTIFY_TO" != "pangtong-fujunshi" ]; then + curl --max-time 5 -s -X POST http://localhost:8083/api/mail \ + -H "Content-Type: application/json" \ + -d "{\"from\":\"system\",\"to\":\"pangtong-fujunshi\",\"title\":\"$MAIL_TITLE\",\"text\":\"$MAIL_TEXT\",\"type\":\"inform\"}" \ + || echo "Mail notification failed (non-blocking)" + fi + + echo "Deploy success notification sent to: $NOTIFY_TO"