|
| 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" |
0 commit comments