1+ name : Enhanced Production Build Notification
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ jobs :
9+ notify-prod-build :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - name : Checkout
13+ uses : actions/checkout@v4
14+
15+ - name : Wait for Netlify deployment
16+ run : sleep 90
17+
18+ - name : Check Netlify deployment status
19+ id : netlify-status
20+ run : |
21+ # Get latest deployment from Netlify API
22+ DEPLOY_DATA=$(curl -s -H "Authorization: Bearer ${{ secrets.NETLIFY_TOKEN }}" \
23+ "https://api.netlify.com/api/v1/sites/cockroachdb-docs/deploys?per_page=1")
24+
25+ DEPLOY_STATE=$(echo "$DEPLOY_DATA" | jq -r '.[0].state')
26+ DEPLOY_URL=$(echo "$DEPLOY_DATA" | jq -r '.[0].deploy_ssl_url')
27+ COMMIT_SHA=$(echo "$DEPLOY_DATA" | jq -r '.[0].commit_ref')
28+ DEPLOY_ID=$(echo "$DEPLOY_DATA" | jq -r '.[0].id')
29+ DEPLOY_LOG_URL=$(echo "$DEPLOY_DATA" | jq -r '.[0].admin_url // "https://app.netlify.com"')
30+
31+ echo "deploy_state=$DEPLOY_STATE" >> $GITHUB_OUTPUT
32+ echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
33+ echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
34+ echo "deploy_id=$DEPLOY_ID" >> $GITHUB_OUTPUT
35+ echo "deploy_log_url=$DEPLOY_LOG_URL" >> $GITHUB_OUTPUT
36+
37+ echo "Deployment state: $DEPLOY_STATE"
38+ echo "Deployment URL: $DEPLOY_URL"
39+ echo "Commit SHA: $COMMIT_SHA"
40+
41+ - name : Create GitHub deployment
42+ id : deployment
43+ uses : actions/github-script@v7
44+ with :
45+ script : |
46+ const deployment = await github.rest.repos.createDeployment({
47+ owner: context.repo.owner,
48+ repo: context.repo.repo,
49+ ref: context.sha,
50+ environment: 'production',
51+ description: 'Production deployment via Netlify',
52+ auto_merge: false,
53+ required_contexts: []
54+ });
55+ return deployment.data.id;
56+
57+ - name : Post GitHub commit comment - Success
58+ if : steps.netlify-status.outputs.deploy_state == 'ready'
59+ uses : actions/github-script@v7
60+ with :
61+ script : |
62+ const commitSha = '${{ steps.netlify-status.outputs.commit_sha }}' || context.sha;
63+ await github.rest.repos.createCommitComment({
64+ owner: context.repo.owner,
65+ repo: context.repo.repo,
66+ commit_sha: commitSha.substring(0, 40), // Ensure proper SHA length
67+ body: `✅ **Production Deployment Successful**
68+
69+ | Name | Link |
70+ |------|------|
71+ | Latest commit | ${commitSha.substring(0, 7)} |
72+ | Production site | https://www.cockroachlabs.com |
73+ | Deploy log | ${{ steps.netlify-status.outputs.deploy_log_url }} |
74+ | Deploy ID | ${{ steps.netlify-status.outputs.deploy_id }} |
75+
76+ 🚀 Your changes are now live on production!`
77+ });
78+
79+ - name : Post GitHub commit comment - Failure
80+ if : steps.netlify-status.outputs.deploy_state == 'error'
81+ uses : actions/github-script@v7
82+ with :
83+ script : |
84+ const commitSha = '${{ steps.netlify-status.outputs.commit_sha }}' || context.sha;
85+ await github.rest.repos.createCommitComment({
86+ owner: context.repo.owner,
87+ repo: context.repo.repo,
88+ commit_sha: commitSha.substring(0, 40), // Ensure proper SHA length
89+ body: `❌ **Production Deployment Failed**
90+
91+ | Name | Link |
92+ |------|------|
93+ | Latest commit | ${commitSha.substring(0, 7)} |
94+ | Deploy log | ${{ steps.netlify-status.outputs.deploy_log_url }} |
95+ | Deploy ID | ${{ steps.netlify-status.outputs.deploy_id }} |
96+
97+ ⚠️ Production deployment failed. Check the deploy log for details.`
98+ });
99+
100+ - name : Post GitHub commit comment - In Progress
101+ if : steps.netlify-status.outputs.deploy_state == 'building' || steps.netlify-status.outputs.deploy_state == 'enqueued'
102+ uses : actions/github-script@v7
103+ with :
104+ script : |
105+ const commitSha = '${{ steps.netlify-status.outputs.commit_sha }}' || context.sha;
106+ await github.rest.repos.createCommitComment({
107+ owner: context.repo.owner,
108+ repo: context.repo.repo,
109+ commit_sha: commitSha.substring(0, 40), // Ensure proper SHA length
110+ body: `⏳ **Production Deployment In Progress**
111+
112+ | Name | Link |
113+ |------|------|
114+ | Latest commit | ${commitSha.substring(0, 7)} |
115+ | Deploy status | ${{ steps.netlify-status.outputs.deploy_state }} |
116+ | Deploy ID | ${{ steps.netlify-status.outputs.deploy_id }} |
117+
118+ 🔄 Production deployment is still building after 90 seconds. Check Netlify dashboard for progress.`
119+ });
120+
121+ - name : Update GitHub deployment status - Success
122+ if : steps.netlify-status.outputs.deploy_state == 'ready'
123+ uses : actions/github-script@v7
124+ with :
125+ script : |
126+ await github.rest.repos.createDeploymentStatus({
127+ owner: context.repo.owner,
128+ repo: context.repo.repo,
129+ deployment_id: ${{ steps.deployment.outputs.result }},
130+ state: 'success',
131+ environment: 'production',
132+ environment_url: 'https://www.cockroachlabs.com',
133+ description: 'Production deployment successful'
134+ });
135+
136+ - name : Update GitHub deployment status - Failure
137+ if : steps.netlify-status.outputs.deploy_state == 'error'
138+ uses : actions/github-script@v7
139+ with :
140+ script : |
141+ await github.rest.repos.createDeploymentStatus({
142+ owner: context.repo.owner,
143+ repo: context.repo.repo,
144+ deployment_id: ${{ steps.deployment.outputs.result }},
145+ state: 'failure',
146+ environment: 'production',
147+ description: 'Production deployment failed'
148+ });
149+
150+ - name : Send Slack notification - Success
151+ if : steps.netlify-status.outputs.deploy_state == 'ready'
152+ run : |
153+ curl -X POST -H 'Content-type: application/json' \
154+ --data '{
155+ "text": "✅ Production build successful!",
156+ "blocks": [
157+ {
158+ "type": "section",
159+ "text": {
160+ "type": "mrkdwn",
161+ "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 }}\n*GitHub Comment:* Posted automatically"
162+ }
163+ }
164+ ]
165+ }' \
166+ ${{ secrets.SLACK_WEBHOOK_URL }}
167+
168+ - name : Send Slack notification - Failure
169+ if : steps.netlify-status.outputs.deploy_state == 'error'
170+ run : |
171+ curl -X POST -H 'Content-type: application/json' \
172+ --data '{
173+ "text": "❌ Production build failed!",
174+ "blocks": [
175+ {
176+ "type": "section",
177+ "text": {
178+ "type": "mrkdwn",
179+ "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\n*GitHub Comment:* Posted automatically"
180+ }
181+ }
182+ ]
183+ }' \
184+ ${{ secrets.SLACK_WEBHOOK_URL }}
185+
186+ - name : Send Slack notification - In Progress
187+ if : steps.netlify-status.outputs.deploy_state == 'building' || steps.netlify-status.outputs.deploy_state == 'enqueued'
188+ run : |
189+ echo "::warning::Deployment still in progress after 90 seconds: ${{ steps.netlify-status.outputs.deploy_state }}"
190+ curl -X POST -H 'Content-type: application/json' \
191+ --data '{
192+ "text": "⏳ Production build still in progress...",
193+ "blocks": [
194+ {
195+ "type": "section",
196+ "text": {
197+ "type": "mrkdwn",
198+ "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*GitHub Comment:* Posted automatically\n*Note:* Check Netlify dashboard for completion status"
199+ }
200+ }
201+ ]
202+ }' \
203+ ${{ secrets.SLACK_WEBHOOK_URL }}
0 commit comments