Skip to content

Commit ff8381b

Browse files
committed
Add Slack notification
1 parent 03a480c commit ff8381b

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

.github/workflows/markdown_links.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ on:
3232
jobs:
3333

3434
# Define a job for detecting broken links in Markdown files...
35-
check_links:
35+
markdown_links:
3636

3737
# Define a display name:
3838
name: 'Check links'
@@ -75,3 +75,58 @@ jobs:
7575
if: ${{ steps.results.outputs.status }} != 'success'
7676
run: |
7777
exit 1
78+
79+
# Define a job for sending notifications to Slack...
80+
slack:
81+
82+
# Define a display name:
83+
name: 'Slack notification'
84+
85+
# Define the type of virtual host machine:
86+
runs-on: 'ubuntu-latest'
87+
88+
# Indicate that this job depends on the prior job finishing:
89+
needs: markdown_links
90+
91+
# Run this job regardless of the outcome of the prior job:
92+
if: always()
93+
94+
# Set defaults:
95+
defaults:
96+
run:
97+
# Set the default shell to `bash`:
98+
shell: bash --noprofile --norc -eo pipefail {0}
99+
100+
# Define the sequence of job steps...
101+
steps:
102+
103+
# Resolve notification data:
104+
- name: 'Resolve notification data'
105+
run: |
106+
echo 'NOTIFICATION_STATUS=${{ needs.markdown_links.result}}' >> $GITHUB_ENV
107+
if [[ "${{ needs.markdown_links.result }}" = "success" ]]; then
108+
echo 'NOTIFICATION_TEXT=**markdown_links** workflow succeeded' >> $GITHUB_ENV
109+
echo 'NOTIFICATION_AUTHOR_NAME=Success' >> $GITHUB_ENV
110+
elif [[ "${{ needs.markdown_links.result }}" = "failure" ]]; then
111+
echo 'NOTIFICATION_TEXT=**markdown_links** workflow failed' >> $GITHUB_ENV
112+
echo 'NOTIFICATION_AUTHOR_NAME=Failure' >> $GITHUB_ENV
113+
elif [[ "${{ needs.markdown_links.result }}" = "cancelled" ]]; then
114+
echo 'NOTIFICATION_TEXT=**markdown_links** workflow was canceled' >> $GITHUB_ENV
115+
echo 'NOTIFICATION_AUTHOR_NAME=Canceled' >> $GITHUB_ENV
116+
else
117+
exit 1
118+
fi
119+
timeout-minutes: 5
120+
121+
# Send notification to Slack:
122+
- name: 'Send notification'
123+
uses: 8398a7/action-slack@v3
124+
if: success()
125+
with:
126+
status: "${{ env.NOTIFICATION_STATUS }}"
127+
fields: repo,commit,message
128+
text: "${{ env.NOTIFICATION_TEXT }}"
129+
author_name: "${{ env.NOTIFICATION_AUTHOR_NAME }}"
130+
env:
131+
SLACK_WEBHOOK_URL: ${{ secrets.REPO_SLACK_WEBHOOK_URL }}
132+
timeout-minutes: 5

0 commit comments

Comments
 (0)