Tests workflow (unpoly/unpoly)
The Tests workflow from unpoly/unpoly, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, run de-duplication, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Tests workflow from the unpoly/unpoly 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: Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
branches:
- master
jobs:
test:
runs-on: ubuntu-22.04
timeout-minutes: 16
strategy:
fail-fast: false
matrix:
include:
- name: Chrome without CSP
browser: chrome
csp: none
- name: Chrome with nonce-only CSP
browser: chrome
csp: nonce-only
- name: Chrome with strict-dynamic CSP
browser: chrome
csp: strict-dynamic
- name: Chrome with unpoly-migrate
browser: chrome
migrate: true
- name: Chrome with ES6 build
browser: chrome
es6: true
- name: Chrome with minified build
browser: chrome
min: true
# - name: Firefox
# browser: firefox
name: ${{ matrix.name }}
env:
BROWSER: "${{ matrix.browser }}"
CSP: "${{ matrix.csp }}"
MIGRATE: "${{ matrix.migrate }}"
ES6: "${{ matrix.es6 }}"
MIN: "${{ matrix.min }}"
DEBUG: "puppeteer:*,-puppeteer:protocol:*,-puppeteer:webDriverBiDi:*"
steps:
- uses: actions/checkout@v3
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Install Node.js vom .nvmrc
uses: actions/setup-node@v4
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
- name: Install npm dependencies
run: npm ci
- name: Install Firefox for Puppeteer
if: matrix.browser == 'firefox'
run: npx puppeteer browsers install firefox
- name: Build Unpoly and tests
run: npm run build-ci
- name: Start test server
run: npm run test-server &
- name: Wait for test server
run: npx wait-on http://localhost:4000
- name: Run tests
run: npm run test
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: Tests on: push: branches: - master pull_request: branches: - master workflow_dispatch: branches: - master concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test: runs-on: latchkey-small timeout-minutes: 16 strategy: fail-fast: false matrix: include: - name: Chrome without CSP browser: chrome csp: none - name: Chrome with nonce-only CSP browser: chrome csp: nonce-only - name: Chrome with strict-dynamic CSP browser: chrome csp: strict-dynamic - name: Chrome with unpoly-migrate browser: chrome migrate: true - name: Chrome with ES6 build browser: chrome es6: true - name: Chrome with minified build browser: chrome min: true # - name: Firefox # browser: firefox name: ${{ matrix.name }} env: BROWSER: "${{ matrix.browser }}" CSP: "${{ matrix.csp }}" MIGRATE: "${{ matrix.migrate }}" ES6: "${{ matrix.es6 }}" MIN: "${{ matrix.min }}" DEBUG: "puppeteer:*,-puppeteer:protocol:*,-puppeteer:webDriverBiDi:*" steps: - uses: actions/checkout@v3 - name: Read .nvmrc run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" id: nvm - name: Install Node.js vom .nvmrc uses: actions/setup-node@v4 with: cache: 'npm' node-version: "${{ steps.nvm.outputs.NVMRC }}" - name: Install npm dependencies run: npm ci - name: Install Firefox for Puppeteer if: matrix.browser == 'firefox' run: npx puppeteer browsers install firefox - name: Build Unpoly and tests run: npm run build-ci - name: Start test server run: npm run test-server & - name: Wait for test server run: npx wait-on http://localhost:4000 - name: Run tests run: npm run test
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.
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
- End-to-end and browser tests
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.