Skip to content

Commit

Permalink
feat(v2): Added Lighthouse CI to PR checks (#3761)
Browse files Browse the repository at this point in the history
* added lighthouse CI

removed wait for Netlify action

corrected Netlify deploy urls

corrected sitename

corrected sitename

* removed bootstrap and blog-only urls

* upload results to public storage

* added lighthousesrc.json

* corrected configPath

* corrected robots-txt assertion

* corrected syntax for lighthousesrc

* tried different audit

* corrected all audits for lighthouse

* added is-crawlable audit to skip

* added lighthouse stats commit to action

* Fixed Lighthouse yml syntax

* Fixed lighthouse yml syntax(2)

* trying comment

* trying yaml syntax

* test logging

* trying to see a log

* logging....

* corrected audit step id

* Corrected token

* changed comment number from issue to PR

* trying different message

* corrected message

* added offline-start-url to skip audits

* added start-url to skip fields

* added offline-starts-url
  • Loading branch information
sarthakkundra committed Nov 26, 2020
1 parent fc4b756 commit bd62be9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/lighthouseCI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Lighthouse CI
on: pull_request
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install and Build
run: |
yarn install
yarn build
- name: Wait for the Netlify Preview
uses: jakepartusch/wait-for-netlify-action@v1
id: netlify
with:
site_name: 'docusaurus-2'
- name: Audit URLs using Lighthouse
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v3
with:
urls: |
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/classic/
configPath: ./.github/workflows/lighthousesrc.json
uploadArtifacts: true
temporaryPublicStorage: true
env:
PR_NUMBER: ${{ github.event.pull_request.number}}
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary
const links = ${{ steps.lighthouse_audit.outputs.links }}
const formatResult = (res) => Math.round((res * 100))
Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
const comment = [
`⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:`,
'| Category | Score |',
'| --- | --- |',
`| ${score(result.performance)} Performance | ${result.performance} |`,
`| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`,
`| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`,
`| ${score(result.seo)} SEO | ${result.seo} |`,
`| ${score(result.pwa)} PWA | ${result.pwa} |`,
' ',
`*Lighthouse ran on [${Object.keys(links)[0]}](${Object.keys(links)[0]})*`
].join('\n')
core.setOutput("comment", comment);
- name: Add Lighthouse stats as comment
id: comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2.0.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.pull_request.number }}
header: lighthouse
message: ${{ steps.format_lighthouse_score.outputs.comment }}
9 changes: 9 additions & 0 deletions .github/workflows/lighthousesrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ci": {
"collect": {
"settings": {
"skipAudits": ["robots-txt", "canonical", "tap-targets", "is-crawlable", "works-offline", "offline-start-url"]
}
}
}
}

0 comments on commit bd62be9

Please sign in to comment.