-
Notifications
You must be signed in to change notification settings - Fork 1
35 lines (29 loc) · 1.45 KB
/
notify.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This GitHub workflow will send a notification to Slack when a scheduled test
# workflow completes.
# There needs to be a GitHub secret named "SLACK_HOOK" that is set to the
# incoming webhook URL for Slack. That webhook is tied to a Slack channel, so
# this workflow does not select the channel and relies on that default.
# Instructions to set up Slack for incoming webhooks are here:
# https://api.slack.com/messaging/webhooks.
name: notify
on:
workflow_run:
workflows:
- test
types:
- completed
jobs:
notify:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'schedule' }}
steps:
- name: Post status to Slack
run: |
run_id=$(echo "${{ github.event.workflow_run.url }}" | rev | cut -d '/' -f 1 | rev)
run_url="https://github.com/${{ github.repository }}/actions/runs/$run_id"
branch="${{ github.event.workflow_run.head_branch }}"
branch_url="https://github.com/${{ github.repository }}/commits/$branch"
repo_url="https://github.com/${{ github.repository }}/actions/workflows/test.yml"
emoji=$(if [[ "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then echo ":white_check_mark:"; else echo ":x:"; fi)
json="{ \"text\": \"$emoji <$repo_url|${{ github.repository }}>: Scheduled run <$run_url|$run_id> on branch <$branch_url|$branch>: ${{ github.event.workflow_run.conclusion }}\" }"
curl -s -d "payload=$json" ${{ secrets.SLACK_HOOK }}