1212 - name : Checkout
1313 uses : actions/checkout@v4
1414
15+ - name : Find merged PR
16+ id : find-pr
17+ uses : actions/github-script@v7
18+ with :
19+ script : |
20+ // Get the commit that triggered this push
21+ const commit = context.sha;
22+
23+ // Find PRs that were merged with this commit
24+ const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
25+ owner: context.repo.owner,
26+ repo: context.repo.repo,
27+ commit_sha: commit
28+ });
29+
30+ // Find the merged PR
31+ const mergedPR = prs.data.find(pr => pr.merged_at && pr.base.ref === 'main');
32+
33+ if (mergedPR) {
34+ console.log(`Found merged PR: #${mergedPR.number}`);
35+ return {
36+ number: mergedPR.number,
37+ title: mergedPR.title,
38+ author: mergedPR.user.login,
39+ url: mergedPR.html_url
40+ };
41+ } else {
42+ console.log('No merged PR found for this commit');
43+ return null;
44+ }
45+
1546 - name : Wait for Netlify deployment
1647 run : sleep 90
1748
@@ -84,54 +115,184 @@ jobs:
84115 - name : Send Slack notification - Success
85116 if : steps.netlify-status.outputs.deploy_state == 'ready'
86117 run : |
87- curl -X POST -H 'Content-type: application/json' \
88- --data '{
89- "text": "✅ Production build successful!",
90- "blocks": [
118+ echo "🔔 Sending production success notification to Slack..."
119+ RESPONSE=$(curl -X POST -H 'Content-type: application/json' \
120+ --data "{
121+ \"text\": \"✅ Production build successful!\",
122+ \"blocks\": [
91123 {
92- "type": "section",
93- "text": {
94- "type": "mrkdwn",
95- "text": "*Production Build Successful* ✅\n\ n*Site:* <https://www.cockroachlabs.com|cockroachlabs.com>\n*Commit:* `${{ steps.netlify-status.outputs.commit_sha }}`\ n*Branch:* main\n*Deploy ID:* ${{ steps.netlify-status.outputs.deploy_id }}"
124+ \ "type\ ": \ "section\ ",
125+ \ "text\ ": {
126+ \ "type\ ": \ "mrkdwn\ ",
127+ \ "text\ ": \ "*Production Build Successful* ✅\\n\\ n*Site:* <https://www.cockroachlabs.com|cockroachlabs.com>\\ n*Commit:* \\\ `${{ steps.netlify-status.outputs.commit_sha }}\\\`\\ n*Branch:* main\\ n*Deploy ID:* ${{ steps.netlify-status.outputs.deploy_id }}\ "
96128 }
97129 }
98130 ]
99- }' \
100- ${{ secrets.SLACK_WEBHOOK_URL }}
131+ }" \
132+ --write-out "%{http_code}" \
133+ --silent \
134+ --output /tmp/slack_response.txt \
135+ ${{ secrets.SLACK_WEBHOOK_URL }})
136+
137+ echo "Slack response code: $RESPONSE"
138+ if [ "$RESPONSE" = "200" ]; then
139+ echo "✅ Slack notification sent successfully"
140+ else
141+ echo "❌ Slack notification failed with code: $RESPONSE"
142+ echo "Response body:"
143+ cat /tmp/slack_response.txt
144+ fi
145+
146+ - name : Comment on PR - Success
147+ if : steps.netlify-status.outputs.deploy_state == 'ready' && fromJSON(steps.find-pr.outputs.result) != null
148+ uses : actions/github-script@v7
149+ with :
150+ script : |
151+ const prInfo = ${{ steps.find-pr.outputs.result }};
152+ if (prInfo) {
153+ const commentBody = `## 🚀 Production Deployment Successful!
154+
155+ **✅ Your changes are now live on [cockroachlabs.com](https://www.cockroachlabs.com)**
156+
157+ **Deployment Details:**
158+ - **PR:** #${prInfo.number} - ${prInfo.title}
159+ - **Author:** @${prInfo.author}
160+ - **Commit:** \`${{ steps.netlify-status.outputs.commit_sha }}\`
161+ - **Deploy ID:** ${{ steps.netlify-status.outputs.deploy_id }}
162+ - **Deploy URL:** ${{ steps.netlify-status.outputs.deploy_url }}
163+
164+ *Deployment completed successfully! 🎉*`;
165+
166+ await github.rest.issues.createComment({
167+ issue_number: prInfo.number,
168+ owner: context.repo.owner,
169+ repo: context.repo.repo,
170+ body: commentBody
171+ });
172+ }
101173
102174 - name : Send Slack notification - Failure
103175 if : steps.netlify-status.outputs.deploy_state == 'error'
104176 run : |
105- curl -X POST -H 'Content-type: application/json' \
106- --data '{
107- "text": "❌ Production build failed!",
108- "blocks": [
177+ echo "🔔 Sending production failure notification to Slack..."
178+ RESPONSE=$(curl -X POST -H 'Content-type: application/json' \
179+ --data "{
180+ \"text\": \"❌ Production build failed!\",
181+ \"blocks\": [
109182 {
110- "type": "section",
111- "text": {
112- "type": "mrkdwn",
113- "text": "*Production Build Failed* ❌\n\ n*Commit:* `${{ steps.netlify-status.outputs.commit_sha }}`\ n*Branch:* main\n*Deploy ID:* ${{ steps.netlify-status.outputs.deploy_id }}\n*Error:* Check Netlify dashboard for details"
183+ \ "type\ ": \ "section\ ",
184+ \ "text\ ": {
185+ \ "type\ ": \ "mrkdwn\ ",
186+ \ "text\ ": \ "*Production Build Failed* ❌\\n\\ n*Commit:* \\\ `${{ steps.netlify-status.outputs.commit_sha }}\\\`\\ n*Branch:* main\\ n*Deploy ID:* ${{ steps.netlify-status.outputs.deploy_id }}\\ n*Error:* Check Netlify dashboard for details\ "
114187 }
115188 }
116189 ]
117- }' \
118- ${{ secrets.SLACK_WEBHOOK_URL }}
190+ }" \
191+ --write-out "%{http_code}" \
192+ --silent \
193+ --output /tmp/slack_response.txt \
194+ ${{ secrets.SLACK_WEBHOOK_URL }})
195+
196+ echo "Slack response code: $RESPONSE"
197+ if [ "$RESPONSE" = "200" ]; then
198+ echo "✅ Slack notification sent successfully"
199+ else
200+ echo "❌ Slack notification failed with code: $RESPONSE"
201+ echo "Response body:"
202+ cat /tmp/slack_response.txt
203+ fi
204+
205+ - name : Comment on PR - Failure
206+ if : steps.netlify-status.outputs.deploy_state == 'error' && fromJSON(steps.find-pr.outputs.result) != null
207+ uses : actions/github-script@v7
208+ with :
209+ script : |
210+ const prInfo = ${{ steps.find-pr.outputs.result }};
211+ if (prInfo) {
212+ const commentBody = `## ❌ Production Deployment Failed
213+
214+ **🚨 There was an issue deploying your changes to production**
215+
216+ **Deployment Details:**
217+ - **PR:** #${prInfo.number} - ${prInfo.title}
218+ - **Author:** @${prInfo.author}
219+ - **Commit:** \`${{ steps.netlify-status.outputs.commit_sha }}\`
220+ - **Deploy ID:** ${{ steps.netlify-status.outputs.deploy_id }}
221+ - **Status:** Failed
222+
223+ **Next Steps:**
224+ - Check the [Netlify dashboard](https://app.netlify.com/sites/cockroachdb-docs/deploys) for error details
225+ - Review build logs for the specific error
226+ - Contact the docs team if you need assistance
227+
228+ *Please investigate and resolve the deployment issue.*`;
229+
230+ await github.rest.issues.createComment({
231+ issue_number: prInfo.number,
232+ owner: context.repo.owner,
233+ repo: context.repo.repo,
234+ body: commentBody
235+ });
236+ }
119237
120238 - name : Handle pending deployment
121239 if : steps.netlify-status.outputs.deploy_state == 'building' || steps.netlify-status.outputs.deploy_state == 'enqueued'
122240 run : |
123241 echo "::warning::Deployment still in progress after 90 seconds: ${{ steps.netlify-status.outputs.deploy_state }}"
124- curl -X POST -H 'Content-type: application/json' \
125- --data '{
126- "text": "⏳ Production build still in progress...",
127- "blocks": [
242+ echo "🔔 Sending production pending notification to Slack..."
243+ RESPONSE=$(curl -X POST -H 'Content-type: application/json' \
244+ --data "{
245+ \"text\": \"⏳ Production build still in progress...\",
246+ \"blocks\": [
128247 {
129- "type": "section",
130- "text": {
131- "type": "mrkdwn",
132- "text": "*Production Build In Progress* ⏳\n\ n*Status:* ${{ steps.netlify-status.outputs.deploy_state }}\n*Commit:* `${{ steps.netlify-status.outputs.commit_sha }}`\ n*Branch:* main\n*Note:* Check Netlify dashboard for completion status"
248+ \ "type\ ": \ "section\ ",
249+ \ "text\ ": {
250+ \ "type\ ": \ "mrkdwn\ ",
251+ \ "text\ ": \ "*Production Build In Progress* ⏳\\n\\ n*Status:* ${{ steps.netlify-status.outputs.deploy_state }}\\ n*Commit:* \\\ `${{ steps.netlify-status.outputs.commit_sha }}\\\`\\ n*Branch:* main\\ n*Note:* Check Netlify dashboard for completion status\ "
133252 }
134253 }
135254 ]
136- }' \
137- ${{ secrets.SLACK_WEBHOOK_URL }}
255+ }" \
256+ --write-out "%{http_code}" \
257+ --silent \
258+ --output /tmp/slack_response.txt \
259+ ${{ secrets.SLACK_WEBHOOK_URL }})
260+
261+ echo "Slack response code: $RESPONSE"
262+ if [ "$RESPONSE" = "200" ]; then
263+ echo "✅ Slack notification sent successfully"
264+ else
265+ echo "❌ Slack notification failed with code: $RESPONSE"
266+ echo "Response body:"
267+ cat /tmp/slack_response.txt
268+ fi
269+
270+ - name : Comment on PR - Pending
271+ if : (steps.netlify-status.outputs.deploy_state == 'building' || steps.netlify-status.outputs.deploy_state == 'enqueued') && fromJSON(steps.find-pr.outputs.result) != null
272+ uses : actions/github-script@v7
273+ with :
274+ script : |
275+ const prInfo = ${{ steps.find-pr.outputs.result }};
276+ if (prInfo) {
277+ const commentBody = `## ⏳ Production Deployment In Progress
278+
279+ **🔄 Your changes are currently being deployed to production**
280+
281+ **Deployment Details:**
282+ - **PR:** #${prInfo.number} - ${prInfo.title}
283+ - **Author:** @${prInfo.author}
284+ - **Commit:** \`${{ steps.netlify-status.outputs.commit_sha }}\`
285+ - **Deploy ID:** ${{ steps.netlify-status.outputs.deploy_id }}
286+ - **Status:** ${{ steps.netlify-status.outputs.deploy_state }}
287+
288+ **Note:** Deployment is taking longer than expected (>90 seconds). Please check the [Netlify dashboard](https://app.netlify.com/sites/cockroachdb-docs/deploys) for current status.
289+
290+ *Will update when deployment completes.*`;
291+
292+ await github.rest.issues.createComment({
293+ issue_number: prInfo.number,
294+ owner: context.repo.owner,
295+ repo: context.repo.repo,
296+ body: commentBody
297+ });
298+ }
0 commit comments