Tests workflow (gruntjs/grunt)
The Tests workflow from gruntjs/grunt, explained and optimized by Latchkey.
D
CI health: D - needs work
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 Tests workflow from the gruntjs/grunt 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
workflow (.yml)
name: Tests
on: [push, pull_request]
env:
FORCE_COLOR: 2
jobs:
run:
name: Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node: [16, 18, 20, 22, 24]
os: [ubuntu-latest, windows-latest]
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install npm dependencies
run: npm i
- name: Run tests
run: npm test
# We test multiple Windows shells because of prior stdout buffering issues
# filed against Grunt. https://github.com/joyent/node/issues/3584
- name: Run PowerShell tests
run: "npm test # PowerShell" # Pass comment to PS for easier debugging
shell: powershell
if: startsWith(matrix.os, 'windows')
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, pull_request] env: FORCE_COLOR: 2 concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: run: timeout-minutes: 30 name: Node ${{ matrix.node }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: node: [16, 18, 20, 22, 24] os: [ubuntu-latest, windows-latest] steps: - name: Clone repository uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: cache: 'npm' node-version: ${{ matrix.node }} - name: Install npm dependencies run: npm i - name: Run tests run: npm test # We test multiple Windows shells because of prior stdout buffering issues # filed against Grunt. https://github.com/joyent/node/issues/3584 - name: Run PowerShell tests run: "npm test # PowerShell" # Pass comment to PS for easier debugging shell: powershell if: startsWith(matrix.os, 'windows')
What changed
- 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.
This workflow runs 1 job (10 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.