Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cronjob to check website is online #228

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/webcheck.yaml
Original file line number Diff line number Diff line change
@@ -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.
Loading