Skip to content

Slack Build Notifications #14360

Slack Build Notifications

Slack Build Notifications #14360

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@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
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@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
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