-
Notifications
You must be signed in to change notification settings - Fork 1.4k
49 lines (42 loc) · 2 KB
/
alert-on-failed-automerge.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Check Suite Failure Notification
on:
# whenever a workflow suite completes trigger this
check_suite:
types:
- completed
jobs:
notify_on_failure:
if: ${{ github.event.check_suite.conclusion == 'failure' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check if the PR has "automerge" label
id: automerge_check
run: |
pr_number=$(jq -r '.check_suite.pull_requests[0].number' <<< "${{ toJson(github.event) }}")
if [ -z "$pr_number" ]; then
echo "No PR associated with this check suite."
echo "::set-output name=result::false"
exit 0
fi
labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/$pr_number/labels)
echo "Labels: $labels"
if echo "$labels" | grep -q "automerge"; then
echo "::set-output name=result::true"
else
echo "::set-output name=result::false"
fi
- name: Send Slack notification if the PR has "automerge" label
if: ${{ steps.automerge_check.outputs.result == 'true' }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: subscriptions-slack-testing
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://github.com/posthog.png?size=48
SLACK_USERNAME: Max Hedgehog
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
message: "PR #${{ github.event.check_suite.pull_requests[0].number }} failed a check suite and is labeled 'automerge'. Please investigate!"
status: failure