From 2db730d837f4cdafc98eac1a3e26b52fdad38026 Mon Sep 17 00:00:00 2001 From: Marlon Saglia Date: Thu, 8 Aug 2024 15:24:23 +0200 Subject: [PATCH] feat: add workflow to run htmlproofer --- .github/workflows/jekyll-link-checker.yml | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/jekyll-link-checker.yml diff --git a/.github/workflows/jekyll-link-checker.yml b/.github/workflows/jekyll-link-checker.yml new file mode 100644 index 0000000..6cc3356 --- /dev/null +++ b/.github/workflows/jekyll-link-checker.yml @@ -0,0 +1,78 @@ +--- +name: Link Checker + +on: + workflow_call: + inputs: + ignore-urls: + description: "Comma separated list of URLs to ignore" + required: false + default: "" + type: string + ignore-files: + description: "Comma separated list of files to ignore" + required: false + default: "" + type: string + swap-urls: + description: "Comma separated list of URLs to swap" + required: false + type: string + default: >- + (https\://github.com.*/master/.*)#.*:\1, + (https\://github.com.*/main/.*)#.*:\1, + (https\://github.com.*/blob/.*)#.*:\1 + +defaults: + run: + # Specify to ensure "pipefail and errexit" are set. + # Ref: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defaultsrunshell + shell: bash + +jobs: + htmlproofer: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: true + + - name: Build site + run: | + bunbdle exec jekyll build + + - name: Clean redirections + run: | + # Remove the redirect-files before link-check + find _site/ -name \*.html | \ + xargs grep -l "Click here if you are not redirected." | xargs rm + + - name: Clean code elements from html + run: | + # htmlproofer does not check links inside "" and "
" elements
+          find _site -name \*.html | xargs sed -i.orig 's/]*>//g; s/<\/code>//g; s/]*>//g; s/<\/pre>//g;'
+          find _site -name \*.orig | xargs rm
+
+      - name: check links
+        env:
+          LANG: "C.UTF-8"
+          IGNORE_URLS: "${{ inputs.ignore-urls }}"
+          IGNORE_FILES: "${{ inputs.ignore-files }}"
+          SWAP_URLS: "${{ inputs.swap-urls }}"
+        run: |
+          bundle exec htmlproofer \
+            --assume-extension .html \
+            --no-enforce-https \
+            --no-check-external-hash \
+            --allow-missing-href \
+            --typhoeus '{"connecttimeout": 10, "timeout": 30, "accept_encoding": "zstd,br,gzip,deflate"}' \
+            --hydra '{"max_concurrency": 1}' \
+            --ignore-files "${IGNORE_FILES}" \
+            --ignore-urls "${IGNORE_URLS}" \
+            --swap-urls "${SWAP_URLS}" \
+            _site