Skip to content

Server Status Badge #967

Server Status Badge

Server Status Badge #967

Workflow file for this run

name: Server Status Badge
permissions:
contents: write # Grants the workflow permission to push changes
on:
schedule:
- cron: '*/5 * * * *' # Runs every 5 minutes
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
check-server-status:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure Git
run: |
git config --global user.name 'OtsoBear'
git config --global user.email '[email protected]'
- name: Pull latest changes
run: |
git pull origin main
- name: Check Server Status and Create Badge
id: server_status
run: |
response=$(curl --write-out "%{http_code}\n" --silent --output /dev/null https://otso.veistera.com/translate)
echo "Received HTTP response: $response"
if [ "$response" -eq 200 ]; then
echo "Server Status: Online"
badge_url="![Server Status](https://img.shields.io/badge/Server-Online-brightgreen)"
echo "online" > server-status.txt
else
echo "Server Status: Offline (HTTP Code: $response)"
badge_url="![Server Status](https://img.shields.io/badge/Server-Offline-red)"
echo "offline" > server-status.txt
fi
# Output status for debugging
echo "Current server status written to file: $(cat server-status.txt)"
# Debug print to show current content of README.md
echo "Current content of README.md:"
cat README.md
# Use sed to replace the badge if it exists
if grep -q "!\[Server Status\]" README.md; then
echo "Server Status badge found in README.md. Replacing with new badge."
# Replace existing badge using a regex pattern
sed -i.bak "s|!\[Server Status\](.*)|$badge_url|g" README.md
echo "Badge updated in README.md."
else
echo "Server Status badge not found in README.md. Adding new badge."
# Append the badge if it doesn't exist
echo "$badge_url" >> README.md
echo "Badge appended to README.md."
fi
# Debug print to show updated content of README.md
echo "Updated content of README.md:"
cat README.md
- name: Commit changes
run: |
# Check if there are changes to commit
if [[ -n $(git status --porcelain) ]]; then
git add server-status.txt README.md # Add README.md to the commit
git commit -m "Update Server status badge"
git push
echo "Changes committed and pushed."
else
echo "No changes to commit."
fi