This commit is contained in:
2026-08-10 20:40:27 +02:00
parent 7c9a275cc5
commit 343afe021a
+24 -22
View File
@@ -23,10 +23,7 @@ jobs:
env: env:
WEBSITE_URL: ${{ secrets.WEBSITE_URL }} WEBSITE_URL: ${{ secrets.WEBSITE_URL }}
run: | run: |
set +e if curl \
# Follow redirects and fail on HTTP errors.
curl \
--silent \ --silent \
--show-error \ --show-error \
--location \ --location \
@@ -34,12 +31,11 @@ jobs:
--max-time 30 \ --max-time 30 \
--connect-timeout 10 \ --connect-timeout 10 \
"$WEBSITE_URL" "$WEBSITE_URL"
then
EXIT_CODE=$? echo "Website is UP"
if [ "$EXIT_CODE" -eq 0 ]; then
echo "status=up" >> "$GITHUB_OUTPUT" echo "status=up" >> "$GITHUB_OUTPUT"
else else
echo "Website is DOWN"
echo "status=down" >> "$GITHUB_OUTPUT" echo "status=down" >> "$GITHUB_OUTPUT"
fi fi
@@ -50,55 +46,61 @@ jobs:
NTFY_URL: ${{ secrets.NTFY_URL }} NTFY_URL: ${{ secrets.NTFY_URL }}
NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }} NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }}
run: | run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ -f "./websiteIsDown" ]; then if [ -f "./websiteIsDown" ]; then
# Website was previously detected as down.
# Website was previously down
if [ "$WEBSITE_STATUS" = "up" ]; then if [ "$WEBSITE_STATUS" = "up" ]; then
echo "Website is back up." echo "Website is back up."
rm ./websiteIsDown rm ./websiteIsDown
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./websiteIsDown git add ./websiteIsDown
git commit -m "chore: website is back up" git commit -m "chore: website is back up"
git push git push
echo "Sending notification..."
curl \ curl \
--fail \ --fail \
--silent \ --silent \
--show-error \ --show-error \
-X POST \ --request POST \
-H "Authorization: Bearer $NTFY_TOKEN" \ --header "Authorization: Bearer $NTFY_TOKEN" \
-d "Website is back up: $WEBSITE_URL" \ --data "Website is back up: $WEBSITE_URL" \
"$NTFY_URL" "$NTFY_URL"
else else
echo "Website is still down. No notification." echo "Website is still down. No notification."
fi fi
else else
# Website was not previously detected as down.
# Website was previously up
if [ "$WEBSITE_STATUS" = "down" ]; then if [ "$WEBSITE_STATUS" = "down" ]; then
echo "Website is down." echo "Website is down."
touch ./websiteIsDown touch ./websiteIsDown
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./websiteIsDown git add ./websiteIsDown
git commit -m "chore: website is down" git commit -m "chore: website is down"
git push git push
echo "Sending notification..."
curl \ curl \
--fail \ --fail \
--silent \ --silent \
--show-error \ --show-error \
-X POST \ --request POST \
-H "Authorization: Bearer $NTFY_TOKEN" \ --header "Authorization: Bearer $NTFY_TOKEN" \
-d "Website is down: $WEBSITE_URL" \ --data "Website is down: $WEBSITE_URL" \
"$NTFY_URL" "$NTFY_URL"
else else
echo "Website is up. Nothing to do." echo "Website is up. Nothing to do."
fi fi
fi fi