Update Discord with Uptime Status #4061
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: Update Discord with Uptime Status | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: '*/30 * * * *' | |
jobs: | |
send_discord_message: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Fetch README content | |
id: fetch_readme | |
run: | | |
readme_content=$(head -n 1 README.md) # Read the first line | |
echo "::set-output name=content::$readme_content" | |
- name: Determine status color | |
id: determine_status | |
run: | | |
status="online" | |
color=5814783 # Green by default | |
if grep -q "offline" README.md; then | |
status="offline" | |
color=16711680 # Red | |
elif grep -q "partial" README.md; then | |
status="partial" | |
color=16753920 # Orange | |
fi | |
echo "::set-output name=status::$status" | |
echo "::set-output name=color::$color" | |
- name: Print fetched content for debugging | |
run: | | |
echo "Fetched README content: ${{ steps.fetch_readme.outputs.content }}" | |
echo "Status: ${{ steps.determine_status.outputs.status }}" | |
echo "Color: ${{ steps.determine_status.outputs.color }}" | |
- name: Send status to Discord | |
env: | |
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
run: | | |
content="${{ steps.fetch_readme.outputs.content }}" | |
status="${{ steps.determine_status.outputs.status }}" | |
color="${{ steps.determine_status.outputs.color }}" | |
# Properly escape the fetched content | |
escaped_content=$(echo "$content" | jq -Rsa .) | |
echo "Sending status to Discord" | |
curl -H "Content-Type: application/json" \ | |
-d "{ | |
\"embeds\": [ | |
{ | |
\"title\": \"Miko Radio Uptime Status Update\", | |
\"description\": \"Here is the latest status update for Miko Radio.\", | |
\"color\": $color, | |
\"fields\": [ | |
{ | |
\"name\": \"Website\", | |
\"value\": \"[Miko Radio](https://mikoradio.com)\", | |
\"inline\": true | |
}, | |
{ | |
\"name\": \"Status Page\", | |
\"value\": \"[Miko Radio Status](https://status.mikoradio.com)\", | |
\"inline\": true | |
}, | |
{ | |
\"name\": \"Summary\", | |
\"value\": $escaped_content, | |
\"inline\": false | |
} | |
] | |
} | |
] | |
}" \ | |
$DISCORD_WEBHOOK_URL | |