-
Notifications
You must be signed in to change notification settings - Fork 1
Improve Lighthouse CI workflow: use npm ci, npx, dynamic URL, and badges #41
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
Improve Lighthouse CI workflow: use npm ci, npx, dynamic URL, and badges #41
Conversation
Co-authored-by: theartcher <57297314+theartcher@users.noreply.github.com>
theartcher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add badges using https://github.com/myactionway/lighthouse-badger-action, at least the 'Pagespeed Badge' kind.
| - name: Run Lighthouse CI | ||
| run: > | ||
| npx --yes @lhci/cli@0.15.x autorun | ||
| --collect.url="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me what this line does, can you give me some context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 74 (now line 77) constructs the GitHub Pages URL dynamically using repository context variables. github.repository_owner is the owner (e.g., "S7-OpenLearning-Individual") and github.event.repository.name is the repo name (e.g., "DesignPatternPedia"). This creates the full URL: https://s7-openlearning-individual.github.io/DesignPatternPedia/ which is where the site is deployed. This approach makes the workflow self-contained and reusable without hardcoding URLs.
lighthouserc.js
Outdated
| ci: { | ||
| collect: { | ||
| numberOfRuns: 3, | ||
| settings: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you leave an empty object? Is it optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty settings object has been removed in commit 72f908e. It was left there to show where Chrome flags could be configured in the config file, but they're now only passed via the command line in the workflow, making the config cleaner.
lighthouserc.js
Outdated
| }, | ||
| assert: { | ||
| preset: 'lighthouse:recommended', | ||
| assertions: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Lighthouse getting started guide recommended not yet adding assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions section removed in commit 72f908e. Following the Lighthouse getting started guide recommendation, the configuration now only includes collect and upload sections for a simpler initial setup.
Co-authored-by: theartcher <57297314+theartcher@users.noreply.github.com>
Lighthouse badge generation added in commit 72f908e using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves the Lighthouse CI workflow by implementing code review feedback to enhance reproducibility, security, and maintainability of the GitHub Actions configuration. The changes modernize the workflow using npm best practices and add automated badge generation for Lighthouse metrics.
Key changes:
- Replaced
npm installwithnpm ciand enabled npm caching for faster, deterministic builds - Switched from global package installation to
npxfor cleaner CI execution - Constructed GitHub Pages URL dynamically from repository context variables
- Added Lighthouse badge generation with appropriate repository permissions
- Configured Lighthouse CI to run 3 audits for more reliable metrics
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
.github/workflows/deploy.yml |
Enhanced lighthouse job with npm caching, npm ci, npx usage, dynamic URL construction, Chrome headless flags, and badge generation with contents:write permission |
lighthouserc.js |
Added numberOfRuns configuration for reliable metrics averaging and normalized quote style to single quotes |
| --collect.settings.chromeFlags="--headless --no-sandbox --disable-gpu" | ||
| - name: Generate Lighthouse Badges | ||
| uses: myactionway/lighthouse-badger-action@v2.2 |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The badge generation step may fail if the repository is private or if the lighthouse-badger-action encounters issues writing to the repository. Consider adding error handling or making this step continue on error using 'continue-on-error: true' to prevent the entire workflow from failing if badge generation has issues.
| uses: myactionway/lighthouse-badger-action@v2.2 | |
| uses: myactionway/lighthouse-badger-action@v2.2 | |
| continue-on-error: true |
Addresses PR#40 review feedback to make the Lighthouse CI workflow more robust, reproducible, and secure.
Workflow improvements (
.github/workflows/deploy.yml)cache: 'npm'inactions/setup-node@v4npm installwithnpm cifor deterministic installsnpx --yes @lhci/cli@0.15.xinstead of global package installation--headless --no-sandbox --disable-gpufor headless CI executionmyactionway/lighthouse-badger-action@v2.2contents: writepermission for badge generationBefore:
After:
Configuration improvements (
lighthouserc.js)collectsection withnumberOfRuns: 3for reliable metricsOriginal prompt
This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.