-
Notifications
You must be signed in to change notification settings - Fork 535
67 lines (50 loc) · 1.65 KB
/
health_check.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Health Check
on:
# Run the workflow test on push events
push:
# Run the main workflow on workflow_dispatch or schedule
workflow_dispatch:
schedule:
# Every 5 minutes
- cron: '*/5 * * * *'
jobs:
health_check:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
environment: |
${{fromJson(github.event_name == 'push' && '["test"]' || '["dev","stage","prod"]')}}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Run Health Checks
shell: bash
run: |
set -ue
environment="${{ matrix.environment }}"
output_file="out.json"
./scripts/health_check.py --env $environment --verbose --output $output_file
version=$(cat $output_file | jq -r '.version')
monitors=$(cat $output_file | jq -r '.monitors')
echo "Version: $version"
echo "Monitors: $monitors"
if [ "$version" = "null" ] || [ "$monitors" = "null" ]; then
echo "Environment $environment is not reachable"
exit 1
fi
message=""
data=$(echo $monitors | jq -r 'to_entries[] | select(.value.state == false) | .key')
for monitor in $data; do
message="$message\n- $monitor: $(echo $monitors | jq -r ".[\"$monitor\"].status")"
done
echo "Environment: $environment"
echo "$message"