2626 with :
2727 fetch-depth : 0
2828
29+ - name : Detect Proto changes
30+ id : proto_changes
31+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
32+ shell : bash
33+ env :
34+ BEFORE_SHA : ${{ github.event.before }}
35+ AFTER_SHA : ${{ github.sha }}
36+ run : |
37+ if git diff --quiet "$BEFORE_SHA" "$AFTER_SHA" -- proto; then
38+ echo "changed=false" >> "$GITHUB_OUTPUT"
39+ else
40+ echo "changed=true" >> "$GITHUB_OUTPUT"
41+ fi
42+
2943 - name : Resolve breaking check policy
3044 id : breaking
3145 if : github.event_name == 'pull_request'
@@ -47,3 +61,119 @@ jobs:
4761 pr_comment : true
4862 # Skip breaking change check when any PR commit contains "buf skip breaking".
4963 breaking : ${{ github.event_name == 'pull_request' && steps.breaking.outputs.enabled == 'true' }}
64+
65+ - name : Check Feishu webhook configuration
66+ id : feishu
67+ if : github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.proto_changes.outputs.changed == 'true'
68+ shell : bash
69+ env :
70+ FEISHU_BSR_WEBHOOK : ${{ secrets.FEISHU_BSR_WEBHOOK }}
71+ run : |
72+ if [[ -n "$FEISHU_BSR_WEBHOOK" ]]; then
73+ echo "configured=true" >> "$GITHUB_OUTPUT"
74+ else
75+ echo "configured=false" >> "$GITHUB_OUTPUT"
76+ echo "::notice::FEISHU_BSR_WEBHOOK is not configured; skipping Feishu notification"
77+ fi
78+
79+ - name : Build BSR notification card
80+ id : bsr_card
81+ if : steps.feishu.outputs.configured == 'true'
82+ shell : bash
83+ env :
84+ BEFORE_SHA : ${{ github.event.before }}
85+ AFTER_SHA : ${{ github.sha }}
86+ REPOSITORY : ${{ github.repository }}
87+ SERVER_URL : ${{ github.server_url }}
88+ run : |
89+ commit_url="$SERVER_URL/$REPOSITORY/commit/$AFTER_SHA"
90+ bsr_url="https://buf.build/sast/sast-shop-v2"
91+ short_sha="${AFTER_SHA:0:7}"
92+ changed_files="$(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- proto | wc -l | tr -d ' ')"
93+ diff_lines="$(git diff --unified=2 "$BEFORE_SHA" "$AFTER_SHA" -- proto | wc -l | tr -d ' ')"
94+ diff_preview="$(git diff --unified=2 "$BEFORE_SHA" "$AFTER_SHA" -- proto | awk '
95+ NR <= 80 {
96+ if (length($0) > 160) {
97+ print substr($0, 1, 160) "…"
98+ } else {
99+ print
100+ }
101+ }
102+ ')"
103+
104+ if (( diff_lines > 80 )); then
105+ diff_preview+=$'\n... diff 已截断,请在 GitHub 查看完整变更'
106+ fi
107+
108+ payload="$(jq -cn \
109+ --arg repository "$REPOSITORY" \
110+ --arg short_sha "$short_sha" \
111+ --arg commit_url "$commit_url" \
112+ --arg bsr_url "$bsr_url" \
113+ --arg changed_files "$changed_files" \
114+ --arg diff "$diff_preview" \
115+ '($diff | gsub("```"; "``\u200b`")) as $safe_diff |
116+ {
117+ msg_type: "interactive",
118+ card: {
119+ schema: "2.0",
120+ config: {
121+ summary: {
122+ content: "sast-shop-v2 Proto 已发布到 BSR"
123+ }
124+ },
125+ header: {
126+ title: {
127+ tag: "plain_text",
128+ content: "BSR Proto 已更新"
129+ },
130+ subtitle: {
131+ tag: "plain_text",
132+ content: "main · \($short_sha)"
133+ },
134+ template: "green"
135+ },
136+ body: {
137+ direction: "vertical",
138+ elements: [
139+ {
140+ tag: "markdown",
141+ content: "**仓库** [\($repository)](\($commit_url))\n**变更** \($changed_files) 个 Proto 文件\n**提交** [`\($short_sha)`](\($commit_url))"
142+ },
143+ {
144+ tag: "hr"
145+ },
146+ {
147+ tag: "markdown",
148+ content: "**Proto diff(最多 80 行)**\n```diff\n\($safe_diff)\n```"
149+ },
150+ {
151+ tag: "button",
152+ text: {
153+ tag: "plain_text",
154+ content: "查看 BSR"
155+ },
156+ type: "primary",
157+ width: "fill",
158+ behaviors: [
159+ {
160+ type: "open_url",
161+ default_url: $bsr_url
162+ }
163+ ]
164+ }
165+ ]
166+ }
167+ }
168+ }')"
169+
170+ echo "payload=$payload" >> "$GITHUB_OUTPUT"
171+
172+ - name : Notify Feishu after BSR publish
173+ if : steps.feishu.outputs.configured == 'true'
174+ # v1.1.1, pinned to prevent a mutable tag from changing executed code.
175+ uses : northwang-lucky/chatbot-webhook-client@24c335b79a1d9db8ba191f89ddd66837f595dd63
176+ with :
177+ app : Lark
178+ webhook : ${{ secrets.FEISHU_BSR_WEBHOOK }}
179+ template : ${{ steps.bsr_card.outputs.payload }}
0 commit comments