Improve reports #70
Workflow file for this run
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
# Performs Lighthouse checks | |
name: Lighthouse | |
on: | |
# Runs on pushes targeting the default branch | |
pull_request: | |
branches: ["main"] | |
# Default to bash | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
# Check on PR | |
lighthouse: | |
runs-on: ubuntu-latest | |
env: | |
HUGO_VERSION: 0.108.0 | |
permissions: | |
# Required to upload/save artifact, otherwise you'll get | |
# "Error: Resource not accessible by integration" | |
contents: write | |
# Required to post comment, otherwise you'll get | |
# "Error: Resource not accessible by integration" | |
pull-requests: write | |
steps: | |
- name: Install Hugo CLI | |
run: | | |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ | |
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
- name: Install Dart Sass Embedded | |
run: sudo snap install dart-sass-embedded | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Install Node.js dependencies | |
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" | |
- name: Build with Hugo | |
working-directory: ./src | |
env: | |
# For maximum backward compatibility with Hugo modules | |
HUGO_ENVIRONMENT: production | |
HUGO_ENV: production | |
run: | | |
hugo \ | |
--minify | |
- name: Run Hugo Server | |
working-directory: ./src | |
env: | |
# For maximum backward compatibility with Hugo modules | |
HUGO_ENVIRONMENT: production | |
HUGO_ENV: production | |
# Run server in background | |
run: hugo server & | |
# Wait till the server warms up | |
- run: sleep 15 | |
- run: mkdir -p ${{ github.workspace }}/tmp/desktop | |
- run: mkdir -p ${{ github.workspace }}/tmp/mobile | |
- name: Lighthouse Desktop | |
uses: foo-software/lighthouse-check-action@v12.0.1 | |
id: lighthouseDesktop | |
with: | |
device: 'desktop' | |
locale: 'en' | |
tag: "desktop" | |
prCommentEnabled: false | |
prCommentSaveOld: true | |
gitAuthor: ${{ github.actor }} | |
gitBranch: ${{ github.ref }} | |
gitHubAccessToken: ${{ secrets.GITHUB_TOKEN }} | |
outputDirectory: ${{ github.workspace }}/tmp/desktop | |
# see https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md | |
# and https://github.com/GoogleChrome/lighthouse/blob/main/core/config/default-config.js | |
overridesJsonFile: ./lighthouse-overrides.json | |
sha: ${{ github.sha }} | |
urls: 'http://localhost:1313/' | |
- name: Lighthouse Mobile | |
uses: foo-software/lighthouse-check-action@v12.0.1 | |
id: lighthouseMobile | |
with: | |
device: 'mobile' | |
locale: 'en' | |
tag: "mobile" | |
prCommentEnabled: false | |
prCommentSaveOld: true | |
gitAuthor: ${{ github.actor }} | |
gitBranch: ${{ github.ref }} | |
gitHubAccessToken: ${{ secrets.GITHUB_TOKEN }} | |
outputDirectory: ${{ github.workspace }}/tmp/mobile | |
# see https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md | |
# and https://github.com/GoogleChrome/lighthouse/blob/main/core/config/default-config.js | |
overridesJsonFile: ./lighthouse-overrides.json | |
sha: ${{ github.sha }} | |
urls: 'http://localhost:1313/' | |
- name: Upload mobile report | |
id: lighthouseMobileReport | |
uses: actions/upload-artifact@master | |
with: | |
name: Lighthouse-mobile-report | |
path: ${{ github.workspace }}/tmp/mobile | |
- name: Upload desktop report | |
id: lighthouseDesktopReport | |
uses: actions/upload-artifact@master | |
with: | |
name: Lighthouse-desktop-report | |
path: ${{ github.workspace }}/tmp/desktop | |
- name: Parse Mobile Scores | |
id: mobileScores | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
try { | |
const fs = require('fs') | |
const jsonString = fs.readFileSync("${{ github.workspace }}/tmp/mobile/results.json") | |
var score = JSON.parse(jsonString) | |
console.log(score[0].scores) | |
} catch(err) { | |
core.error("Error while reading or parsing the JSON") | |
core.setFailed(err) | |
} | |
- name: Parse Desktop Scores | |
id: desktopScores | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
try { | |
const fs = require('fs') | |
const jsonString = fs.readFileSync("${{ github.workspace }}/tmp/desktop/results.json") | |
var score = JSON.parse(jsonString) | |
console.log(score[0].scores) | |
} catch(err) { | |
core.error("Error while reading or parsing the JSON") | |
core.setFailed(err) | |
} | |
- name: Publish the reports | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
### Lighthouse Reports | |
| Mode | Accessibility | Best Practicies | Performance | SEO | Report | | |
| Mobile | ${{ steps.mobileScores.outputs.accessibility }} | ${{ steps.mobileScores.outputs.bestPractices }} | ${{ steps.mobileScores.outputs.performance }} | ${{ steps.mobileScores.outputs.seo }} | [Mobile.zip](${{ steps.lighthouseMobileReport.outputs.artifact-url }}) | | |
| Desktop | ${{ steps.desktopScores.outputs.accessibility }} | ${{ steps.desktopScores.outputs.bestPractices }} | ${{ steps.desktopScores.outputs.performance }} | ${{ steps.desktopScores.outputs.seo }} | [Desktop.zip](${{ steps.lighthouseDesktopReport.outputs.artifact-url }}) | | |
- name: Verify Lighthouse Desktop Results | |
uses: foo-software/lighthouse-check-status-action@v3.0.1 | |
with: | |
lighthouseCheckResults: ${{ steps.lighthouseDesktop.outputs.lighthouseCheckResults }} | |
minAccessibilityScore: "80" | |
minBestPracticesScore: "80" | |
minPerformanceScore: "40" | |
minProgressiveWebAppScore: "0" | |
minSeoScore: "70" | |
- name: Verify Lighthouse Mobile Results | |
uses: foo-software/lighthouse-check-status-action@v3.0.1 | |
with: | |
lighthouseCheckResults: ${{ steps.lighthouseMobile.outputs.lighthouseCheckResults }} | |
minAccessibilityScore: "80" | |
minBestPracticesScore: "80" | |
minPerformanceScore: "40" | |
minProgressiveWebAppScore: "0" | |
minSeoScore: "70" |