Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/frontend-deploy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ on:
description: 'Slack channel for deployment notifications (e.g., tfprod-deploy)'
type: string
default: 'poc-tfprod-admin-deploy'
team-slack-handle:
description: 'Team Slack handle to mention on deploy failure (e.g., @tech-frontend). Leave empty to skip.'
type: string
default: ''

secrets:
GH_TOKEN:
Expand Down Expand Up @@ -669,16 +673,15 @@ jobs:

steps:
- name: Send deployment notification
uses: Typeform/.github/shared-actions/slack-deployment-notification@v1
uses: Typeform/.github/shared-actions/slack-deployment-notification@feat/align-frontend-deploy-notifications
with:
slack-channel: ${{ inputs.slack-channel }}
app-name: ${{ inputs.app-name }}
deployment-status: ${{ needs.deploy.result }}
cdn-url: ${{ inputs.cdn-url }}
github-sha: ${{ github.sha }}
github-actor: ${{ github.actor }}
github-ref-name: ${{ github.ref_name }}
github-repository: ${{ github.repository }}
github-server-url: ${{ github.server_url }}
github-run-id: ${{ github.run_id }}
team-slack-handle: ${{ inputs.team-slack-handle }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN }}
188 changes: 30 additions & 158 deletions shared-actions/slack-deployment-notification/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Slack Deployment Notification'
description: 'Send deployment success or failure notifications to Slack with detailed information'
description: 'Send deployment success or failure notifications to Slack, matching the backend deploy message format used in #tfprod-deploy'
inputs:
slack-channel:
description: 'Slack channel ID for notifications (e.g., tfprod-deploy)'
Expand All @@ -10,18 +10,12 @@ inputs:
deployment-status:
description: 'Deployment status: success or failure'
required: true
cdn-url:
description: 'Public CDN URL for the deployed application'
required: true
github-sha:
description: 'Git commit SHA'
required: true
github-actor:
description: 'GitHub user who triggered the deployment'
required: true
github-ref-name:
description: 'Git branch or tag name'
required: true
github-repository:
description: 'Repository name (owner/repo)'
required: true
Expand All @@ -31,183 +25,61 @@ inputs:
github-run-id:
description: 'GitHub Actions run ID'
required: true
team-slack-handle:
description: 'Team Slack handle to mention on failure (e.g., @tech-frontend). Leave empty to skip team mention.'
required: false
default: ''
SLACK_BOT_TOKEN:
description: 'Slack OAuth token for posting messages'
required: true

runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Get commit message
id: commit
- name: Build notification message
id: msg
shell: bash
run: |
COMMIT_MSG=$(git log -1 --pretty=%B ${{ inputs.github-sha }} 2>/dev/null || echo "Commit message unavailable")
# Truncate to 100 chars and escape for JSON
COMMIT_MSG=$(echo "$COMMIT_MSG" | head -c 100 | sed 's/"/\\"/g' | tr -d '\n')
echo "message=$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "short_sha=$(echo ${{ inputs.github-sha }} | cut -c1-7)" >> $GITHUB_OUTPUT

SHORT_SHA=$(echo "${{ inputs.github-sha }}" | cut -c1-7)
APP="${{ inputs.app-name }}"
ACTOR="${{ inputs.github-actor }}"
WORKFLOW_URL="${{ inputs.github-server-url }}/${{ inputs.github-repository }}/actions/runs/${{ inputs.github-run-id }}"
TEAM="${{ inputs.team-slack-handle }}"

# Success: 🚀 [frontend] `app:sha` was deployed to production by *actor*
SUCCESS_MSG="🚀 [frontend] \`${APP}:${SHORT_SHA}\` was deployed to production by *${ACTOR}*"

# Failure: 🔥 [frontend] The deployment of `app:sha` to production by *actor* has failed (<url|logs>) @team
FAILURE_MSG="🔥 [frontend] The deployment of \`${APP}:${SHORT_SHA}\` to production by *${ACTOR}* has failed (<${WORKFLOW_URL}|logs>)"
if [ -n "$TEAM" ]; then
FAILURE_MSG="${FAILURE_MSG} ${TEAM}"
fi

echo "success_msg=${SUCCESS_MSG}" >> $GITHUB_OUTPUT
echo "failure_msg=${FAILURE_MSG}" >> $GITHUB_OUTPUT

- name: Send success notification
if: ${{ inputs.deployment-status == 'success' }}
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ inputs.slack-channel }}
payload: |
{
"text": "✅ Deployment Successful: ${{ inputs.app-name }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "✅ Deployment Successful",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*App:*\n${{ inputs.app-name }}"
},
{
"type": "mrkdwn",
"text": "*Environment:*\nProduction"
},
{
"type": "mrkdwn",
"text": "*CDN:*\n<${{ inputs.cdn-url }}|${{ inputs.cdn-url }}>"
},
{
"type": "mrkdwn",
"text": "*Deployed by:*\n${{ inputs.github-actor }}"
},
{
"type": "mrkdwn",
"text": "*Commit:*\n<${{ inputs.github-server-url }}/${{ inputs.github-repository }}/commit/${{ inputs.github-sha }}|${{ steps.commit.outputs.short_sha }}>"
},
{
"type": "mrkdwn",
"text": "*Branch:*\n${{ inputs.github-ref-name }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Commit Message:*\n${{ steps.commit.outputs.message }}"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow"
},
"url": "${{ inputs.github-server-url }}/${{ inputs.github-repository }}/actions/runs/${{ inputs.github-run-id }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Commit"
},
"url": "${{ inputs.github-server-url }}/${{ inputs.github-repository }}/commit/${{ inputs.github-sha }}"
}
]
}
]
"text": "${{ steps.msg.outputs.success_msg }}",
"username": "Deploy Notifier"
}
env:
SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }}

- name: Send failure notification
if: ${{ inputs.deployment-status == 'failure' }}
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ inputs.slack-channel }}
payload: |
{
"text": "❌ Deployment Failed: ${{ inputs.app-name }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ Deployment Failed",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*App:*\n${{ inputs.app-name }}"
},
{
"type": "mrkdwn",
"text": "*Environment:*\nProduction"
},
{
"type": "mrkdwn",
"text": "*Failed at:*\nDeploy job"
},
{
"type": "mrkdwn",
"text": "*Deployed by:*\n${{ inputs.github-actor }}"
},
{
"type": "mrkdwn",
"text": "*Commit:*\n<${{ inputs.github-server-url }}/${{ inputs.github-repository }}/commit/${{ inputs.github-sha }}|${{ steps.commit.outputs.short_sha }}>"
},
{
"type": "mrkdwn",
"text": "*Branch:*\n${{ inputs.github-ref-name }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":warning: *Action Required:* Check the workflow logs for details."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Logs"
},
"url": "${{ inputs.github-server-url }}/${{ inputs.github-repository }}/actions/runs/${{ inputs.github-run-id }}",
"style": "danger"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Commit"
},
"url": "${{ inputs.github-server-url }}/${{ inputs.github-repository }}/commit/${{ inputs.github-sha }}"
}
]
}
]
"text": "${{ steps.msg.outputs.failure_msg }}",
"username": "Deploy Notifier"
}
env:
SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }}
Expand Down
Loading