Skip to content

Health Check

Health Check #11

Workflow file for this run

name: Health Check
on:
schedule:
- cron: '*/5 * * * *' # Runs every 5 minutes
workflow_dispatch:
permissions:
contents: write # Grants write permission
jobs:
health-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Check backend health
id: health
run: |
STATUS="OFFLINE"
CUSTOM_MESSAGE="The backend server is currently down. Please try again later."
COLOR="aa0000"
if curl -s https://harmless-ram-luckily.ngrok-free.app/health | grep -q 'UP'; then
STATUS="ONLINE"
CUSTOM_MESSAGE="The backend server is up and running smoothly."
COLOR="00aa00"
fi
echo "::set-output name=status::$STATUS"
echo "::set-output name=message::$CUSTOM_MESSAGE"
- name: Update README with status
if: ${{ steps.health.outputs.status == 'ONLINE' }}
run: |
STATUS="${{ steps.health.outputs.status }}"
COLOR="${{ steps.health.outputs.color }}"
sed -i "s|<!-- health-status -->|<img alt='status' title='Status' src='https://custom-icon-badges.demolab.com/badge/-server%20status:%20${STATUS}-${COLOR}?style=for-the-badge&logo=server&logoColor=white'/>|" README.md
- name: Commit and push status update
if: ${{ steps.health.outputs.status == 'ONLINE' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m "Update health status to ${{ steps.health.outputs.message }}"
git push