CI workflow (preactjs/preact-cli)
The CI workflow from preactjs/preact-cli, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, 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/preact-cli 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:
- master
- next
pull_request:
branches:
- master
- next
jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node-version: [14.x, 16.x]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
cli:
- 'packages/cli/**'
- uses: actions/cache@v3
id: gittar-cache
with:
path: ~/.gittar
key: ${{ runner.os }}-gittar
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-
- run: yarn install --frozen-lockfile
- name: test:cli
if: steps.filter.outputs.cli == 'true'
env:
CI: true
WITH_LOG: true
LIGHTHOUSE_CHROMIUM_PATH: 'which google-chrome-stable'
run: yarn test:cli
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: - master - next pull_request: branches: - master - next concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test: name: Test runs-on: latchkey-small timeout-minutes: 10 strategy: matrix: node-version: [14.x, 16.x] steps: - uses: actions/checkout@v2 with: fetch-depth: 1 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: cache: 'npm' node-version: ${{ matrix.node-version }} - uses: dorny/paths-filter@v2 id: filter with: filters: | cli: - 'packages/cli/**' - uses: actions/cache@v3 id: gittar-cache with: path: ~/.gittar key: ${{ runner.os }}-gittar - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - uses: actions/cache@v3 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: ${{ runner.os }}-yarn- - run: yarn install --frozen-lockfile - name: test:cli if: steps.filter.outputs.cli == 'true' env: CI: true WITH_LOG: true LIGHTHOUSE_CHROMIUM_PATH: 'which google-chrome-stable' run: yarn test:cli
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.
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 1 job (2 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.