Skip to content

feat: send notifications on both workflow success and failure#3

Draft
John-Chan with Copilot wants to merge 2 commits into
mainfrom
copilot/update-notification-for-workflow
Draft

feat: send notifications on both workflow success and failure#3
John-Chan with Copilot wants to merge 2 commits into
mainfrom
copilot/update-notification-for-workflow

Conversation

Copilot AI commented Feb 25, 2026

Copy link
Copy Markdown

Notification steps previously only ran on success (GitHub Actions default) and hardcoded "镜像同步成功" in the message body. This adds always() to both notification conditions and dynamically reflects job.status in the message.

Changes

Both qyweixin and Telegram steps:

  • if condition wrapped with always() to ensure execution regardless of prior step outcome
  • Message text now uses job.status == 'success' && '成功' || '失败' to display localized success/failure label
  • ${{ job.status }} included explicitly so receivers can see the raw status value
# Before
- name: qyweixin send message
  if: ${{ env.QYWX_ROBOT_URL != '' }}
  ...
  content: |
    # 镜像同步成功

# After
- name: qyweixin send message
  if: ${{ always() && env.QYWX_ROBOT_URL != '' }}
  ...
  content: |
    # 镜像同步${{ job.status == 'success' && '成功' || '失败' }}
    > 状态: ${{ job.status }}

IMAGE_URL is derived entirely from workflow inputs (not step outputs), so it remains available even when earlier steps fail — no default-value handling needed.

Original prompt

请在仓库 power4j/docker-mirror 中修改 GitHub Actions 工作流文件 .github/workflows/mirror.yaml,实现“工作流执行成功和失败都推送消息通知”。

上下文与要求:

  • 现状:当前工作流只在部分情况下推送消息(需要你查看现有 mirror.yaml 里的通知实现与 if 条件)。
  • 目标:无论 workflow 成功或失败,都要发送通知;失败时应明确标识为失败并包含失败原因/步骤(在 GitHub Actions 能获取到的信息范围内)。
  • 需要保持:现有通知渠道/方式不变(例如:如果当前用 webhook/自建 action/飞书/钉钉/Telegram 等,请沿用同一种方式),仅调整条件与消息内容,使 success/failure 都能推送。
  • 兼容性:不要破坏现有作业逻辑;如果是多 job/多 step,确保最终通知只发送一次(或如果现有设计是每个 job 发送一次,则保持一致但必须覆盖 success/failure)。

实现建议(如适用):

  • 对通知 step 使用 if: ${{ always() }} 来确保无论成功/失败都执行。
  • 在通知消息中使用 ${{ job.status }}${{ needs.<job>.result }} 等表达式区分 success/failure。
  • 如果通知依赖前面步骤输出,注意在失败时这些输���可能缺失,需做默认值处理,避免通知 step 自己失败。

交付物:

  1. 修改后的 .github/workflows/mirror.yaml
  2. 提交一个 Pull Request 说明:做了什么、为何这样做、如何验证。

相关文件:

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: John-Chan <2360910+John-Chan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update notification settings for workflow success and failure feat: send notifications on both workflow success and failure Feb 25, 2026
Copilot AI requested a review from John-Chan February 25, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants