Skip to content

Commit f4114ae

Browse files
authored
Merge pull request #329 from stackhpc/slack-notifications
Add Slack notification to Github workflows
2 parents ebd06c3 + ebc3fe1 commit f4114ae

File tree

11 files changed

+158
-0
lines changed

11 files changed

+158
-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ jobs:
7171
FILTER: ${{ inputs.filter }}
7272
PACKAGE_SYNC_GROUP: ${{ inputs.package_sync_group }}
7373

74+
- name: Send message to Slack via Workflow Builder
75+
uses: ./.github/actions/slack-alert
76+
with:
77+
inputs: >-
78+
filter: ${{ inputs.filter }}\n
79+
sync_ark: ${{ inputs.sync_ark }}\n
80+
sync_test: ${{ inputs.sync_test }}\n
81+
package_sync_group: ${{ inputs.package_sync_group }}\n
82+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
83+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
84+
if: failure()
85+
7486
package-sync-test:
7587
name: Sync package repositories in test
7688
runs-on: arc-release-train-runner
@@ -105,3 +117,15 @@ jobs:
105117
env:
106118
FILTER: ${{ inputs.filter }}
107119
PACKAGE_SYNC_GROUP: ${{ inputs.package_sync_group }}
120+
121+
- name: Send message to Slack via Workflow Builder
122+
uses: ./.github/actions/slack-alert
123+
with:
124+
inputs: >-
125+
filter: ${{ inputs.filter }}\n
126+
sync_ark: ${{ inputs.sync_ark }}\n
127+
sync_test: ${{ inputs.sync_test }}\n
128+
package_sync_group: ${{ inputs.package_sync_group }}\n
129+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
130+
slack-channel-id: ${{ vars.SLACK_CHANNEL_ID }}
131+
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'

docs/usage/notifications.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Notifications
2+
3+
Much of the functionality of StackHPC Release Train is built around GitHub Actions workflows.
4+
Some of these are triggered automatically based on an event such as pushing to a branch in a GitHub repository.
5+
Others are triggered manually, such as using a "workflow dispatch" from GitHub's web UI or API.
6+
7+
Failure of a manually triggered workflow will result in an email being sent to the user who triggered the workflow.
8+
Failure of an automatically triggered workflow will result in an email being sent to the user who *created* the workflow file.
9+
This is not ideal, and makes that person a bottleneck and single point of failure.
10+
To make failures of automatically triggered workflows more visible, notifications are sent to the `#release-train-alerts` Slack channel.
11+
12+
These notifications are implemented in the [slack-alert](https://github.com/stackhpc/stackhpc-release-train/tree/main/.github/actions/slack-alert/) GitHub action.
13+
The `slack-alert` action uses the "workflow builder" approach described in [slack-github-action](https://github.com/slackapi/slack-github-action/).
14+
Slack's [workflow builder](https://slack.com/intl/en-gb/help/articles/360035692513-Guide-to-Slack-Workflow-Builder) feature allows for flexible integration of Slack with various other services, based on various events.
15+
The [Release train status](https://slack.com/shortcuts/Ft07L987AQ91/1f20fd53512385abf199c9357071cb02) workflow has a webhook URL event trigger, with a single action that sends a message to the `#release-train-alerts` Slack channel.
16+
The Slack webhook URL is set in the `SLACK_WEBHOOK_URL` GitHub Actions secret, and the `#release-train-alerts` channel ID is set in the `SLACK_CHANNEL_ID` GitHub Actions variable.

0 commit comments

Comments
 (0)