Skip to content

Commit

Permalink
Add Slack notification to Github workflows
Browse files Browse the repository at this point in the history
Alert on failures for automatically triggered workflows. For manually
triggered workflows we rely on GitHub emails to the individual that
triggered the workflow.

See the "Workflow builder" approach in
https://github.com/slackapi/slack-github-action/.
  • Loading branch information
markgoddard committed Sep 6, 2024
1 parent ff9e7dd commit ca84afe
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/actions/slack-alert/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# See the "workflow builder" approach in https://github.com/slackapi/slack-github-action/.
name: Slack alert
description: Send an alert to a Slack channel using workflow builder
inputs:
inputs:
description: Textual representation of workflow inputs
required: false
default: "N/A"
type: string
message:
description: Slack alert message
required: false
default: "${{ github.workflow }}/${{ github.job }} GitHub Actions workflow failed :sob:"
type: string
results-url:
description: URL for workflow results
required: false
default: "N/A"
type: string
# Typically this would be a secret.
slack-webhook-url:
description: Slack workflow builder webhook URL
required: true
type: string
# Typically this would be a secret or variable.
slack-channel-id:
description: ID of Slack channel to send alert to
required: true
type: string
runs:
using: composite
steps:
- name: Send message to Slack via Workflow Builder
uses: slackapi/[email protected]
with:
payload: |
{
"channel-id": "${{ env.SLACK_CHANNEL_ID }}",
"inputs": "${{ env.INPUTS }}",
"message": "${{ env.MESSAGE }}",
"results-url": "${{ env.RESULTS_URL }}",
"workflow-url": "${{ env.WORKFLOW_URL }}"
}
env:
SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook-url }}
SLACK_CHANNEL_ID: ${{ inputs.slack-channel-id }}
INPUTS: ${{ inputs.inputs }}
MESSAGE: ${{ inputs.message }}
RESULTS_URL: ${{ inputs.results-url }}
WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
11 changes: 11 additions & 0 deletions .github/workflows/container-promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ jobs:
env:
FILTER: ${{ github.event.inputs.filter }}
CHECK_MODE: ${{ inputs.check_mode }}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
inputs: >-
filter: ${{ inputs.filter }}\n
kayobe_config_branch: ${{ inputs.kayobe_config_branch }}\n
check_mode: ${{ inputs.check_mode }}\n
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure()
10 changes: 10 additions & 0 deletions .github/workflows/container-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ jobs:
env:
FILTER: ${{ github.event.inputs.filter }}
DISTROS: ${{ github.event.inputs.distros }}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
inputs: >-
filter: ${{ inputs.filter }}\n
distros: ${{ inputs.distros }}\n
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure() && github.event_name == 'push'
13 changes: 13 additions & 0 deletions .github/workflows/container-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ jobs:
DISTROS: ${{ github.event.inputs.distros }}
SYNC_OLD_IMAGES: ${{ github.event.inputs.sync-old-images }}
SYNC_NEW_IMAGES: ${{ github.event.inputs.sync-new-images }}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
inputs: >-
filter: ${{ inputs.filter }}\n
distros: ${{ inputs.distros }}\n
sync-old-images: ${{ inputs.sync-old-images }}\n
sync-new-images: ${{ inputs.sync-new-images }}\n
sync-test-pulp: ${{ inputs.sync-test-pulp }}\n
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure()
7 changes: 7 additions & 0 deletions .github/workflows/docs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ jobs:
python-version: 3.x
- run: pip install -r docs-requirements.txt
- run: mkdocs gh-deploy --force

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure()
11 changes: 11 additions & 0 deletions .github/workflows/package-promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ jobs:
env:
FILTER: ${{ github.event.inputs.filter }}
CHECK_MODE: ${{ inputs.check_mode }}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
inputs: >-
filter: ${{ inputs.filter }}\n
kayobe_config_branch: ${{ inputs.kayobe_config_branch }}\n
check_mode: ${{ inputs.check_mode }}\n
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure()
22 changes: 22 additions & 0 deletions .github/workflows/package-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ jobs:
env:
FILTER: ${{ inputs.filter }}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
inputs: >-
filter: ${{ inputs.filter }}\n
sync_ark: ${{ inputs.sync_ark }}\n
sync_test: ${{ inputs.sync_test }}\n
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure()

package-sync-test:
name: Sync package repositories in test
runs-on: arc-release-train-runner
Expand Down Expand Up @@ -100,3 +111,14 @@ jobs:
retry_wait_seconds: 3600
env:
FILTER: ${{ inputs.filter }}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
inputs: >-
filter: ${{ inputs.filter }}\n
sync_ark: ${{ inputs.sync_ark }}\n
sync_test: ${{ inputs.sync_test }}\n
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure()
7 changes: 7 additions & 0 deletions .github/workflows/source-repo-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ jobs:
env:
ANSIBLE_FORCE_COLOR: True
GITHUB_TOKEN: ${{secrets.repository_configuration_token}}

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure() && github.event_name == 'push'
7 changes: 7 additions & 0 deletions .github/workflows/terraform-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ jobs:
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false

- name: Send message to Slack via Workflow Builder
uses: ./.github/actions/slack-alert
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
if: failure() && github.ref == 'refs/heads/main' && github.event_name == 'push'

0 comments on commit ca84afe

Please sign in to comment.