chore: Make Lighthouse CI run on local build (#9447)

This commit is contained in:
Sébastien Lorber 2023-10-25 11:44:47 +02:00 committed by GitHub
parent c6762a2542
commit dd03a25a71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 15 deletions

View file

@ -22,29 +22,33 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Wait for the Netlify Preview
uses: jakepartusch/wait-for-netlify-action@f1e137043864b9ab9034ae3a5adc1c108e3f1a48 # v1 - name: Use Node.js
id: netlify uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with: with:
site_name: docusaurus-2 node-version: 18
max_timeout: 600
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website fast
run: yarn build:website:fast
- name: Audit URLs using Lighthouse - name: Audit URLs using Lighthouse
id: lighthouse_audit id: lighthouse_audit
uses: treosh/lighthouse-ci-action@03becbfc543944dd6e7534f7ff768abb8a296826 # 10.1.0 uses: treosh/lighthouse-ci-action@03becbfc543944dd6e7534f7ff768abb8a296826 # 10.1.0
with: with:
urls: | urls: |
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/ http://localhost:3000
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/docs/installation/ http://localhost:3000/docs/installation
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/docs/category/getting-started/ http://localhost:3000/docs/category/getting-started
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/blog/ http://localhost:3000/blog
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/blog/preparing-your-site-for-docusaurus-v3/ http://localhost:3000/blog/preparing-your-site-for-docusaurus-v3
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/blog/tags/release/ http://localhost:3000/blog/tags/release
https://deploy-preview-$PR_NUMBER--docusaurus-2.netlify.app/blog/tags/ http://localhost:3000/blog/tags
configPath: ./.github/workflows/lighthouserc.json configPath: ./.github/workflows/lighthouserc.json
uploadArtifacts: true uploadArtifacts: true
temporaryPublicStorage: true temporaryPublicStorage: true
env:
PR_NUMBER: ${{ github.event.pull_request.number}}
- name: Format lighthouse score - name: Format lighthouse score
id: format_lighthouse_score id: format_lighthouse_score

View file

@ -1,6 +1,12 @@
{ {
"ci": { "ci": {
"collect": { "collect": {
"startServerCommand": "yarn serve:website",
"startServerReadyPattern": "Serving",
"startServerReadyTimeout": 10000,
"numberOfRuns": 5,
"settings": { "settings": {
"skipAudits": [ "skipAudits": [
"robots-txt", "robots-txt",

View file

@ -26,6 +26,18 @@ const scoreEntry = (rawScore) => {
return `${scoreIcon} ${score}`; return `${scoreIcon} ${score}`;
}; };
/**
* @param {string} url
* @returns {module:url.URL}
*/
function createURL(url) {
try {
return new URL(url);
} catch (e) {
throw new Error(`Can't create URL for string=${url}`, {cause: e});
}
}
/** /**
* @param {Object} param0 * @param {Object} param0
* @param {string} param0.url * @param {string} param0.url
@ -34,7 +46,7 @@ const scoreEntry = (rawScore) => {
*/ */
const createMarkdownTableRow = ({url, summary, reportUrl}) => const createMarkdownTableRow = ({url, summary, reportUrl}) =>
[ [
`| [${new URL(url).pathname}](${url})`, `| [${createURL(url).pathname}](${url})`,
.../** @type {(keyof LighthouseSummary)[]} */ ( .../** @type {(keyof LighthouseSummary)[]} */ (
Object.keys(summaryKeys) Object.keys(summaryKeys)
).map((k) => scoreEntry(summary[k])), ).map((k) => scoreEntry(summary[k])),