Skip to content

Slack Build Notifications #12822

Slack Build Notifications

Slack Build Notifications #12822

name: Slack Build Notifications
on:
workflow_run:
workflows:
[
Add To Project,
Version,
Release,
Deploy React storybook to GitHub Pages,
promote,
]
types: [completed]
branches: [main]
jobs:
on-success:
runs-on: ubuntu-latest
# We only want notifications for successful runs for certain workflows
if:
${{ github.event.workflow_run.conclusion == 'success' &&
contains(fromJson('["Version", "Release", "Deploy React storybook to
GitHub Pages", "promote"]'), github.event.workflow.name) }}
steps:
- name: Send custom JSON data to Slack
id: slack-success
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
with:
payload: |
{
"username": "Workflow succeeded ✅",
"icon_url": "https://user-images.githubusercontent.com/3360588/192045905-5d9705af-92e2-4432-805e-15db98571e8b.png",
"channel": "#carbon-system-notifications",
"text": "The ${{ github.event.workflow.name }} workflow succeeded: ${{ github.event.workflow_run.url }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Send custom JSON data to Slack
id: slack-failure
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
with:
payload: |
{
"username": "Workflow failed 🚫",
"icon_url": "https://user-images.githubusercontent.com/3360588/192045905-5d9705af-92e2-4432-805e-15db98571e8b.png",
"channel": "#carbon-system-notifications",
"text": "The ${{ github.event.workflow.name }} workflow failed: ${{ github.event.workflow_run.url }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK