From 0598aa08c3b3326a1f63eeb32c4b716aa4f31fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Rivera?= Date: Mon, 10 Aug 2026 20:18:50 +0200 Subject: [PATCH] Initial action --- .github/workflows/action.yml | 104 +++++++++++++++++++++++++++++++++++ README.md | 8 +++ 2 files changed, 112 insertions(+) create mode 100644 .github/workflows/action.yml diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 0000000..380d46b --- /dev/null +++ b/.github/workflows/action.yml @@ -0,0 +1,104 @@ +name: Website Monitor + +on: + schedule: + - cron: "*/10 * * * *" + workflow_dispatch: + +permissions: + contents: write + +jobs: + monitor: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check website + id: check + env: + WEBSITE_URL: ${{ secrets.WEBSITE_URL }} + run: | + set +e + + # Follow redirects and fail on HTTP errors. + curl \ + --silent \ + --show-error \ + --location \ + --fail \ + --max-time 30 \ + --connect-timeout 10 \ + "$WEBSITE_URL" + + EXIT_CODE=$? + + if [ "$EXIT_CODE" -eq 0 ]; then + echo "status=up" >> "$GITHUB_OUTPUT" + else + echo "status=down" >> "$GITHUB_OUTPUT" + fi + + - name: Handle website status + env: + WEBSITE_STATUS: ${{ steps.check.outputs.status }} + WEBSITE_URL: ${{ secrets.WEBSITE_URL }} + NTFY_URL: ${{ secrets.NTFY_URL }} + NTFY_TOKEN: ${{ secrets.NTFY_TOKEN }} + run: | + if [ -f "./websiteIsDown" ]; then + # Website was previously detected as down. + if [ "$WEBSITE_STATUS" = "up" ]; then + echo "Website is back up." + + rm ./websiteIsDown + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add ./websiteIsDown + git commit -m "chore: website is back up" + git push + + curl \ + --fail \ + --silent \ + --show-error \ + -X POST \ + -H "Authorization: Bearer $NTFY_TOKEN" \ + -d "Website is back up: $WEBSITE_URL" \ + "$NTFY_URL" + else + echo "Website is still down. No notification." + fi + + else + # Website was not previously detected as down. + if [ "$WEBSITE_STATUS" = "down" ]; then + echo "Website is down." + + touch ./websiteIsDown + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add ./websiteIsDown + git commit -m "chore: website is down" + git push + + curl \ + --fail \ + --silent \ + --show-error \ + -X POST \ + -H "Authorization: Bearer $NTFY_TOKEN" \ + -d "Website is down: $WEBSITE_URL" \ + "$NTFY_URL" + else + echo "Website is up. Nothing to do." + fi + fi diff --git a/README.md b/README.md index 5885de9..7c960af 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # action-ntfy-down Really simple GitHub actions to alert via ntfy when a website is down. + + +# How to use +1. Activate actions in your repo. +2. Add the following secrets to your actions + - WEBSITE_URL + - NTFY_URL + - NTFY_TOKEN