Skip to content

Commit

Permalink
feat(ci): add options to disable liquid rendering and run pre-check s…
Browse files Browse the repository at this point in the history
…cript

This commit adds two new options to the Jekyll link checker workflow:

1. `add-no-render-with-liquid`: When set to "true", this option adds `render_with_liquid: false`
   to a set of files (*.md, *.java, *.sd, services.xml, hosts.xml, deployment.xml) before
   building the site. This is useful for preventing liquid rendering in certain files.

2. `pre-check-script`: Allows specifying a path to a script that should be run before
   the link checking step. This can be used to perform additional checks or
   modifications before the main link checking process.

These changes provide more flexibility and control over the build and link
checking process, allowing users to customize the workflow to their specific
needs.
  • Loading branch information
esolitos authored and gitbutler-client committed Aug 14, 2024
1 parent a157bc1 commit b14ae6e
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions .github/workflows/jekyll-link-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ on:
required: false
type: string
default: ""
build-plugins:
description: |
List of plugins to build before building the site, must be one per line.
required: false
type: string
default: ""
add-no-render-with-liquid:
description: |
Set to "true" to adds`render_with_liquid: false` to a set of files before building the site.
File types: *.md, *.java, *.sd, services.xml, hosts.xml, deployment.xml
required: false
type: string
default: "false"
pre-check-script:
description: |
Path to the script to run before checking the links.
required: false
type: string
default: ""

defaults:
run:
Expand All @@ -57,22 +77,42 @@ jobs:
ruby-version: 3.1
bundler-cache: true

- name: Do not render with liquid
if: ${{ inputs.add-no-render-with-liquid == 'true' }}
run: |
find . -not -path './_site/*' \( -name '*.md' -or -name '*.java' -or -name '*.sd' \) | \
while read f; do (echo -e "---\nrender_with_liquid: false\n---\n"; cat ${f})>${f}.new; mv ${f}.new ${f}; done
find . -not -path './_site/*' \( -name services.xml -or -name hosts.xml -or -name deployment.xml \) | \
while read f; do (echo -e "---\nrender_with_liquid: false\n---\n"; cat ${f})>${f}.new; mv ${f}.new ${f}; done
- name: Build Plugins
if: ${{ inputs.build-plugins }}
run: |
for plg in "${{ inputs.build-plugins }}"; do
echo "Building plugin: $plg"
bundle exec jekyll build -p "$plg"
done
- name: Build site
run: |
bundle exec jekyll build
- name: Clean redirections
run: |
# Remove the redirect-files before link-check
find _site/ -name \*.html -print0 | \
find _site/ -name '*.html' -print0 | \
xargs -0 -n 100 --no-run-if-empty grep -l "Click here if you are not redirected." || true | \
xargs --no-run-if-empty rm
- name: Clean code elements from html
run: |
# htmlproofer does not check links inside "<code>" and "<pre>" elements
find _site -name \*.html | xargs sed -i.orig 's/<code[^>]*>//g; s/<\/code>//g; s/<pre[^>]*>//g; s/<\/pre>//g;'
find _site -name \*.orig | xargs rm
find _site -name '*.html' | xargs sed -i'' 's/<code[^>]*>//g; s/<\/code>//g; s/<pre[^>]*>//g; s/<\/pre>//g;'
- name: Run pre-check script
if: ${{ inputs.pre-check-script }}
run: |
${{ inputs.pre-check-script }}
- name: check links
env:
Expand Down

0 comments on commit b14ae6e

Please sign in to comment.