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: | if [ -z "${WEBSITE_URL}" ]; then echo "ERROR: WEBSITE_URL is empty." exit 1 fi echo "Checking website..." if curl \ --fail \ --silent \ --show-error \ --location \ --max-time 30 \ --connect-timeout 10 \ --request GET \ "${WEBSITE_URL}" then echo "Website is UP" echo "status=up" >> "${GITHUB_OUTPUT}" else echo "Website is DOWN" 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: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" if [ -f "./websiteIsDown" ]; then if [ "${WEBSITE_STATUS}" = "up" ]; then echo "Website is back up." rm ./websiteIsDown git add ./websiteIsDown git commit -m "chore: website is back up" git push echo "Sending notification..." curl \ --fail \ --silent \ --show-error \ --request POST \ --header "Authorization: Bearer ${NTFY_TOKEN}" \ --data "Website is back up: ${WEBSITE_URL}" \ "${NTFY_URL}" else echo "Website is still down. No notification." fi else if [ "${WEBSITE_STATUS}" = "down" ]; then echo "Website is down." touch ./websiteIsDown git add ./websiteIsDown git commit -m "chore: website is down" git push echo "Sending notification..." curl \ --fail \ --silent \ --show-error \ --request POST \ --header "Authorization: Bearer ${NTFY_TOKEN}" \ --data "Website is down: ${WEBSITE_URL}" \ "${NTFY_URL}" else echo "Website is up. Nothing to do." fi fi