From 4f638ba6b0e033e4ca1d1c9f23d5e5751108d1fe Mon Sep 17 00:00:00 2001 From: Luke Moll Date: Thu, 7 Mar 2024 21:04:58 +0000 Subject: [PATCH 1/6] Add webcheck.yaml Provides a GitHub actions that runs regularly, checking the website is a) online and b) up-to-date. If the job fails, it indicates that something is amiss with the infrastructure (Runciman, at time of writing). --- .github/workflows/webcheck.yaml | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/webcheck.yaml diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml new file mode 100644 index 0000000..72fd571 --- /dev/null +++ b/.github/workflows/webcheck.yaml @@ -0,0 +1,40 @@ +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/" + +# TODO: would be good to catch various failures and present a more friendly message. + +jobs: + myjob: + runs-on: ubuntu-latest + steps: + - name: Fetch website + # If this step fails, likely some issue with DNS, HTTPS, or server not running. + run: curl $WEBSITE_URL -o index.html --connect-timeout 5 + + - uses: actions/checkout@v4 + with: + # Only need the latest commit + fetch-depth: 1 + # And don't even need any files! + sparse-checkout: . + + - 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 + # If this step fails, then the website is out-of-date. + run: grep ${{steps.git_sha.outputs.SHA}} index.html From c5213d9092d20304bebaf31034946f5250795f4b Mon Sep 17 00:00:00 2001 From: Luke Moll Date: Fri, 8 Mar 2024 20:44:21 +0000 Subject: [PATCH 2/6] Rename actions, add nicer output formatting --- .github/workflows/webcheck.yaml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml index 72fd571..88b62f3 100644 --- a/.github/workflows/webcheck.yaml +++ b/.github/workflows/webcheck.yaml @@ -13,12 +13,18 @@ env: # TODO: would be good to catch various failures and present a more friendly message. jobs: - myjob: + webcheck: runs-on: ubuntu-latest steps: - 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 + 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 }}" - uses: actions/checkout@v4 with: @@ -36,5 +42,11 @@ jobs: 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! From a953952dbf1a4839c44f6c83149c9594f457ee1e Mon Sep 17 00:00:00 2001 From: Luke Moll Date: Mon, 18 Mar 2024 21:06:35 +0000 Subject: [PATCH 3/6] Try with unicode escapes --- .github/workflows/webcheck.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml index 88b62f3..d41daca 100644 --- a/.github/workflows/webcheck.yaml +++ b/.github/workflows/webcheck.yaml @@ -24,7 +24,8 @@ jobs: - name: Error message if cURL fails if: failure() # Hopefully displays a nicely formatted error - run: echo "::error title=cURL:: ${{ steps.curl.outputs.OUTPUT }}" + # TODO: turn this into a block with a "this might mean Runciman is offline" + run: echo "\u003a\u003aerror title=cURL\u003a\u003a${{ steps.curl.outputs.OUTPUT }}" - uses: actions/checkout@v4 with: @@ -48,5 +49,6 @@ jobs: - name: Error message if SHA mismatches # Only run if this specific step failed. + # TODO: turn this into a block with a "this might mean xxx is broken" 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! + run: echo \u003a\u003error title=SHA mismatch\u003a\u003The commit SHA ${{steps.git_sha.outputs.SHA}} was not found in index.html! From af5cca7f781df7f9bd30034f6ed9c1fe281c7e43 Mon Sep 17 00:00:00 2001 From: Luke Moll Date: Mon, 18 Mar 2024 21:23:06 +0000 Subject: [PATCH 4/6] Put the colons back and add messages --- .github/workflows/webcheck.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml index d41daca..a24476d 100644 --- a/.github/workflows/webcheck.yaml +++ b/.github/workflows/webcheck.yaml @@ -10,8 +10,6 @@ on: env: WEBSITE_URL: "https://www.hacksoc.org/" -# TODO: would be good to catch various failures and present a more friendly message. - jobs: webcheck: runs-on: ubuntu-latest @@ -24,8 +22,7 @@ jobs: - name: Error message if cURL fails if: failure() # Hopefully displays a nicely formatted error - # TODO: turn this into a block with a "this might mean Runciman is offline" - run: echo "\u003a\u003aerror title=cURL\u003a\u003a${{ steps.curl.outputs.OUTPUT }}" + run: echo "::error title=cURL::${{ steps.curl.outputs.OUTPUT }}. This might mean that Runciman is offline" - uses: actions/checkout@v4 with: @@ -49,6 +46,5 @@ jobs: - name: Error message if SHA mismatches # Only run if this specific step failed. - # TODO: turn this into a block with a "this might mean xxx is broken" if: failure() && steps.grep.conclusion == 'failure' - run: echo \u003a\u003error title=SHA mismatch\u003a\u003The commit SHA ${{steps.git_sha.outputs.SHA}} was not found in index.html! + 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. From f73f2a8d5aa3776558c85dfe7de88ac7941097c8 Mon Sep 17 00:00:00 2001 From: Luke Moll Date: Mon, 18 Mar 2024 21:37:12 +0000 Subject: [PATCH 5/6] Check that index.html was actually written --- .github/workflows/webcheck.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml index a24476d..48cbed8 100644 --- a/.github/workflows/webcheck.yaml +++ b/.github/workflows/webcheck.yaml @@ -24,6 +24,9 @@ jobs: # 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 + - uses: actions/checkout@v4 with: # Only need the latest commit From fe74ad43f6ed6c05097d836c48395624ff5a2308 Mon Sep 17 00:00:00 2001 From: Luke Moll Date: Mon, 18 Mar 2024 21:40:36 +0000 Subject: [PATCH 6/6] Do checkout before fetch --- .github/workflows/webcheck.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/webcheck.yaml b/.github/workflows/webcheck.yaml index 48cbed8..5abd014 100644 --- a/.github/workflows/webcheck.yaml +++ b/.github/workflows/webcheck.yaml @@ -14,6 +14,13 @@ 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. @@ -27,13 +34,6 @@ jobs: - name: Check index.html was written correctly run: stat index.html > /dev/null - - uses: actions/checkout@v4 - with: - # Only need the latest commit - fetch-depth: 1 - # And don't even need any files! - sparse-checkout: . - - 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