Add GitHub Actions health check workflow #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Health Check | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
schedule: | ||
# Every 5 minutes | ||
- cron: '*/5 * * * *' | ||
jobs: | ||
health-check: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
# Placeholder for endpoints - to be specified later | ||
endpoint: [] | ||
fail-fast: false | ||
steps: | ||
- name: Check Version | ||
id: version | ||
shell: bash | ||
run: | | ||
VERSION_JSON=$(curl -s "${{ matrix.endpoint }}/__version__") | ||
echo "Version info for ${{ matrix.endpoint }}:" | ||
echo "$VERSION_JSON" | ||
echo "version_info=$VERSION_JSON" >> "$GITHUB_OUTPUT" | ||
- name: Check Services | ||
shell: bash | ||
run: | | ||
MONITOR_JSON=$(curl -s "${{ matrix.endpoint }}/services/monitor.json") | ||
echo "Services status for ${{ matrix.endpoint }}:" | ||
echo "$MONITOR_JSON" | ||
# Parse JSON and check for down services | ||
echo "Checking for down services..." | ||
echo "$MONITOR_JSON" | jq -r 'to_entries | .[] | select(.value.state == false) | "\(.key) is down: \(.value.status)"' | ||
# If any service is down, check if the JSON contains any false states | ||
if echo "$MONITOR_JSON" | jq -e 'to_entries | .[] | select(.value.state == false)' > /dev/null; then | ||
echo "::error::One or more services are down!" | ||
exit 1 | ||
fi |