GitHub Action to run GSA EDX Lighthouse plugin
This composite action integrates Lighthouse CI and the lighthouse-plugin-edx with Github Actions. The results of the Lighthouse audit are added as a pull request comment.
Run Lighthouse on each pull request.
Create .github/workflows/main.yml and include the EDX-github-action step.
name: Lighthouse CI
on: [pull_request]
permissions:
pull-requests: write
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
- run: npm ci
- name: Audit site using Lighthouse
uses: GSA/EDX-github-action@v1Make a lighthouserc.json file with LHCI assertion syntax.
{
"ci": {
"collect": {
"settings": {
"plugins": ["lighthouse-plugin-edx"]
},
"startServerCommand": "NODE_ENV=production npm run start",
"url": ["http://localhost:3000"]
}
}
}Use a directory of static files instead of a URL
Create .github/workflows/main.yml and include the EDX-github-action step.
name: Lighthouse CI
on: [pull_request]
permissions:
pull-requests: write
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
- run: npm ci
- run: npm run build
- name: Audit site using Lighthouse
uses: GSA/EDX-github-action@v1Make a lighthouserc.json file with LHCI assertion syntax.
{
"ci": {
"collect": {
"settings": {
"plugins": ["lighthouse-plugin-edx"]
},
"staticDistDir": "./_site"
}
}
}Integrate with a Jekyll based site
Create .github/workflows/main.yml and include the EDX-github-action step.
name: Lighthouse CI
on: [pull_request]
permissions:
pull-requests: write
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
bundler-cache: true
- name: Audit site using Lighthouse
uses: GSA/EDX-github-action@v1Make a lighthouserc.json file with LHCI assertion syntax.
{
"ci": {
"collect": {
"settings": {
"plugins": ["lighthouse-plugin-edx"]
},
"startServerCommand": "bundle exec jekyll serve",
"url": ["http://localhost:4000"]
}
}
}Use a configuration file in a custom location
Create .github/workflows/main.yml and include the EDX-github-action step.
name: Lighthouse CI
on: [pull_request]
permissions:
pull-requests: write
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Audit site using Lighthouse
uses: GSA/EDX-github-action@v1
with:
config-path: "./some/dir/lighthouserc.json"Make a lighthouserc.json file with LHCI assertion syntax.
{
"ci": {
"collect": {
"settings": {
"plugins": ["lighthouse-plugin-edx"]
},
"url": ["http://localhost:4000"]
}
}
}Optional Path to Lighthouse configuration file.
See https://github.com/treosh/lighthouse-ci-action/blob/main/README.md#outputs