Skip to content

(wip) Add lighthouse CI#65

Draft
hbmartin wants to merge 9 commits into
masterfrom
lighthouse
Draft

(wip) Add lighthouse CI#65
hbmartin wants to merge 9 commits into
masterfrom
lighthouse

Conversation

@hbmartin
Copy link
Copy Markdown
Owner

@hbmartin hbmartin commented Oct 26, 2025

Summary by CodeRabbit

  • New Features

    • Integrated automated Lighthouse CI workflow for performance audits.
    • Added a local script to run Lighthouse audits after building the demo.
  • Chores

    • Added Lighthouse CI configuration for collection, assertions, and report output.
    • Deferred and namespaced demo styling initialization for Tailwind.
    • Ignored Lighthouse CI artifacts in version control.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 26, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a Lighthouse CI workflow, LHCI config, a package script, and .gitignore entry; updates demo HTML to namespace Tailwind config and defer its script load. The workflow builds the repo and demo, runs LHCI autorun, computes/report paths, and uploads Lighthouse reports and artifacts.

Changes

Cohort / File(s) Summary
CI Workflow
​.github/workflows/lighthouse.yml
New GitHub Actions workflow ("Lighthouse CI") triggered on pushes to main and on PRs; checks out code, sets up Node 22.x with Yarn caching, installs deps, builds library and demo (yarn build, yarn build:demo --base=/react-mentions-ts/), runs npx @lhci/cli@0.15.x autorun, computes report dirs from lighthouserc.cjs, ensures dirs, conditionally uploads fallback manifest, and always uploads two artifacts (lighthouse-reports, lighthouse-artifacts).
LHCI Configuration
lighthouserc.cjs
Adds CommonJS LHCI config exporting ci.collect (staticDistDir: demo/dist, numberOfRuns: 2, startServerReadyTimeout: 30000, settings: logLevel verbose, chromeFlags --enable-logging=stderr), ci.assert (preset lighthouse:recommended, disables categories:pwa), and ci.upload (target filesystem, outputDir ./lighthouse-reports).
NPM Scripts
package.json
Adds lighthouse script that runs the demo build then npx @lhci/cli@0.15.x autorun.
VCS Ignore
.gitignore
Adds .lighthouseci to ignore Lighthouse CI artifacts.
Demo HTML
demo/index.html
Replaces global tailwind.config with `window.tailwind = window.tailwind

Sequence Diagram(s)

sequenceDiagram
  participant GH as GitHub Actions
  participant Runner as CI Runner
  participant Repo as Repository
  participant Node as Node/Yarn
  participant Build as Build Steps
  participant LHCI as @lhci/cli
  participant FS as Filesystem
  participant Upload as upload-artifact

  GH->>Runner: triggered on push to main or PR
  Runner->>Repo: checkout
  Runner->>Node: setup Node 22.x + yarn cache
  Runner->>Node: yarn install --frozen-lockfile
  Runner->>Build: yarn build
  Runner->>Build: yarn build:demo --base=/react-mentions-ts/
  Build->>LHCI: npx @lhci/cli@0.15.x autorun (reads lighthouserc.cjs)
  LHCI-->>Runner: writes .lighthouseci/ and ./lighthouse-reports
  Runner->>Upload: upload-artifact name=lighthouse-reports path=${{ steps.outputs.reportsPath }}
  Runner->>Upload: upload-artifact name=lighthouse-artifacts path=${{ steps.outputs.resultsPath }}
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Pay special attention to:
    • REPORTS_DIR detection and paths in .github/workflows/lighthouse.yml
    • startServerReadyTimeout and LHCI run behavior for static demo
    • Demo index.html Tailwind namespacing and deferred script correctness

Possibly related PRs

Suggested labels

Review effort 2/5

Poem

🐰 I hopped through CI with nimble feet,

I built the demo and kept it neat.
Reports in folders, safe and bright,
Tailwind waits for evening light.
A rabbit's audit, snug and slight.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title '(wip) Add lighthouse CI' is partially related to the changeset. While it mentions Lighthouse CI, it uses the '(wip)' prefix suggesting work-in-progress status, which is informal and the actual changes involve adding Lighthouse CI configuration files, workflow automation, and demo modifications—more comprehensive than the minimal title suggests. Consider removing '(wip)' prefix and clarifying the scope. A clearer title might be 'Add Lighthouse CI workflow and configuration' to better reflect the multiple files and setup involved.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lighthouse

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @hbmartin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates Lighthouse CI into the project, establishing an automated process for auditing the web application's quality metrics. The primary goal is to continuously monitor and ensure high standards for performance, accessibility, and best practices within the demo environment, providing early feedback on potential regressions or improvements.

Highlights

  • Lighthouse CI Integration: Introduces Lighthouse CI to automate web performance, accessibility, and other audits for the project's demo build.
  • Configuration File: Adds "lighthouserc.js" to define Lighthouse CI settings, including the directory for static assets ("demo/dist"), number of runs, and disabling PWA assertions.
  • New Script: A "lighthouse" script is added to "package.json" to build the demo and then execute the Lighthouse CI audit.
  • Gitignore Update: The ".lighthouseci" directory is added to ".gitignore" to prevent temporary Lighthouse CI output from being committed.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/lighthouse.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.20%. Comparing base (f3e7b1a) to head (22dea7a).
⚠️ Report is 24 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #65   +/-   ##
=======================================
  Coverage   83.20%   83.20%           
=======================================
  Files          35       35           
  Lines        1280     1280           
  Branches      292      292           
=======================================
  Hits         1065     1065           
  Misses         97       97           
  Partials      118      118           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Lighthouse CI to the project, which is a great step for monitoring performance. I've added a couple of suggestions: one to improve the stability of the Lighthouse reports by adjusting the number of runs, and a critical fix for the lighthouse script in package.json which currently uses a non-existent version of @lhci/cli and would fail.

Comment thread package.json
"clean": "rimraf dist",
"build": "yarn clean && tsup --config tsup.config.ts",
"build:demo": "vite build --config demo/vite.config.ts",
"lighthouse": "yarn build:demo && npx @lhci/cli@0.15.x autorun",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The specified version 0.15.x for @lhci/cli does not exist on npm, which will cause this script to fail. The latest version is 0.13.0.

For better dependency management, I recommend adding @lhci/cli to your devDependencies (yarn add -D @lhci/cli@^0.13.0). This will ensure version consistency across all environments.

Suggested change
"lighthouse": "yarn build:demo && npx @lhci/cli@0.15.x autorun",
"lighthouse": "yarn build:demo && npx @lhci/cli@^0.13.0 autorun",

Comment thread lighthouserc.js
ci: {
collect: {
staticDistDir: 'demo/dist',
numberOfRuns: 2,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To get more stable Lighthouse scores, it's recommended to use an odd number of runs (like 3 or 5) to calculate a median. With 2 runs, you're getting an average, which can be more susceptible to outliers. The default value for this property is 3.

Suggested change
numberOfRuns: 2,
numberOfRuns: 3,

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lighthouserc.js (1)

5-7: Consider reducing the server ready timeout.

The startServerReadyTimeout is set to 120 seconds (2 minutes), which is quite long for serving a static demo site. Typical static sites are ready almost immediately.

Consider reducing this to 30 seconds unless there's a specific reason for the extended timeout:

   collect: {
     staticDistDir: 'demo/dist',
     numberOfRuns: 2,
-    startServerReadyTimeout: 120_000,
+    startServerReadyTimeout: 30_000,
   },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3e7b1a and d59d579.

📒 Files selected for processing (4)
  • .github/workflows/lighthouse.yml (1 hunks)
  • .gitignore (2 hunks)
  • lighthouserc.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Lighthouse CI
lighthouserc.js

[error] 2-2: ReferenceError: module is not defined in ES module scope. This file is treated as an ES module but uses CommonJS 'module' syntax.

🔇 Additional comments (4)
.gitignore (1)

6-6: LGTM!

Both additions are appropriate for ignoring CI artifacts generated by the Lighthouse CI workflow and build tooling.

Also applies to: 17-17

.github/workflows/lighthouse.yml (2)

1-11: LGTM!

The workflow configuration is appropriate, triggering on main branch pushes and pull requests to catch performance regressions early.


12-28: Verify repository setup: Lighthouse CI GitHub App token must be configured before workflow can post status checks.

The LHCI_GITHUB_APP_TOKEN should be obtained by authorizing the Lighthouse CI GitHub App and copying the token provided on the authorization page, then adding it to your build environment as a repository secret. Without this secret, the workflow will execute but status checks from Lighthouse will not appear on pull requests.

The workflow code itself is correct. This is a prerequisite setup task—ensure the Lighthouse CI GitHub App is installed and the token is added to the repository secrets before relying on PR status checks.

package.json (1)

41-41: Version constraint is current.

The latest version of @lhci/cli is 0.15.1 (published June 25, 2025), and the script's 0.15.x constraint correctly resolves to this version while maintaining stability across patch releases.

Comment thread lighthouserc.js
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lighthouserc.cjs (1)

1-19: Solid Lighthouse CI configuration!

The configuration follows best practices with appropriate preset selection and PWA disabled for a library demo. The setup will effectively monitor performance regressions.

One optional optimization: the startServerReadyTimeout of 120 seconds (line 7) seems excessive for serving static files. For a static demo build, 30-45 seconds is typically sufficient.

Consider reducing the timeout:

-      startServerReadyTimeout: 120_000,
+      startServerReadyTimeout: 30_000,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e74098f and 1dce517.

📒 Files selected for processing (3)
  • .github/workflows/lighthouse.yml (1 hunks)
  • demo/index.html (2 hunks)
  • lighthouserc.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/lighthouse.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lighthouse
🔇 Additional comments (2)
demo/index.html (2)

8-9: LGTM! Proper Tailwind config namespacing.

The defensive initialization and explicit window namespacing prevents potential conflicts and aligns with Tailwind CDN best practices.


25-25: Excellent performance optimization!

Deferring the Tailwind CSS script load prevents render-blocking and will positively impact Lighthouse performance scores.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/lighthouse.yml (2)

29-29: Make the demo base path configurable or document the assumption.

The hardcoded base path /react-mentions-ts/ assumes the demo will always be served from this path. If the demo might be served from a different location (e.g., in staging or production), consider making this configurable via a workflow input or environment variable. Otherwise, add a comment explaining why this path is fixed.


33-35: Document the required LHCI_GITHUB_APP_TOKEN secret.

The workflow references the LHCI_GITHUB_APP_TOKEN secret, but there's no documentation in the repo (e.g., in a CONTRIBUTING or workflow setup guide) about how to configure this secret. Consider adding a comment or updating your CONTRIBUTING guide to explain how maintainers should set up this token.

Would you like me to help generate documentation or a setup guide for the LHCI token?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1dce517 and 9d2e01e.

📒 Files selected for processing (2)
  • .github/workflows/lighthouse.yml (1 hunks)
  • lighthouserc.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lighthouserc.cjs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lighthouse
🔇 Additional comments (3)
.github/workflows/lighthouse.yml (3)

32-32: Verify the DEBUG pattern intent.

The debug environment variable DEBUG=lhci:*,-*:verbose excludes any logger suffixed with :verbose, which may inadvertently suppress important warnings and diagnostic output. Confirm this is intentional; if you want full logging, use DEBUG=lhci:* instead.


42-44: Verify both artifact paths exist and are necessary.

The workflow uploads artifacts from .lighthouseci/ and lighthouse-reports/. Confirm that both paths are created by Lighthouse CI and are necessary for your reporting needs. If only one is generated, remove the unused path to avoid upload warnings.


1-44: Good foundation for Lighthouse CI integration.

The workflow structure is solid: frozen lockfile ensures reproducibility, artifact upload on all outcomes aids debugging, and the multi-step build approach is appropriate. Verify the Lighthouse configuration in lighthouserc.cjs includes proper audit budgets or collection settings so the CI adds value beyond data collection.

… directory from lighthouserc.cjs,

    ensures both .lighthouseci and the configured reports folder exist, re-runs lhci upload when
    the filesystem target isn’t populated yet, and records both paths in step outputs for downstream
    use .github/workflows/lighthouse.yml:33-55.
  - Artifact uploads now rely on those outputs, eliminating hard‑coded paths that didn’t match the config
    and caused the “path required” failure .github/workflows/lighthouse.yml:63-73.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/lighthouse.yml (1)

39-43: Simplify and harden the config extraction logic.

The inline Node.js code that reads lighthouserc.cjs is fragile. It relies on require() without explicit error handling and could fail if the config file has syntax errors, missing exports, or path resolution issues. Extract this logic into a dedicated helper script or use a more robust approach.

Consider creating a dedicated .js helper file or using a simpler approach:

-          REPORTS_DIR=$(node -p "(() => {
-            const cfg = require('./lighthouserc.cjs')
-            const dir = (cfg && cfg.ci && cfg.ci.upload && cfg.ci.upload.outputDir) || 'lighthouse-reports'
-            return dir.startsWith('./') ? dir.slice(2) : dir
-          })()")
+          REPORTS_DIR=$(node -e "
+            try {
+              const cfg = require('./lighthouserc.cjs');
+              const dir = (cfg?.ci?.upload?.outputDir) || 'lighthouse-reports';
+              console.log(dir.startsWith('./') ? dir.slice(2) : dir);
+            } catch (e) {
+              console.log('lighthouse-reports');
+            }
+          ")

This adds basic error handling to fall back to a default directory if config parsing fails.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd395b9 and 0012e65.

📒 Files selected for processing (2)
  • .github/workflows/lighthouse.yml (1 hunks)
  • lighthouserc.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lighthouserc.cjs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lighthouse
🔇 Additional comments (2)
.github/workflows/lighthouse.yml (2)

48-50: Clarify the conditional upload logic.

The upload condition [ -f ".lighthouseci/manifest.json" ] && [ -z "$(ls -A "$REPORTS_DIR" 2>/dev/null)" ] uploads reports only when the manifest exists and the reports directory is empty. This logic is counterintuitive—typically you'd upload when reports exist, not when they're missing. Add a comment explaining this workaround and verify it aligns with your Lighthouse CI workflow expectations.


35-35: No action required—@lhci/cli@0.15.x is current and secure.

The latest stable version is 0.15.1 (published June 25, 2025), which falls within the @0.15.x range used in the workflow. No security advisories or direct vulnerabilities are reported for version 0.15.x. The version specification is acceptable.

on:
push:
branches:
- main
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Branch name mismatch: workflow triggers on main but PR target is master.

The workflow is configured to run on the main branch, but the PR indicates the target branch is master. This is a critical blocker—the workflow will not execute on the intended target branch. Verify the correct default branch name for the repository and update accordingly.

Update the workflow trigger to match your target branch:

   on:
     push:
       branches:
-        - main
+        - master
     pull_request:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- main
- master
🤖 Prompt for AI Agents
In .github/workflows/lighthouse.yml around line 6 the workflow is set to trigger
on branch "main" while the PR target (and repository default) is "master";
update the workflow trigger to the correct branch name (replace "main" with
"master" or adjust to the repository's actual default branch), verify any other
branch names in the file match the repo, and commit the change so the workflow
will run on the intended target branch.

@openhands-ai
Copy link
Copy Markdown

openhands-ai Bot commented Oct 27, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Lighthouse CI

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #65 at branch `lighthouse`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@hbmartin hbmartin marked this pull request as draft December 18, 2025 21:37
@hbmartin hbmartin changed the title Add lighthouse CI (wip) Add lighthouse CI Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant