All Projects → treosh → Lighthouse Ci Action

treosh / Lighthouse Ci Action

Licence: mit
Audit URLs using Lighthouse and test performance with Lighthouse CI.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lighthouse Ci Action

nuxt-delay-hydration
Improve your Nuxt.js v2 Google Lighthouse score by delaying hydration ⚡️
Stars: ✭ 135 (-79.73%)
Mutual labels:  lighthouse
plugin-lighthouse
Lighthouse plugin for sitespeed.io
Stars: ✭ 24 (-96.4%)
Mutual labels:  lighthouse
Lighthouse Action
💡🏠 GitHub Action for running @GoogleChromeLabs Lighthouse webpage audits
Stars: ✭ 263 (-60.51%)
Mutual labels:  lighthouse
uPyEcho
Emulated Belkin WeMo device that works with Amazon Echo (Alexa) using MicroPython on an ESP32
Stars: ✭ 44 (-93.39%)
Mutual labels:  lighthouse
nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (-89.64%)
Mutual labels:  lighthouse
one-platform
An integrated application hosting platform.
Stars: ✭ 22 (-96.7%)
Mutual labels:  lighthouse
site-audit-seo
Web service and CLI tool for SEO site audit: crawl site, lighthouse all pages, view public reports in browser. Also output to console, json, csv, xlsx, Google Drive.
Stars: ✭ 91 (-86.34%)
Mutual labels:  lighthouse
Libsurvive
Open Source Lighthouse Tracking System
Stars: ✭ 462 (-30.63%)
Mutual labels:  lighthouse
webperf-dashboard
Web Performance Dashboard forked from https://github.com/boyney123/garie
Stars: ✭ 51 (-92.34%)
Mutual labels:  lighthouse
react-seo-friendly-spa-template
React PWA/SPA template initially scaffolded with CRA (Create React App) and configured for SEO. Makes use of prerendering and other techniques/packages in order to achieve a perfect "Lighthouse Score".
Stars: ✭ 24 (-96.4%)
Mutual labels:  lighthouse
joomla-pythagoras
Joomla Pythagoras Repository
Stars: ✭ 19 (-97.15%)
Mutual labels:  lighthouse
docker-google-lighthouse-puppeteer
Google Lighthouse + Puppeteer / Docker Image
Stars: ✭ 29 (-95.65%)
Mutual labels:  lighthouse
ethereum2-docker-compose
Run different kind of Ethereum 2 staking nodes with monitoring tools and own Ethereum 1 node out of the box!
Stars: ✭ 59 (-91.14%)
Mutual labels:  lighthouse
lighthouse-mocha-example
Sample using lighthouse and lighthouse-core with Mocha to run tests on your project/site.
Stars: ✭ 60 (-90.99%)
Mutual labels:  lighthouse
Webpack Lighthouse Plugin
A Webpack plugin for Lighthouse
Stars: ✭ 271 (-59.31%)
Mutual labels:  lighthouse
react-lighthouse-viewer
A React component used for rendering Lighthouse JSON reports Demo:
Stars: ✭ 49 (-92.64%)
Mutual labels:  lighthouse
performance-budgets
performance-budgets gives you a simple way to check and stay on top of performance
Stars: ✭ 56 (-91.59%)
Mutual labels:  lighthouse
Garie
Open source web performance
Stars: ✭ 484 (-27.33%)
Mutual labels:  lighthouse
Exthouse
Analyze the impact of a browser extension on web performance.
Stars: ✭ 377 (-43.39%)
Mutual labels:  lighthouse
partytown
Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
Stars: ✭ 3,626 (+444.44%)
Mutual labels:  lighthouse

Lighthouse CI Action

Audit URLs using Lighthouse and test performance with Lighthouse CI.

This action integrates Lighthouse CI with Github Actions environment. Making it simple to see failed tests, upload results, run jobs in parallel, store secrets, and interpolate env variables.

It is built in collaboration between Lighthouse Team, Treo (web performance monitoring company), and many excellent contributors.

Features:

  • ✅ Audit URLs using Lighthouse v6
  • 🎯 Test performance with Lighthouse CI assertions or performance budgets
  • 😻 See failed results in the action interface
  • 💾 Upload results to a private LHCI server, Temporary Public Storage, or as artifacts
  • ⚙️ Full control over Lighthouse CI config
  • 🚀 Fast action initialization (less than 1 second)
Lighthouse CI Action

Example

Run Lighthouse on each push to the repo, test performance budget, save results as action artifacts.

Create .github/workflows/main.yml with the list of URLs to audit using Lighthouse.

name: Lighthouse CI
on: push
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Audit URLs using Lighthouse
        uses: treosh/[email protected]
        with:
          urls: |
            https://example.com/
            https://example.com/blog
          budgetPath: ./budget.json # test performance budgets
          uploadArtifacts: true # save results as an action artifacts
          temporaryPublicStorage: true # upload lighthouse report to the temporary storage

Describe your performance budget using a budget.json.

[
  {
    "path": "/*",
    "resourceSizes": [
      {
        "resourceType": "document",
        "budget": 18
      },
      {
        "resourceType": "total",
        "budget": 200
      }
    ]
  }
]

⚙️ See this workflow in use

Recipes

Run Lighthouse and validate against Lighthouse CI assertions.

Create .github/workflows/main.yml with the list of URLs to audit and identify a lighthouserc file with configPath.

main.yml

name: Lighthouse
on: push
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Run Lighthouse on urls and validate with lighthouserc
        uses: treosh/[email protected]
        with:
          urls: 'https://exterkamp.codes/'
          configPath: './lighthouserc.json'

Make a lighthouserc.json file with LHCI assertion syntax.

lighthouserc.json

{
  "ci": {
    "assert": {
      "assertions": {
        "first-contentful-paint": ["error", { "minScore": 0.6 }]
      }
    }
  }
}
Lighthouse CI Action: test Lighthouse assertions

⚙️ See this workflow in use

Upload results to a private LHCI server.

Create .github/workflows/main.yml with the list of URLs to audit using lighthouse, and identify a serverBaseUrl to upload to and an token to use.

Note: use GitHub secrets to keep your server address hidden!

main.yml

name: Lighthouse
on: push
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Run Lighthouse on urls and upload data to private lhci server
        uses: treosh/[email protected]
        with:
          urls: 'https://example.com/'
          serverBaseUrl: ${{ secrets.LHCI_SERVER_URL }}
          serverToken: ${{ secrets.LHCI_SERVER_TOKEN }}
Lighthouse CI Action: Upload results to a private server

⚙️ See this workflow in use

Audit with custom Chrome options and custom Lighthouse config.

Create .github/workflows/main.yml with the list of URLs to audit and identify a lighthouserc file with configPath.

main.yml

name: Lighthouse
on: push
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Run Lighthouse on urls with lighthouserc
        uses: treosh/[email protected]
        with:
          urls: 'https://example.com/'
          configPath: './lighthouserc.json'

Chrome flags can be set directly in the lighthouserc's collect section.

lighthouserc.json

{
  "ci": {
    "collect": {
      "numberOfRuns": 1,
      "settings": {
        "chromeFlags": ["--disable-gpu", "--no-sandbox", "--no-zygote"]
      }
    }
  }
}

Custom Lighthouse config can be defined in a seperate Lighthouse config using the custom Lighthouse config syntax. This is then referenced by the lighthouserc file in the configPath.

lighthouserc.json

{
  "ci": {
    "collect": {
      "numberOfRuns": 1,
      "settings": {
        "configPath": "./lighthouse-config.js"
      }
    }
  }
}

Then put all the custom Lighthouse config in the file referenced in the lighthouserc.

lighthouse-config.js

module.exports = {
  extends: 'lighthouse:default',
  settings: {
    emulatedFormFactor: 'desktop',
    audits: [{ path: 'metrics/first-contentful-paint', options: { scorePODR: 800, scoreMedian: 1600 } }],
  },
}

⚙️ See this workflow in use

Test a static site without having to deploy it.

Create .github/workflows/main.yml and identify a lighthouserc file with a staticDistDir config.

main.yml

name: Lighthouse
on: push
jobs:
  static-dist-dir:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Run Lighthouse against a static dist dir
        uses: treosh/[email protected]
        with:
          # no urls needed, since it uses local folder to scan .html files
          configPath: './lighthouserc.json'

lighthouserc.json

{
  "ci": {
    "collect": {
      "staticDistDir": "./dist"
    }
  }
}

Inside your staticDistDir there should be html files that make up your site. LHCI will run a simple static webserver to host the files, then run an audit against each of them. More details on this process are in the Lighthouse CI docs.

Lighthouse CI Action: Test a static site without having to deploy it

⚙️ See this workflow in use

Integrate Lighthouse CI with Netlify

It waits for Netlify to finish building a preview and then uses a built version to check performance. Hence, recipe is a composition of 2 actions: Wait for Netlify Action and Lighthouse CI Action.

name: Lighthouse CI for Netlify sites
on: pull_request
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/[email protected]
      - name: Use Node.js 12.x
        uses: actions/[email protected]
        with:
          node-version: 12.x
      - name: Install & Build
        run: |
          yarn install
          yarn build
      - name: Wait for the Netlify Preview
        uses: jakepartusch/[email protected]
        id: netlify
        with:
          site_name: 'gallant-panini-bc8593'
      - name: Audit URLs using Lighthouse
        uses: treosh/[email protected]
        with:
          urls: |
            ${{ steps.netlify.outputs.url }}
            ${{ steps.netlify.outputs.url }}/products/
          budgetPath: ./budget.json
          uploadArtifacts: true

⚙️ See this workflow in use

Use URLs interpolation to pass secrets or environment variables

URLs support interpolation of process env variables so that you can write URLs like:

name: Lighthouse CI
on: push
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Run Lighthouse and test budgets
        uses: treosh/[email protected]
        with:
          urls: |
            https://pr-$PR_NUMBER.staging-example.com/
            https://pr-$PR_NUMBER.staging-example.com/blog
          budgetPath: ./budgets.json
          temporaryPublicStorage: true
        env:
          PR_NUMBER: ${{ github.event.pull_request.number }}

⚙️ See this workflow in use

Use with a Lighthouse plugin.

Combine the field performance plugin with Github Actions.

main.yml

name: Lighthouse CI with a plugin
on: push
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - run: npm install # install dependencies, that includes Lighthouse plugins
      - name: Audit URLs with Field Performance Plugin
        uses: treosh/[email protected]
        with:
          urls: |
            https://www.example.com/
          configPath: '.lighthouserc.json'
          temporaryPublicStorage: true

lighthouserc.json

{
  "ci": {
    "collect": {
      "settings": {
        "plugins": ["lighthouse-plugin-field-performance"]
      }
    }
  }
}

Add a plugin as a dependency, so it's installed locally:

package.json

{
  "devDependencies": {
    "lighthouse-plugin-field-performance": "^2.0.1"
  }
}

⚙️ See this workflow in use

Use `output` for a powerful composition with other actions

main.yml

# Example of output usage
name: LHCI-output-webhook
on: push
jobs:
  output-webhook:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Use output for sending data to API.
        id: LHCIAction
        uses: ./
        with:
          urls: |
            https://treo.sh/
      - name: Webhook
          uses: denar90/[email protected]
          with:
            webhookUrl: ${{secrets.ACTION_WEBHOOK_URL}}
            data: '{ "links": ${{steps.LHCIAction.outputs.links}}, "manifest": ${{steps.LHCIAction.outputs.manifest}} }'

⚙️ See this workflow in use

Explore more workflows in public examples. Submit a pull request with a new one if they don't cover your use case.

Inputs

urls

Provide the list of URLs separated by a new line. Each URL is audited using the latest version of Lighthouse and Chrome preinstalled on the environment.

urls: |
  https://example.com/
  https://example.com/blog
  https://example.com/pricing

uploadArtifacts (default: false)

Upload Lighthouse results as action artifacts to persist results. Equivalent to using actions/upload-artifact to save the artifacts with additional action steps.

uploadArtifacts: true

temporaryPublicStorage (default: false)

Upload reports to the temporary public storage.

Note: As the name implies, this is temporary and public storage. If you're uncomfortable with the idea of your Lighthouse reports being stored on a public URL on Google Cloud, use a private LHCI server. Reports are automatically deleted 7 days after upload.

temporaryPublicStorage: true

budgetPath

Use a performance budget to keep your page size in check. Lighthouse CI Action will fail the build if one of the URLs exceeds the budget.

Learn more about the budget.json spec and practical use of performance budgets.

budgetPath: ./budget.json

runs (default: 1)

Specify the number of runs to do on each URL.

Note: Asserting against a single run can lead to flaky performance assertions. Use 1 only to ensure static audits like Lighthouse scores, page size, or performance budgets.

runs: 3

configPath

Set a path to a custom lighthouserc file for full control of the Lighthouse environment and assertions.

Use lighthouserc to configure the collection of data (via Lighthouse config and Chrome Flags), and CI assertions (via LHCI assertions).

configPath: ./lighthouserc.json

serverBaseUrl

Upload Lighthouse results to a private LHCI server by specifying both serverBaseUrl and serverToken. This will replace uploading to temporary-public-storage.

serverBaseUrl: ${{ secrets.LHCI_SERVER_BASE_URL }}
serverToken: ${{ secrets.LHCI_SERVER_TOKEN }}

Note: Use Github secrets to keep your token hidden!

basicAuthUsername basicAuthPassword

Lighthouse servers can be protected with basic authentication LHCI server basic authentication by specifying both basicAuthUsername and basicAuthPassword will authenticate the upload.

basicAuthUsername: ${{ secrets.LHCI_SERVER_BASIC_AUTH_USERNAME }}
basicAuthPassword: ${{ secrets.LHCI_SERVER_BASIC_AUTH_PASSWORD }}

Note: Use Github secrets to keep your username and password hidden!

Outputs

Use outputs to compose results of the LHCI Action with other Github Actions, like webhooks, notifications, or custom assertions.

resultsPath

A path to .lighthouseci results folder:

/Users/lighthouse-ci-action/.lighthouseci

links

A JSON string with a links to uploaded results:

{
  'https://treo.sh/': 'https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1593981455963-59854.report.html'
  ...
}

assertionResults

A JSON string with assertion results:

[
  {
    name: 'maxNumericValue',
    expected: 61440,
    actual: 508455,
    values: [508455],
    operator: '<=',
    passed: false,
    auditProperty: 'total.size',
    auditId: 'resource-summary',
    level: 'error',
    url: 'https://treo.sh/',
    auditTitle: 'Keep request counts low and transfer sizes small',
    auditDocumentationLink: 'https://developers.google.com/web/tools/lighthouse/audits/budgets',
  },
  ...
]

manifest

A JSON string with report results (LHCI docs reference):

;[
  {
    url: 'https://treo.sh/',
    isRepresentativeRun: true,
    htmlPath: '/Users/lighthouse-ci-action/.lighthouseci/treo_sh-_-2020_07_05_20_37_18.report.html',
    jsonPath: '/Users/lighthouse-ci-action/.lighthouseci/treo_sh-_-2020_07_05_20_37_18.report.json',
    summary: { performance: 0.99, accessibility: 0.98, 'best-practices': 1, seo: 0.96, pwa: 0.71 },
  },
]

Credits

Sponsored by Treo and Google.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].