CI workflow (preactjs/wmr)
The CI workflow from preactjs/wmr, explained and optimized by Latchkey.
CI health: F - at risk
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the CI workflow from the preactjs/wmr repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
changes:
runs-on: ubuntu-latest
outputs:
wmr: ${{ steps.filter.outputs.wmr }}
preact-iso: ${{ steps.filter.outputs.preact-iso }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
wmr:
- 'packages/wmr/**'
- 'examples/demo/**'
preact-iso:
- 'packages/preact-iso/**'
wmr-prod-test:
needs: changes
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 18.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
if: ${{ needs.changes.outputs.wmr == 'true' }}
run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent
- name: Build
if: ${{ needs.changes.outputs.wmr == 'true' }}
run: yarn wmr build
- name: Test production
if: ${{ needs.changes.outputs.wmr == 'true' }}
run: yarn wmr test-prod
wmr-dev-test:
needs: changes
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 18.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
if: ${{ needs.changes.outputs.wmr == 'true' }}
run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent
- name: Test wmr
if: ${{ needs.changes.outputs.wmr == 'true' }}
run: yarn eslint packages/wmr && yarn wmr test
preact-iso-test:
needs: changes
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 18.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
if: ${{ needs.changes.outputs.preact-iso == 'true' }}
run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent
- name: Test preact-iso
if: ${{ needs.changes.outputs.preact-iso == 'true' }}
run: yarn eslint packages/preact-iso && yarn iso test
lhci:
needs: changes
if: ${{ needs.changes.outputs.wmr == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Prepare LHCI
run: npm install -g @lhci/cli@0.4.x
- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent
- name: Build
run: yarn ci
- name: LHCI
run: lhci autorun --upload.target=temporary-public-storage --collect.url="http://localhost:8080" --collect.startServerCommand="yarn workspace @examples/demo serve" --collect.startServerReadyPattern="server running at" --upload.githubAppToken=${{ secrets.LHCI_GITHUB_APP_TOKEN }}
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. 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: changes: timeout-minutes: 30 runs-on: latchkey-small outputs: wmr: ${{ steps.filter.outputs.wmr }} preact-iso: ${{ steps.filter.outputs.preact-iso }} steps: - uses: actions/checkout@v2 - uses: dorny/paths-filter@v2 id: filter with: filters: | wmr: - 'packages/wmr/**' - 'examples/demo/**' preact-iso: - 'packages/preact-iso/**' wmr-prod-test: timeout-minutes: 30 needs: changes runs-on: latchkey-small strategy: matrix: node-version: [14.x, 18.x] steps: - name: Checkout uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: cache: 'npm' node-version: ${{ matrix.node-version }} - name: Get Yarn cache directory id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Use Yarn cache uses: actions/cache@v2 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - name: Install if: ${{ needs.changes.outputs.wmr == 'true' }} run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent - name: Build if: ${{ needs.changes.outputs.wmr == 'true' }} run: yarn wmr build - name: Test production if: ${{ needs.changes.outputs.wmr == 'true' }} run: yarn wmr test-prod wmr-dev-test: timeout-minutes: 30 needs: changes runs-on: latchkey-small strategy: matrix: node-version: [14.x, 18.x] steps: - name: Checkout uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: cache: 'npm' node-version: ${{ matrix.node-version }} - name: Get Yarn cache directory id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Use Yarn cache uses: actions/cache@v2 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - name: Install if: ${{ needs.changes.outputs.wmr == 'true' }} run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent - name: Test wmr if: ${{ needs.changes.outputs.wmr == 'true' }} run: yarn eslint packages/wmr && yarn wmr test preact-iso-test: timeout-minutes: 30 needs: changes runs-on: latchkey-small strategy: matrix: node-version: [14.x, 18.x] steps: - name: Checkout uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: cache: 'npm' node-version: ${{ matrix.node-version }} - name: Get Yarn cache directory id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Use Yarn cache uses: actions/cache@v2 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - name: Install if: ${{ needs.changes.outputs.preact-iso == 'true' }} run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent - name: Test preact-iso if: ${{ needs.changes.outputs.preact-iso == 'true' }} run: yarn eslint packages/preact-iso && yarn iso test lhci: timeout-minutes: 30 needs: changes if: ${{ needs.changes.outputs.wmr == 'true' }} runs-on: latchkey-small steps: - name: Checkout uses: actions/checkout@v2 - name: Use Node.js 16.x uses: actions/setup-node@v1 with: cache: 'npm' node-version: 16.x - name: Prepare LHCI run: npm install -g @lhci/cli@0.4.x - name: Get Yarn cache directory id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Use Yarn cache uses: actions/cache@v2 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - name: Install run: yarn --prefer-offline --frozen-lockfile --non-interactive --silent - name: Build run: yarn ci - name: LHCI run: lhci autorun --upload.target=temporary-public-storage --collect.url="http://localhost:8080" --collect.startServerCommand="yarn workspace @examples/demo serve" --collect.startServerReadyPattern="server running at" --upload.githubAppToken=${{ secrets.LHCI_GITHUB_APP_TOKEN }}
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
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:
- Dependency installs
This workflow runs 5 jobs (8 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.