Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions .github/actions/feishu-reply/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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" \
Expand Down
125 changes: 99 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]]
}
}')"

Expand Down Expand Up @@ -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<<EOF'
printf 'PR #%s 部署成功(Commit: %s)\n' "$PR_NUMBER" "$short_sha"
printf '\n'
printf '访问地址:\n'
printf -- '- API:%s\n' "$API_URL"
printf -- '- Playground:%s\n' "$PLAYGROUND_URL"
echo 'EOF'
} >> "$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'
Expand All @@ -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
Expand Down Expand Up @@ -1119,29 +1159,62 @@ 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<<EOF'
if [ "$DEPLOY_RESULT" = "success" ]; then
printf 'UAT 部署成功(Commit: %s)\n' "$short_sha"
printf '\n'
printf '访问地址:\n'
printf -- '- API:%s\n' "$API_URL"
printf -- '- Playground:%s\n' "$PLAYGROUND_URL"
else
printf 'UAT 部署失败(Commit: %s)\n' "$short_sha"
fi
echo 'EOF'
} >> "$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
with:
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 }}
Loading