@@ -78,10 +78,10 @@ function validate-ts {
7878}
7979
8080# #############################################################################
81- # CI failure handling - post PR comments instead of blocking the build
81+ # CI failure handling - send Slack notifications instead of blocking the build
8282# #############################################################################
8383
84- # Get PR number for commenting (returns empty string if not in PR context)
84+ # Get PR number (returns empty string if not in PR context)
8585function get_pr_number {
8686 if [[ -z " ${CI:- } " ]] || ! command -v gh & > /dev/null; then
8787 return
@@ -94,43 +94,41 @@ function get_pr_number {
9494 fi
9595}
9696
97- # Find existing docs examples failure comment ID
98- function get_existing_comment_id {
99- local pr_number=$1
100- local jq_filter=' .comments[] | select(.body | startswith("⚠️ **Docs Examples Validation Failed**")) | .id'
101- gh pr view " $pr_number " --json comments --jq " $jq_filter " 2> /dev/null | head -n 1
102- }
97+ function send_slack_message {
98+ local message=$1
99+ local channel=${2:- " #devrel-docs-updates" }
100+ if [[ -z " ${SLACK_BOT_TOKEN:- } " ]]; then
101+ echo " SLACK_BOT_TOKEN not set, skipping Slack notification"
102+ return 0
103+ fi
103104
104- # Post or update a PR comment about docs example failures
105- function post_failure_comment {
106- local pr_number=$1
107- local comment_body=$2
108- local existing_comment
109- existing_comment=$( get_existing_comment_id " $pr_number " )
110-
111- if [[ -n " $existing_comment " ]]; then
112- echo " Updating existing docs examples failure comment..."
113- gh api " repos/{owner}/{repo}/issues/comments/$existing_comment " \
114- -X PATCH -f body=" $comment_body " 2> /dev/null \
115- || echo " ⚠ Failed to update existing comment"
116- else
117- echo " Adding docs examples failure comment to PR #$pr_number ..."
118- gh pr comment " $pr_number " --body " $comment_body " 2> /dev/null \
119- || echo " ⚠ Failed to add PR comment"
105+ local data
106+ data=$( jq -n --arg channel " $channel " --arg text " $message " \
107+ ' {channel: $channel, text: $text}' )
108+
109+ local response
110+ if ! response=$( curl -s --fail-with-body -X POST https://slack.com/api/chat.postMessage \
111+ -H " Authorization: Bearer $SLACK_BOT_TOKEN " \
112+ -H " Content-type: application/json" \
113+ --data " $data " ) ; then
114+ echo " Slack API request failed (curl error)" >&2
115+ return 1
120116 fi
121- }
122117
123- # Delete existing failure comment (called when validation passes)
124- function delete_failure_comment {
125- local pr_number= $1
126- local existing_comment
127- existing_comment= $( get_existing_comment_id " $pr_number " )
118+ local ok
119+ if ! ok= $( echo " $response " | jq -r ' .ok ' 2> /dev/null ) ; then
120+ echo " Slack API returned invalid JSON: $response " >&2
121+ return 1
122+ fi
128123
129- if [[ -n " $existing_comment " ]]; then
130- echo " Validation passed - deleting previous failure comment..."
131- gh api " repos/{owner}/{repo}/issues/comments/$existing_comment " \
132- -X DELETE 2> /dev/null || true
124+ if [[ " $ok " != " true" ]]; then
125+ local error
126+ error=$( echo " $response " | jq -r ' .error // "unknown error"' 2> /dev/null)
127+ echo " Slack API error: $error " >&2
128+ return 1
133129 fi
130+
131+ return 0
134132}
135133
136134# Arrays to collect failures across all steps
@@ -157,24 +155,37 @@ function run_step {
157155 fi
158156}
159157
160- # Post a consolidated failure comment for all failed steps
161- function post_failure_comment_for_steps {
162- local pr_number=$1
163- local max_chars_per_failure=$(( 4500 / ${# FAILED_STEPS[@]} ))
164- local body=" ⚠️ **Docs Examples Validation Failed**" $' \n\n '
158+ # Send a consolidated Slack message for all failed steps
159+ function send_failure_slack_message {
160+ local branch=" ${GITHUB_HEAD_REF:- $(git rev-parse --abbrev-ref HEAD 2>/ dev/ null || echo " unknown" )} "
161+ local context=" branch: \` ${branch} \` "
162+
163+ local pr_number
164+ pr_number=$( get_pr_number)
165+ if [[ -n " $pr_number " ]]; then
166+ local pr_url
167+ pr_url=$( gh pr view " $pr_number " --json url --jq ' .url' 2> /dev/null || echo " " )
168+ if [[ -n " $pr_url " ]]; then
169+ context=" <${pr_url} |PR #${pr_number} >"
170+ else
171+ context=" PR #${pr_number} "
172+ fi
173+ fi
174+
175+ local max_chars_per_failure=$(( 2500 / ${# FAILED_STEPS[@]} ))
176+ local message=" :warning: *Docs Examples Validation Failed* (${context} )" $' \n\n '
165177
166178 for i in " ${! FAILED_STEPS[@]} " ; do
167179 local output=" ${FAILED_OUTPUTS[$i]} "
168180 if [[ ${# output} -gt $max_chars_per_failure ]]; then
169181 output=" (truncated)..." $' \n ' " ${output: -$max_chars_per_failure } "
170182 fi
171- body +=" ### ${FAILED_STEPS[$i]} " $' \n\n ' " ~~~ " $' \n ' " $output " $' \n ' " ~~~ " $' \n\n '
183+ message +=" * ${FAILED_STEPS[$i]} * " $' \n ' " \`\`\` " $' \n ' " $output " $' \n ' " \`\`\` " $' \n\n '
172184 done
173185
174- body+=" **Action required:** Please fix the docs examples or update them to match the current API." $' \n\n '
175- body+=" cc @AztecProtocol/devrel"
186+ message+=" *Action required:* Please fix the docs examples or update them to match the current API."
176187
177- post_failure_comment " $pr_number " " $body "
188+ send_slack_message " $message "
178189}
179190
180191case " $cmd " in
@@ -184,13 +195,8 @@ case "$cmd" in
184195 run_step " Compile (Solidity)" compile-solidity
185196 run_step " TypeScript validation" validate-ts
186197
187- pr_number=$( get_pr_number)
188- if [[ -n " $pr_number " ]]; then
189- if [[ ${# FAILED_STEPS[@]} -gt 0 ]]; then
190- post_failure_comment_for_steps " $pr_number "
191- else
192- delete_failure_comment " $pr_number "
193- fi
198+ if [[ ${# FAILED_STEPS[@]} -gt 0 ]]; then
199+ send_failure_slack_message
194200 fi
195201 ;;
196202 compile-circuits)
0 commit comments