Node.js CI workflow (laravel-mix/laravel-mix)
The Node.js CI workflow from laravel-mix/laravel-mix, explained and optimized by Latchkey.
CI health: C - fair
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the Node.js CI workflow from the laravel-mix/laravel-mix 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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [master]
pull_request:
branches: [master, next]
jobs:
build:
name: Build and test for ${{ matrix.os }} - ${{ matrix.node-version }}
runs-on: ${{ matrix.os }}
env:
CI: true
PLAYWRIGHT_BROWSERS_PATH: 0
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm ci --legacy-peer-deps
- name: Run Tests
run: npm test
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions name: Node.js CI on: push: branches: [master] pull_request: branches: [master, next] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build: timeout-minutes: 30 name: Build and test for ${{ matrix.os }} - ${{ matrix.node-version }} runs-on: ${{ matrix.os }} env: CI: true PLAYWRIGHT_BROWSERS_PATH: 0 strategy: fail-fast: false matrix: node-version: [14.x, 16.x, 18.x, 19.x] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: cache: 'npm' node-version: ${{ matrix.node-version }} - name: Install Dependencies run: npm ci --legacy-peer-deps - name: Run Tests run: npm test
What changed
- Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
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 (8 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.