Skip to content

Commit ca84afe

Browse files
committed
Add Slack notification to Github workflows
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/.
1 parent ff9e7dd commit ca84afe

File tree

9 files changed

+139
-0
lines changed

9 files changed

+139
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# See the "workflow builder" approach in https://github.com/slackapi/slack-github-action/.
3+
name: Slack alert
4+
description: Send an alert to a Slack channel using workflow builder
5+
inputs:
6+
inputs:
7+
description: Textual representation of workflow inputs
8+
required: false
9+
default: "N/A"
10+
type: string
11+
message:
12+
description: Slack alert message
13+
required: false
14+
default: "${{ github.workflow }}/${{ github.job }} GitHub Actions workflow failed :sob:"
15+
type: string
16+
results-url:
17+
description: URL for workflow results
18+
required: false
19+
default: "N/A"
20+
type: string
21+
# Typically this would be a secret.
22+
slack-webhook-url:
23+
description: Slack workflow builder webhook URL
24+
required: true
25+
type: string
26+
# Typically this would be a secret or variable.
27+
slack-channel-id:
28+
description: ID of Slack channel to send alert to
29+
required: true
30+
type: string
31+
runs:
32+
using: composite
33+
steps:
34+
- name: Send message to Slack via Workflow Builder
35+
uses: slackapi/[email protected]
36+
with:
37+
payload: |
38+
{
39+
"channel-id": "${{ env.SLACK_CHANNEL_ID }}",
40+
"inputs": "${{ env.INPUTS }}",
41+
"message": "${{ env.MESSAGE }}",
42+
"results-url": "${{ env.RESULTS_URL }}",
43+
"workflow-url": "${{ env.WORKFLOW_URL }}"
44+
}
45+
env:
46+
SLACK_WEBHOOK_URL: ${{ inputs.slack-webhook-url }}
47+
SLACK_CHANNEL_ID: ${{ inputs.slack-channel-id }}
48+
INPUTS: ${{ inputs.inputs }}
49+
MESSAGE: ${{ inputs.message }}
50+
RESULTS_URL: ${{ inputs.results-url }}
51+
WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

.github/workflows/container-promote.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ jobs:
5656
env:
5757
FILTER: ${{ github.event.inputs.filter }}
5858
CHECK_MODE: ${{ inputs.check_mode }}
59+
60+
- name: Send message to Slack via Workflow Builder
61+
uses: ./.github/actions/slack-alert
62+
with:
63+
inputs: >-
64+
filter: ${{ inputs.filter }}\n
65+
kayobe_config_branch: ${{ inputs.kayobe_config_branch }}\n
66+
check_mode: ${{ inputs.check_mode }}\n
67+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
68+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
69+
if: failure()

.github/workflows/container-publish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ jobs:
4646
env:
4747
FILTER: ${{ github.event.inputs.filter }}
4848
DISTROS: ${{ github.event.inputs.distros }}
49+
50+
- name: Send message to Slack via Workflow Builder
51+
uses: ./.github/actions/slack-alert
52+
with:
53+
inputs: >-
54+
filter: ${{ inputs.filter }}\n
55+
distros: ${{ inputs.distros }}\n
56+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
57+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
58+
if: failure() && github.event_name == 'push'

.github/workflows/container-sync.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,16 @@ jobs:
8787
DISTROS: ${{ github.event.inputs.distros }}
8888
SYNC_OLD_IMAGES: ${{ github.event.inputs.sync-old-images }}
8989
SYNC_NEW_IMAGES: ${{ github.event.inputs.sync-new-images }}
90+
91+
- name: Send message to Slack via Workflow Builder
92+
uses: ./.github/actions/slack-alert
93+
with:
94+
inputs: >-
95+
filter: ${{ inputs.filter }}\n
96+
distros: ${{ inputs.distros }}\n
97+
sync-old-images: ${{ inputs.sync-old-images }}\n
98+
sync-new-images: ${{ inputs.sync-new-images }}\n
99+
sync-test-pulp: ${{ inputs.sync-test-pulp }}\n
100+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
101+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
102+
if: failure()

.github/workflows/docs-publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ jobs:
1515
python-version: 3.x
1616
- run: pip install -r docs-requirements.txt
1717
- run: mkdocs gh-deploy --force
18+
19+
- name: Send message to Slack via Workflow Builder
20+
uses: ./.github/actions/slack-alert
21+
with:
22+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
23+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
24+
if: failure()

.github/workflows/package-promote.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ jobs:
5858
env:
5959
FILTER: ${{ github.event.inputs.filter }}
6060
CHECK_MODE: ${{ inputs.check_mode }}
61+
62+
- name: Send message to Slack via Workflow Builder
63+
uses: ./.github/actions/slack-alert
64+
with:
65+
inputs: >-
66+
filter: ${{ inputs.filter }}\n
67+
kayobe_config_branch: ${{ inputs.kayobe_config_branch }}\n
68+
check_mode: ${{ inputs.check_mode }}\n
69+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
70+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
71+
if: failure()

.github/workflows/package-sync.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ jobs:
6868
env:
6969
FILTER: ${{ inputs.filter }}
7070

71+
- name: Send message to Slack via Workflow Builder
72+
uses: ./.github/actions/slack-alert
73+
with:
74+
inputs: >-
75+
filter: ${{ inputs.filter }}\n
76+
sync_ark: ${{ inputs.sync_ark }}\n
77+
sync_test: ${{ inputs.sync_test }}\n
78+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
79+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
80+
if: failure()
81+
7182
package-sync-test:
7283
name: Sync package repositories in test
7384
runs-on: arc-release-train-runner
@@ -100,3 +111,14 @@ jobs:
100111
retry_wait_seconds: 3600
101112
env:
102113
FILTER: ${{ inputs.filter }}
114+
115+
- name: Send message to Slack via Workflow Builder
116+
uses: ./.github/actions/slack-alert
117+
with:
118+
inputs: >-
119+
filter: ${{ inputs.filter }}\n
120+
sync_ark: ${{ inputs.sync_ark }}\n
121+
sync_test: ${{ inputs.sync_test }}\n
122+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
123+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
124+
if: failure()

.github/workflows/source-repo-sync.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ jobs:
3030
env:
3131
ANSIBLE_FORCE_COLOR: True
3232
GITHUB_TOKEN: ${{secrets.repository_configuration_token}}
33+
34+
- name: Send message to Slack via Workflow Builder
35+
uses: ./.github/actions/slack-alert
36+
with:
37+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
38+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
39+
if: failure() && github.event_name == 'push'

.github/workflows/terraform-github.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,10 @@ jobs:
115115
- name: Terraform Apply
116116
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
117117
run: terraform apply -auto-approve -input=false
118+
119+
- name: Send message to Slack via Workflow Builder
120+
uses: ./.github/actions/slack-alert
121+
with:
122+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
123+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
124+
if: failure() && github.ref == 'refs/heads/main' && github.event_name == 'push'

0 commit comments

Comments
 (0)