Skip to content

Commit 3878630

Browse files
chore: notify Slack after frontend production deploy (#8340)
1 parent 2c313e0 commit 3878630

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Notify Slack of a deploy
2+
description: Post a deploy notification to a Slack incoming webhook, prompting a smoke test.
3+
4+
inputs:
5+
webhook_url:
6+
description: The Slack incoming webhook to post the notification to.
7+
required: true
8+
service:
9+
description: The name of the deployed service, e.g. Frontend.
10+
required: true
11+
app_url:
12+
description: The URL of the deployed application, linked from the notification.
13+
required: true
14+
environment:
15+
description: The environment that was deployed to.
16+
required: false
17+
default: production
18+
19+
runs:
20+
using: composite
21+
22+
steps:
23+
- name: Post to Slack
24+
shell: bash
25+
env:
26+
SLACK_WEBHOOK_URL: ${{ inputs.webhook_url }}
27+
SERVICE: ${{ inputs.service }}
28+
APP_URL: ${{ inputs.app_url }}
29+
ENVIRONMENT: ${{ inputs.environment }}
30+
COMMIT_SHA: ${{ github.sha }}
31+
ACTOR: ${{ github.actor }}
32+
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
33+
# jq builds the payload so every value is escaped for us, rather than
34+
# interpolated into a JSON heredoc.
35+
run: |
36+
jq -n \
37+
--arg service "$SERVICE" \
38+
--arg environment "$ENVIRONMENT" \
39+
--arg short_sha "${COMMIT_SHA:0:7}" \
40+
--arg actor "$ACTOR" \
41+
--arg app_url "$APP_URL" \
42+
--arg workflow_url "$WORKFLOW_URL" \
43+
'($environment | (.[0:1] | ascii_upcase) + .[1:]) as $env_name |
44+
{
45+
# Slack honours username on this webhook but ignores icon_emoji.
46+
# The avatar comes from the icon set on the Slack app itself.
47+
username: "\($service) Deploy",
48+
text: "🚀 \($service) deployed to \($environment): smoke test required",
49+
blocks: [
50+
{
51+
type: "header",
52+
text: { type: "plain_text", text: "🚀 \($service) deployed to \($environment)" }
53+
},
54+
{
55+
type: "section",
56+
text: {
57+
type: "mrkdwn",
58+
text: "🧪 *\($env_name) smoke test required*\n\nPlease verify the application directly in \($environment)."
59+
}
60+
},
61+
{
62+
type: "section",
63+
fields: [
64+
{ type: "mrkdwn", text: "*Commit:*\n\($short_sha)" },
65+
{ type: "mrkdwn", text: "*Deployed by:*\n@\($actor)" }
66+
]
67+
},
68+
{
69+
type: "actions",
70+
elements: [
71+
{
72+
type: "button",
73+
text: { type: "plain_text", text: "Open \($env_name)" },
74+
url: $app_url
75+
},
76+
{
77+
type: "button",
78+
text: { type: "plain_text", text: "View GitHub Actions" },
79+
url: $workflow_url
80+
}
81+
]
82+
}
83+
]
84+
}' \
85+
| curl --fail-with-body --connect-timeout 10 --max-time 30 -X POST \
86+
-H 'Content-Type: application/json' \
87+
--data @- \
88+
"$SLACK_WEBHOOK_URL"

.github/workflows/frontend-deploy-production.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ jobs:
7979
npm_build_environment: prod
8080
secrets: inherit
8181

82+
notify-production-smoke-test:
83+
name: Notify Production Smoke Test
84+
needs: deploy-production
85+
if: ${{ needs.deploy-production.result == 'success' }}
86+
runs-on: ubuntu-latest
87+
# Only needs to read the repo to resolve the local action below.
88+
permissions:
89+
contents: read
90+
91+
steps:
92+
- name: Cloning repo
93+
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
94+
with:
95+
# Nothing runs git after this, so the token need not persist.
96+
persist-credentials: false
97+
98+
- name: Notify Slack
99+
# The deploy has already succeeded by this point, so a Slack outage or a
100+
# rotated webhook should not fail the run.
101+
continue-on-error: true
102+
uses: ./.github/actions/notify-slack-deploy
103+
with:
104+
webhook_url: ${{ secrets.SLACK_FRONTEND_DEPLOY_WEBHOOK }}
105+
service: Frontend
106+
app_url: https://app.flagsmith.com
107+
82108
deploy-demo:
83109
name: Deploy to Vercel Demo
84110
needs: run-tests

0 commit comments

Comments
 (0)