diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml new file mode 100644 index 0000000..5abd014 --- /dev/null +++ b/.github/workflows/webcheck.yaml @@ -0,0 +1,53 @@ +name: Website alive and correct + +on: + schedule: + - cron: 30 8 * * 1-5 + # 8:30am, Mon-Fri + workflow_dispatch: + # Also work manually with a button press in GitHub UI. + +env: + WEBSITE_URL: "https://www.hacksoc.org/" + +jobs: + webcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # Only need the latest commit + fetch-depth: 1 + # And don't even need any files! + sparse-checkout: . + + - name: Fetch website + id: curl + # If this step fails, likely some issue with DNS, HTTPS, or server not running. + run: curl $WEBSITE_URL -o index.html --connect-timeout 5 -sS 2>&1 | sed -e 's/^/OUTPUT=/;' >> $GITHUB_OUTPUT + + - name: Error message if cURL fails + if: failure() + # Hopefully displays a nicely formatted error + run: echo "::error title=cURL::${{ steps.curl.outputs.OUTPUT }}. This might mean that Runciman is offline" + + - name: Check index.html was written correctly + run: stat index.html > /dev/null + + - name: Get Git SHA of HEAD + run: git rev-parse main | sed -e 's/^/SHA=/;' >> $GITHUB_OUTPUT + # git rev-parse main -- gets the full SHA1 of the most recent commit to 'main' branch + # sed -e 's/^/SHA=/;' -- adds "sha=" to the start of the line. This is important because... + # >> $GITHUB_OUTPUT -- Store the output in a variable so we can use it later. + # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter + id: git_sha + + - name: Search for Git SHA in fetched HTML + id: grep + # If this step fails, then the website is out-of-date. + run: grep ${{steps.git_sha.outputs.SHA}} index.html + + - name: Error message if SHA mismatches + # Only run if this specific step failed. + if: failure() && steps.grep.conclusion == 'failure' + run: echo ::error title=SHA mismatch::The commit SHA ${{steps.git_sha.outputs.SHA}} was not found in index.html. This means that the live website is out-of-date with the main branch.