Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): Added Lighthouse CI to PR checks #3761

Merged
merged 26 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3873153
added lighthouse CI
sarthakkundra Nov 16, 2020
d7ba998
removed bootstrap and blog-only urls
sarthakkundra Nov 17, 2020
3f72815
upload results to public storage
sarthakkundra Nov 17, 2020
1cbc5e4
added lighthousesrc.json
sarthakkundra Nov 18, 2020
c4c314e
corrected configPath
sarthakkundra Nov 18, 2020
c4f8490
corrected robots-txt assertion
sarthakkundra Nov 18, 2020
82a583c
corrected syntax for lighthousesrc
sarthakkundra Nov 18, 2020
1d90b1a
tried different audit
sarthakkundra Nov 18, 2020
5c9ddbb
corrected all audits for lighthouse
sarthakkundra Nov 18, 2020
379fde0
added is-crawlable audit to skip
sarthakkundra Nov 18, 2020
8a2591c
added lighthouse stats commit to action
sarthakkundra Nov 24, 2020
f672a67
Fixed Lighthouse yml syntax
sarthakkundra Nov 24, 2020
5fb61f4
Fixed lighthouse yml syntax(2)
sarthakkundra Nov 24, 2020
b966170
trying comment
sarthakkundra Nov 24, 2020
cc28a4f
trying yaml syntax
sarthakkundra Nov 24, 2020
67395f9
test logging
sarthakkundra Nov 24, 2020
adf78ad
trying to see a log
sarthakkundra Nov 24, 2020
e02e269
logging....
sarthakkundra Nov 24, 2020
ee4fcee
corrected audit step id
sarthakkundra Nov 24, 2020
607efd4
Corrected token
sarthakkundra Nov 24, 2020
0f966e0
changed comment number from issue to PR
sarthakkundra Nov 24, 2020
bd70339
trying different message
sarthakkundra Nov 24, 2020
85f6507
corrected message
sarthakkundra Nov 24, 2020
0ea0d94
added offline-start-url to skip audits
sarthakkundra Nov 24, 2020
789f845
added start-url to skip fields
sarthakkundra Nov 24, 2020
b407ab8
added offline-starts-url
sarthakkundra Nov 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
sarthakkundra marked this conversation as resolved.
Show resolved Hide resolved
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"]
}
}
}
}