-
Notifications
You must be signed in to change notification settings - Fork 1
59 lines (50 loc) · 1.68 KB
/
healthcheck.yaml
File metadata and controls
59 lines (50 loc) · 1.68 KB
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
50
51
52
53
54
55
56
57
58
59
name: Health Check
on:
schedule:
- cron: '*/10 * * * *'
workflow_dispatch:
jobs:
health-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Read URLs and Check Health
id: healthcheck
run: |
FAIL_LIST=""
for url in $(yq '.urls[]' .github/urls.yaml); do
echo "Checking $url"
set +e
code=$(curl -s -o /dev/null -w "%{http_code}" "$url")
ret=$?
set -e
if [ "$ret" -ne 0 ]; then
code="000"
fi
if [ "$code" -ne 200 ]; then
echo "$url is DOWN (status $code)"
FAIL_LIST+="$url (status code $code)\n"
else
echo "$url is OK"
fi
done
if [ -n "$FAIL_LIST" ]; then
echo "fail_list<<EOF" >> $GITHUB_OUTPUT
echo -e "$FAIL_LIST" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "FAILED=true" >> $GITHUB_ENV
fi
- name: Send Discord Alert if Any Site Fails
if: env.FAILED == 'true'
run: |
MESSAGE=$(echo -e ":x: Health Check Failed!\n\`\`\`\n${{ steps.healthcheck.outputs.fail_list }}\n\`\`\`")
PAYLOAD=$(jq -nc --arg content "$MESSAGE" '{content: $content}')
curl -H "Content-Type: application/json" \
-X POST \
-d "$PAYLOAD" \
${{ secrets.DISCORD_WEBHOOK }}