From f1d8e9b837e4b157a248e22d86df91eedd2d1bc7 Mon Sep 17 00:00:00 2001 From: PiEgg Date: Fri, 17 Apr 2026 14:32:13 +0800 Subject: [PATCH] refactor(scripts): generalize feishu notification script and add auto-merge failure alert (#9138) --- .github/workflows/auto-merge.yml | 20 +++++++++++++++++++ .github/workflows/release.yml | 5 +++-- .github/workflows/test-feishu-notify.yml | 17 ++++++++++------ ...shu-release-notify.sh => feishu-notify.sh} | 19 ++++++++++-------- 4 files changed, 45 insertions(+), 16 deletions(-) rename scripts/{feishu-release-notify.sh => feishu-notify.sh} (72%) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 56888ccedb5..1e56c6ab990 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -60,6 +60,7 @@ jobs: persist-credentials: true fetch-depth: 0 - name: ${{ steps.get-branch.outputs.baseBranch }} -> ${{ steps.get-branch.outputs.targetBranch }} (${{ inputs.repository || 'nocobase' }}) + id: auto-merge run: | git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>' @@ -68,6 +69,25 @@ jobs: git checkout ${{ steps.get-branch.outputs.targetBranch }} git merge ${{ steps.get-branch.outputs.baseBranch }} git push origin ${{ steps.get-branch.outputs.targetBranch }} + - name: Checkout nocobase for notify script + if: failure() + uses: actions/checkout@v4 + with: + repository: nocobase/nocobase + token: ${{ steps.app-token.outputs.token }} + sparse-checkout: scripts/feishu-notify.sh + path: nocobase-scripts + - name: Send Feishu notification on failure + if: failure() + shell: bash + env: + WEBHOOK_URL: ${{ secrets.RELEASE_RESULT_FEISHU_WEBHOOK_URL }} + TITLE: "Auto Merge 失败通知" + STATUS: "failure" + STATUS_TEXT_FAILURE: "合并失败" + CONTENT: "**仓库:**${{ inputs.repository || 'nocobase' }}\n**分支:**${{ steps.get-branch.outputs.baseBranch }} → ${{ steps.get-branch.outputs.targetBranch }}\n**状态:**❌ 合并失败" + WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: bash nocobase-scripts/scripts/feishu-notify.sh # - name: push ${{ inputs.repository || 'nocobase' }}(${{ steps.get-branch.outputs.targetBranch }}) # uses: ad-m/github-push-action@master # with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2fe271cebe3..6b7d20a8988 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -366,7 +366,8 @@ jobs: shell: bash env: WEBHOOK_URL: ${{ secrets.RELEASE_RESULT_FEISHU_WEBHOOK_URL }} - VERSION: ${{ github.ref_name }} + TITLE: "NocoBase 版本 ${{ github.ref_name }} Release 结果通知" STATUS: ${{ steps.result.outputs.status }} + CONTENT: "**版本:**${{ github.ref_name }}\n**时间:**$(TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S')\n**状态:**${{ steps.result.outputs.status == 'success' && '✅ 构建成功' || '❌ 构建失败' }}" WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - run: bash scripts/feishu-release-notify.sh + run: bash scripts/feishu-notify.sh diff --git a/.github/workflows/test-feishu-notify.yml b/.github/workflows/test-feishu-notify.yml index 88eb4127304..87e243c44e7 100644 --- a/.github/workflows/test-feishu-notify.yml +++ b/.github/workflows/test-feishu-notify.yml @@ -1,12 +1,12 @@ -name: Test Feishu Release Notification +name: Test Feishu Notification on: workflow_dispatch: inputs: - version: - description: 'Version tag (e.g. v2.0.34)' + title: + description: 'Card title' required: true - default: 'v0.0.0-test' + default: 'NocoBase 版本 v0.0.0-test Release 结果通知' status: description: 'Build status' required: true @@ -15,6 +15,10 @@ on: - success - failure default: 'success' + content: + description: 'Card body content in lark_md format (leave empty for default)' + required: false + default: '' build_time: description: 'Build time (leave empty for current time)' required: false @@ -34,8 +38,9 @@ jobs: shell: bash env: WEBHOOK_URL: ${{ secrets.RELEASE_RESULT_FEISHU_WEBHOOK_URL }} - VERSION: ${{ inputs.version }} + TITLE: ${{ inputs.title }} STATUS: ${{ inputs.status }} + CONTENT: ${{ inputs.content }} BUILD_TIME: ${{ inputs.build_time }} WORKFLOW_URL: ${{ inputs.workflow_url || format('{0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id) }} - run: bash scripts/feishu-release-notify.sh + run: bash scripts/feishu-notify.sh diff --git a/scripts/feishu-release-notify.sh b/scripts/feishu-notify.sh similarity index 72% rename from scripts/feishu-release-notify.sh rename to scripts/feishu-notify.sh index 4a47957a150..f4a4acbf403 100755 --- a/scripts/feishu-release-notify.sh +++ b/scripts/feishu-notify.sh @@ -1,19 +1,22 @@ #!/usr/bin/env bash -# Send a Feishu interactive card notification for release results. +# Send a Feishu interactive card notification. # # Required environment variables: # WEBHOOK_URL - Feishu bot webhook URL -# VERSION - Release version (e.g. v2.0.34) +# TITLE - Card title # STATUS - "success" or "failure" # WORKFLOW_URL - Link to the GitHub Actions run # # Optional environment variables: +# STATUS_TEXT_SUCCESS - Custom success text (defaults to "构建成功") +# STATUS_TEXT_FAILURE - Custom failure text (defaults to "构建失败") +# CONTENT - Card body content in lark_md format (defaults to status line) # BUILD_TIME - Build timestamp (defaults to current time in Asia/Shanghai) set -euo pipefail : "${WEBHOOK_URL:?WEBHOOK_URL is required}" -: "${VERSION:?VERSION is required}" +: "${TITLE:?TITLE is required}" : "${STATUS:?STATUS must be 'success' or 'failure'}" : "${WORKFLOW_URL:?WORKFLOW_URL is required}" @@ -21,15 +24,15 @@ BUILD_TIME="${BUILD_TIME:-$(TZ="Asia/Shanghai" date +"%Y-%m-%d %H:%M:%S")}" if [[ "$STATUS" == "success" ]]; then HEADER_TEMPLATE="green" - STATUS_TEXT="构建成功" + STATUS_TEXT="${STATUS_TEXT_SUCCESS:-构建成功}" STATUS_EMOJI="✅" else HEADER_TEMPLATE="red" - STATUS_TEXT="构建失败" + STATUS_TEXT="${STATUS_TEXT_FAILURE:-构建失败}" STATUS_EMOJI="❌" fi -TITLE="NocoBase 版本 ${VERSION} Release 结果通知" +CONTENT="${CONTENT:-"**时间:**${BUILD_TIME}\n**状态:**${STATUS_EMOJI} ${STATUS_TEXT}"}" PAYLOAD=$(cat <