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

chore: Make Lighthouse CI run on local build #9447

Merged
merged 10 commits into from
Oct 25, 2023
Merged

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Oct 25, 2023

Motivation

Current setup to run Lighthouse on Netlify deploy previews is fragile and unreliable.

Notably the Wait for the Netlify Preview step which only waits for the first deployment, and then on the next commits will not wait, leading to a stale Lighthouse report.

Running on a local build is also less likely to fail

Test Plan

CI

@slorber slorber added the pr: internal This PR does not touch production code, or is not meaningful enough to be in the changelog. label Oct 25, 2023
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 25, 2023
@netlify
Copy link

netlify bot commented Oct 25, 2023

[V2]

Name Link
🔨 Latest commit 51655ca
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6538d6296e84730008cdd510
😎 Deploy Preview https://deploy-preview-9447--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Oct 25, 2023

[V2]

Name Link
🔨 Latest commit d7ee83f
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6538e01d42368200081acee9
😎 Deploy Preview https://deploy-preview-9447--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link

github-actions bot commented Oct 25, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 60 🟢 97 🟢 92 🟢 100 🟠 89 Report
/docs/installation/ 🟠 79 🟢 98 🟢 92 🟢 100 🟠 89 Report
/docs/category/getting-started/ 🟠 85 🟢 100 🟢 92 🟢 90 🟠 89 Report
/blog/ 🟠 84 🟢 100 🟢 92 🟢 90 🟠 89 Report
/blog/preparing-your-site-for-docusaurus-v3/ 🟠 75 🟢 97 🟢 92 🟢 100 🟠 89 Report
/blog/tags/release/ 🟠 75 🟢 100 🟢 92 🟠 80 🟠 89 Report
/blog/tags/ 🟢 92 🟢 100 🟢 92 🟢 90 🟠 89 Report

@slorber slorber merged commit dd03a25 into main Oct 25, 2023
8 checks passed
@slorber slorber deleted the slorber/lighthouse-localhost branch October 25, 2023 09:44
@slorber
Copy link
Collaborator Author

slorber commented Oct 25, 2023

cc @johnnyreilly I think I read your blog post on that topic and maybe you'd be interested to replicate this new setup?

@johnnyreilly
Copy link
Contributor

cc @johnnyreilly I think I read your blog post on that topic and maybe you'd be interested to replicate this new setup?

Hey @slorber - do you mean this post? https://johnnyreilly.com/azure-static-web-apps-a-netlify-alternative

@slorber
Copy link
Collaborator Author

slorber commented Oct 25, 2023

@johnnyreilly this one: https://johnnyreilly.com/lighthouse-meet-github-actions

You have a similar Static Web App - wait for preview step that imho is not ideal

@johnnyreilly
Copy link
Contributor

I don't know - it's worked pretty well for me. But yeah, I'd be happy to help you with that. Would you like me to?

@johnnyreilly
Copy link
Contributor

If you create a Static Web App for Docusaurus (they're free) then I can start the work of plugging my approach into the pipeline?

@johnnyreilly
Copy link
Contributor

There'd be some CI fun and games but we could turn it out pretty fast I think

@johnnyreilly
Copy link
Contributor

And you can leave the Netlify stuff running in parallel either permanently or until you want to drop it.

@johnnyreilly
Copy link
Contributor

johnnyreilly commented Oct 25, 2023

@slorber
Copy link
Collaborator Author

slorber commented Oct 25, 2023

@johnnyreilly I don't know what you mean here, I have no intention to switch to Azure 😅 and even less can convince Meta in a short time frame to do so.

I want to run lighthouse on a local build, which is what I did in this PR, and recommend you to adopt. If you are satisfied with your Azure setup, fine.

Remote urls are more flaky, depend on CDN availability/network, and the "wait for deployment" function is not super reliable and can easily lead to running lighthouse on a deployment url on subsequent deployments, misleading you. I prefer to use something entirely local.

@johnnyreilly
Copy link
Contributor

oh right - I haven't set up Lighthouse to run on a local build before. You can flip open devtools in Chrome and do that pretty easily though. I guess this risk with running locally though, is that any extensions you have installed may pollute the results?

@johnnyreilly
Copy link
Contributor

Maybe there's a way to do it with a docker container and spinning up Chrome headless inside? Haven't done it myself though.

@johnnyreilly
Copy link
Contributor

@johnnyreilly
Copy link
Contributor

johnnyreilly commented Oct 25, 2023

If you do yarn build && yarn serve, does this work for you @slorber?

docker container run --cap-add=SYS_ADMIN \
  -v "$(pwd)/lhci-data:/home/lhci/reports/.lighthouseci" \
  patrickhulce/lhci-client \
  lhci collect --url="http://localhost:3000/"

@slorber
Copy link
Collaborator Author

slorber commented Oct 25, 2023

@johnnyreilly I don't understand why you keep suggesting me things I don't look for 🤪 I don't want to run lighthouse locally, I want to run lighthouse on a local build (instead of a remote url), in the CI, in an automated way. It is working fine already 😅 I don't want to use docker inside github actions, there's no browser extension there

@johnnyreilly
Copy link
Contributor

johnnyreilly commented Oct 25, 2023

No you misunderstand me!

If I understand you correctly, you want to run lighthouse locally on a local build.

I'm suggesting that you can do that by running locally by spinning up Docusaurus with yarn build && yarn serve and then running the following in a separate process:

docker container run --cap-add=SYS_ADMIN \
  -v "$(pwd)/lhci-data:/home/lhci/reports/.lighthouseci" \
  patrickhulce/lhci-client \
  lhci collect --url="http://localhost:3000/"

This should allow you to run locally and run lighthouse locally without being subject to extensions running on your version of Chrome. Does that make sense?

I'm actually not totally sure what you're trying to do.

@slorber
Copy link
Collaborator Author

slorber commented Oct 25, 2023

I'm actually not totally sure what you're trying to do.

I'm not trying to do anything now, it's done already in this PR and working as I want it to 😅

@johnnyreilly
Copy link
Contributor

Okay cool!

@Josh-Cena
Copy link
Collaborator

@johnnyreilly To clarify: the "local" here does not mean on your very own machine. It means building and serving the website within the action runner, where the lighthouse is also run.

@johnnyreilly
Copy link
Contributor

ahhhhhh. I get it. That's totally not what I took from "local" 😆

@slorber
Copy link
Collaborator Author

slorber commented Oct 25, 2023

Yes exactly 😄

Although I'm now using Docker to get a faster feedback, so thanks for the command ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: internal This PR does not touch production code, or is not meaningful enough to be in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants