Skip to content
Latchkey

CI workflow (GoogleChrome/lighthouse-ci)

The CI workflow from GoogleChrome/lighthouse-ci, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: GoogleChrome/lighthouse-ci.github/workflows/ci.ymlLicense Apache-2.0View source

What it does

This is the CI workflow from the GoogleChrome/lighthouse-ci repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  basics:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: Windows
            os: windows-latest
          - name: macOS
            os: macos-latest
    env:
      YARN_GPG: 'no'
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Use Node.js 18
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn
      - run: yarn install --frozen-lockfile
      - run: yarn build
      - run: yarn test:unit:ci || yarn test:unit:ci --onlyFailures --maxWorkers=1 || yarn test:unit:ci --onlyFailures --maxWorkers=1
      - if: ${{ failure() }}
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: packages/server/test/ui/__image_snapshots__/__diff_output__/*.png
      - if: ${{ failure() }}
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: packages/server/test/e2e/__image_snapshots__/__diff_output__/*.png
      - if: ${{ failure() }}
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: packages/viewer/test/e2e/__image_snapshots__/__diff_output__/*.png
  complete:
    name: Linux
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:12
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: mysql
          MYSQL_DATABASE: test
          MYSQL_ROOT_HOST: '%'
        ports:
          - 33306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Use Node.js 18
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn
      # Since Ubuntu 23, dev builds of Chromium need this.
      # https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
      - run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
      - name: Configure Environment
        run: |-
          echo "CHROME_PATH=$(which google-chrome-stable)" >> $GITHUB_ENV
          echo "POSTGRES_DB_URL=postgres://postgres:postgres@localhost/lighthouse_ci_test" >> $GITHUB_ENV
          echo "MYSQL_DB_URL=mysql://root:mysql@127.0.0.1:33306/lighthouse_ci_test" >> $GITHUB_ENV

          export PGPASSWORD="postgres"
          export MYSQL_PWD="mysql"
          psql -h localhost -p 5432 -c 'create database lighthouse_ci_test;' -U postgres
          mysql --host=127.0.0.1 --port=33306 -e 'create database lighthouse_ci_test;' -u root

          google-chrome-stable --version
      - run: yarn install --frozen-lockfile
      - run: yarn build
      - run: yarn test:typecheck
      - run: yarn test:lint
      - name: Run yarn test:unit
        run: yarn test:unit:ci || yarn test:unit:ci --onlyFailures --maxWorkers=1 || yarn test:unit:ci --onlyFailures --maxWorkers=1
      - run: yarn test:docker
      # TODO: re-enable, once we have canary server up again
      # - run: yarn ci:dogfood
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      #     LHCI_CANARY_SERVER_URL: https://lhci-canary.herokuapp.com/
      #     LHCI_CANARY_SERVER_TOKEN: ${{ secrets.LHCI_CANARY_SERVER_TOKEN }}

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  basics:
    timeout-minutes: 30
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: Windows
            os: windows-latest
          - name: macOS
            os: macos-latest
    env:
      YARN_GPG: 'no'
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Use Node.js 18
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn
      - run: yarn install --frozen-lockfile
      - run: yarn build
      - run: yarn test:unit:ci || yarn test:unit:ci --onlyFailures --maxWorkers=1 || yarn test:unit:ci --onlyFailures --maxWorkers=1
      - if: ${{ failure() }}
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: packages/server/test/ui/__image_snapshots__/__diff_output__/*.png
      - if: ${{ failure() }}
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: packages/server/test/e2e/__image_snapshots__/__diff_output__/*.png
      - if: ${{ failure() }}
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: packages/viewer/test/e2e/__image_snapshots__/__diff_output__/*.png
  complete:
    timeout-minutes: 30
    name: Linux
    runs-on: latchkey-small
    services:
      postgres:
        image: postgres:12
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: mysql
          MYSQL_DATABASE: test
          MYSQL_ROOT_HOST: '%'
        ports:
          - 33306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Use Node.js 18
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: yarn
      # Since Ubuntu 23, dev builds of Chromium need this.
      # https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
      - run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
      - name: Configure Environment
        run: |-
          echo "CHROME_PATH=$(which google-chrome-stable)" >> $GITHUB_ENV
          echo "POSTGRES_DB_URL=postgres://postgres:postgres@localhost/lighthouse_ci_test" >> $GITHUB_ENV
          echo "MYSQL_DB_URL=mysql://root:mysql@127.0.0.1:33306/lighthouse_ci_test" >> $GITHUB_ENV
 
          export PGPASSWORD="postgres"
          export MYSQL_PWD="mysql"
          psql -h localhost -p 5432 -c 'create database lighthouse_ci_test;' -U postgres
          mysql --host=127.0.0.1 --port=33306 -e 'create database lighthouse_ci_test;' -u root
 
          google-chrome-stable --version
      - run: yarn install --frozen-lockfile
      - run: yarn build
      - run: yarn test:typecheck
      - run: yarn test:lint
      - name: Run yarn test:unit
        run: yarn test:unit:ci || yarn test:unit:ci --onlyFailures --maxWorkers=1 || yarn test:unit:ci --onlyFailures --maxWorkers=1
      - run: yarn test:docker
      # TODO: re-enable, once we have canary server up again
      # - run: yarn ci:dogfood
      #   env:
      #     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      #     LHCI_CANARY_SERVER_URL: https://lhci-canary.herokuapp.com/
      #     LHCI_CANARY_SERVER_TOKEN: ${{ secrets.LHCI_CANARY_SERVER_TOKEN }}
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow