From e80e1ebfc9754dd2338bf31ff4377f0b3cbe23b6 Mon Sep 17 00:00:00 2001 From: Zhanna Date: Wed, 14 Jun 2023 22:50:06 -0400 Subject: [PATCH] Add link checker for testing --- .github/workflows/broken-link-checker.yml | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/broken-link-checker.yml diff --git a/.github/workflows/broken-link-checker.yml b/.github/workflows/broken-link-checker.yml new file mode 100644 index 000000000..f3c73e962 --- /dev/null +++ b/.github/workflows/broken-link-checker.yml @@ -0,0 +1,71 @@ +name: Check for Broken Links +on: [push, pull_request] +jobs: + build_and_check: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Install dependencies + run: yarn install + + - name: Build website + run: yarn build + + - name: Setup Simple HTTP Server + run: | + nohup yarn start & + + - name: Check HTTP Server status + run: sleep 5 && curl -I http://127.0.0.1:8000 + + - name: Install Broken Link Checker + run: npm install -g broken-link-checker + + - name: Execute Link Checker and Show Broken Links + env: + TEMPORARY_WEBSITE_URL: "http://127.0.0.1:8080" + ACTUAL_WEBSITE_URL: "https://ddmal.music.mcgill.ca/Neon/" + run: | + blc $TEMPORARY_WEBSITE_URL --filter-level=3 | \ + grep -v "$ACTUAL_WEBSITE_URL" | \ + awk ' + BEGIN { + p=1; + buf="" + } + /^Getting links from:/ { + buf=$0; + next + } + /^Finished!.*0 broken\./ { + if (length(buf)>0) { + buf=""; + next + } + } + { + if(length(buf)>0) + print buf; + if (NF > 0) + print; + buf="" + } + /^Finished!/ { + print "" + }' | sed "s|$TEMPORARY_WEBSITE_URL|$ACTUAL_WEBSITE_URL|g" | \ + tee /dev/fd/2 | grep 'HTTP_404' > /dev/null && flag=1 + + if [ "$flag" -eq "1" ]; then + echo "Broken links were found, exiting with an error." + exit 1 + else + echo "No broken links were found (although there may be other HTTP errors), exiting successfully." + exit 0 + fi