From 5e61a105cc335501eba6a30f949ee1021ee67f56 Mon Sep 17 00:00:00 2001 From: "Wang, Tao" Date: Thu, 10 Sep 2026 17:09:30 +0800 Subject: [PATCH] chore: feishu msg commit link --- .github/actions/feishu-reply/action.yml | 28 +++++- .github/workflows/ci.yml | 125 +++++++++++++++++++----- 2 files changed, 124 insertions(+), 29 deletions(-) diff --git a/.github/actions/feishu-reply/action.yml b/.github/actions/feishu-reply/action.yml index af008b4..909bbb9 100644 --- a/.github/actions/feishu-reply/action.yml +++ b/.github/actions/feishu-reply/action.yml @@ -11,8 +11,12 @@ inputs: message_id: description: 'Message ID to reply to' required: true + msg_type: + description: 'Message type: text, post' + required: false + default: 'text' content: - description: 'Reply content as text' + description: 'Reply content. Text is plain text; post is JSON.' required: true reply_in_thread: description: 'Whether to reply in thread' @@ -60,17 +64,35 @@ runs: env: FEISHU_TOKEN: ${{ steps.token.outputs.token }} MESSAGE_ID: ${{ inputs.message_id }} + MSG_TYPE: ${{ inputs.msg_type }} CONTENT: ${{ inputs.content }} REPLY_IN_THREAD: ${{ inputs.reply_in_thread }} run: | set -euo pipefail - msg_content="$(jq -n --arg text "$CONTENT" '{text: $text}')" + case "$MSG_TYPE" in + text) + msg_content="$(jq -n --arg text "$CONTENT" '{text: $text}')" + ;; + post) + if ! jq -e . >/dev/null 2>&1 <<< "$CONTENT"; then + echo "::error::Post content must be valid JSON" + exit 1 + fi + msg_content="$CONTENT" + ;; + *) + echo "::error::Unsupported message type: $MSG_TYPE" + exit 1 + ;; + esac + thread_flag="$([ "$REPLY_IN_THREAD" = "true" ] && echo "true" || echo "false")" request_body="$(jq -n \ + --arg msg_type "$MSG_TYPE" \ --arg content "$msg_content" \ --argjson reply_in_thread "$thread_flag" \ - '{msg_type: "text", content: $content, reply_in_thread: $reply_in_thread}')" + '{msg_type: $msg_type, content: $content, reply_in_thread: $reply_in_thread}')" response="$(curl -sS -X POST "https://open.feishu.cn/open-apis/im/v1/messages/${MESSAGE_ID}/reply" \ -H "Authorization: Bearer $FEISHU_TOKEN" \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c7107b..c18edff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,20 +37,29 @@ jobs: - name: Build main update content id: main-content env: + COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} HEAD_SHA: ${{ github.sha }} run: | set -euo pipefail short_sha="${HEAD_SHA:0:7}" post_content="$(jq -cn \ + --arg commit_url "$COMMIT_URL" \ --arg short_sha "$short_sha" \ '{ zh_cn: { title: "stargate-next main 分支已更新", - content: [[{ - tag: "text", - text: "提交: \($short_sha)" - }]] + content: [[ + { + tag: "text", + text: "提交: " + }, + { + tag: "a", + text: $short_sha, + href: $commit_url + } + ]] } }')" @@ -1060,20 +1069,50 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} API_URL: http://api.stargate-next-pr-${{ github.event.pull_request.number }}.36node.com PLAYGROUND_URL: http://playground.stargate-next-pr-${{ github.event.pull_request.number }}.36node.com + COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | set -euo pipefail short_sha="${HEAD_SHA:0:7}" - { - echo 'content<> "$GITHUB_OUTPUT" + post_content="$(jq -cn \ + --arg api_url "$API_URL" \ + --arg commit_url "$COMMIT_URL" \ + --arg playground_url "$PLAYGROUND_URL" \ + --arg pr_number "$PR_NUMBER" \ + --arg short_sha "$short_sha" \ + '{ + zh_cn: { + title: "PR #\($pr_number) 部署成功", + content: [ + [ + { + tag: "text", + text: "Commit: " + }, + { + tag: "a", + text: $short_sha, + href: $commit_url + } + ], + [{ + tag: "text", + text: "访问地址:" + }], + [{ + tag: "text", + text: "- API:\($api_url)" + }], + [{ + tag: "text", + text: "- Playground:\($playground_url)" + }] + ] + } + }')" + + echo "content=$post_content" >> "$GITHUB_OUTPUT" - name: Reply Feishu thread if: steps.pr-comments.outputs.found == 'true' @@ -1082,6 +1121,7 @@ jobs: app_id: ${{ secrets.FEISHU_APP_ID }} app_secret: ${{ secrets.FEISHU_APP_SECRET }} message_id: ${{ steps.pr-comments.outputs.value }} + msg_type: post content: ${{ steps.notify-content.outputs.content }} - name: Skip missing Feishu thread @@ -1119,24 +1159,56 @@ jobs: DEPLOY_RESULT: ${{ needs.deploy.result }} API_URL: https://api.stargate-next-uat.36node.com PLAYGROUND_URL: https://playground.stargate-next-uat.36node.com + COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} HEAD_SHA: ${{ github.sha }} run: | set -euo pipefail short_sha="${HEAD_SHA:0:7}" - { - echo 'content<> "$GITHUB_OUTPUT" + post_content="$(jq -cn \ + --arg api_url "$API_URL" \ + --arg commit_url "$COMMIT_URL" \ + --arg deploy_result "$DEPLOY_RESULT" \ + --arg playground_url "$PLAYGROUND_URL" \ + --arg short_sha "$short_sha" \ + '{ + zh_cn: { + title: (if $deploy_result == "success" then "UAT 部署成功" else "UAT 部署失败" end), + content: ( + [[ + { + tag: "text", + text: "Commit: " + }, + { + tag: "a", + text: $short_sha, + href: $commit_url + } + ]] + + if $deploy_result == "success" then + [ + [{ + tag: "text", + text: "访问地址:" + }], + [{ + tag: "text", + text: "- API:\($api_url)" + }], + [{ + tag: "text", + text: "- Playground:\($playground_url)" + }] + ] + else + [] + end + ) + } + }')" + + echo "content=$post_content" >> "$GITHUB_OUTPUT" - name: Reply Feishu thread uses: ./.github/actions/feishu-reply @@ -1144,4 +1216,5 @@ jobs: app_id: ${{ secrets.FEISHU_APP_ID }} app_secret: ${{ secrets.FEISHU_APP_SECRET }} message_id: ${{ needs['notify-main-updated'].outputs.message_id }} + msg_type: post content: ${{ steps.notify-content.outputs.content }}