commit #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: HTML Proofer | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: | | |
[ -f package.json ] && npm ci || npm init -y | |
npm install puppeteer http-server | |
- name: Serve files and render dynamic HTML using Puppeteer | |
run: | | |
npx http-server -p 8080 & | |
SERVER_PID=$! | |
sleep 5 | |
for file in $(find . -maxdepth 1 -iname "*.html" ! -iname "*.partial.html"); do | |
echo "Processing file: ${file:2}" | |
output_file=$file | |
node -e "const puppeteer = require('puppeteer'); | |
(async () => { | |
const url = 'http://localhost:8080/${file:2}'; | |
const browser = await puppeteer.launch({ | |
headless: 'new' | |
}); | |
const page = await browser.newPage(); | |
await page.goto(url, {waitUntil: 'networkidle0'}); | |
const html = await page.content(); | |
await browser.close(); | |
const fs = require('fs'); | |
fs.writeFileSync('$output_file', html); | |
})().catch(err => { | |
console.error('Error processing file:', err); | |
process.exit(1); | |
});" | |
done | |
kill $SERVER_PID | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3.0 | |
- name: Install HTML Proofer | |
run: gem install html-proofer | |
- name: Run HTML Proofer | |
run: | | |
for file in $(find . -maxdepth 1 -iname "*.html" ! -iname "*.partial.html"); do | |
htmlproofer $file --disable-external | |
done |