-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (65 loc) · 2.74 KB
/
Server-Status.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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