Skip to content
Latchkey

Tests: node.js workflow (react-dates/react-dates)

The Tests: node.js workflow from react-dates/react-dates, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: react-dates/react-dates.github/workflows/node.ymlLicense MITView source

What it does

This is the Tests: node.js workflow from the react-dates/react-dates 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: node.js'

on: [pull_request, push]

jobs:
  matrix:
    runs-on: ubuntu-latest
    outputs:
      latest: ${{ steps.set-matrix.outputs.requireds }}
      minors: ${{ steps.set-matrix.outputs.optionals }}
    steps:
      - uses: ljharb/actions/node/matrix@main
        id: set-matrix
        with:
          type: 'majors'
          versionsAsRoot: true
          preset: '>=4'

  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: ljharb/actions/node/install@main
        with:
          node-version: 'lts/*'
      - uses: actions/cache@v2
        id: cache
        with:
          path: |
            lib
            esm
            test-build
          key: ${{ runner.os }}-${{ hashFiles('package.json', 'src/**', 'test/**', 'scripts/buildCSS.js') }}
      - run: npm run build
        if: steps.cache.outputs.cache-hit != 'true'
      - run: npm run build:test
        if: steps.cache.outputs.cache-hit != 'true'


  majors:
    needs: [build, matrix]
    name: 'latest minors'
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
        react:
          - '16'
          - '16.9'
          - '16.3'
          - '16.0'
          - '15'
          - '15.5'
          - '15.0'
          - '0.14'

    steps:
      - uses: actions/checkout@v2
      - uses: ljharb/actions/node/install@main
        name: 'nvm install ${{ matrix.node-version }} && npm install'
        with:
          node-version: ${{ matrix.node-version }}
          skip-ls-check: ${{ !startsWith(matrix.node-version, '5.') && !startsWith(matrix.node-version, '4.') && 'true' || 'false' }}
      - uses: actions/cache@v2
        id: cache
        with:
          path: |
            lib
            esm
            test-build
          key: ${{ runner.os }}-${{ hashFiles('package.json', 'src/**', 'test/**', 'scripts/buildCSS.js') }}
      - run: npm run react
        env:
          REACT: ${{ matrix.react }}
      - run: npm run tests-only
        env:
          REACT: ${{ matrix.react }}
      - uses: codecov/codecov-action@v2

  node:
    name: 'node.js'
    needs: [majors]
    runs-on: ubuntu-latest
    steps:
      - run: 'echo tests completed'

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: 'Tests: node.js'
 
on: [pull_request, push]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  matrix:
    timeout-minutes: 30
    runs-on: latchkey-small
    outputs:
      latest: ${{ steps.set-matrix.outputs.requireds }}
      minors: ${{ steps.set-matrix.outputs.optionals }}
    steps:
      - uses: ljharb/actions/node/matrix@main
        id: set-matrix
        with:
          type: 'majors'
          versionsAsRoot: true
          preset: '>=4'
 
  build:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - uses: actions/checkout@v2
      - uses: ljharb/actions/node/install@main
        with:
          node-version: 'lts/*'
      - uses: actions/cache@v2
        id: cache
        with:
          path: |
            lib
            esm
            test-build
          key: ${{ runner.os }}-${{ hashFiles('package.json', 'src/**', 'test/**', 'scripts/buildCSS.js') }}
      - run: npm run build
        if: steps.cache.outputs.cache-hit != 'true'
      - run: npm run build:test
        if: steps.cache.outputs.cache-hit != 'true'
 
 
  majors:
    timeout-minutes: 30
    needs: [build, matrix]
    name: 'latest minors'
    runs-on: latchkey-small
 
    strategy:
      fail-fast: false
      matrix:
        node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
        react:
          - '16'
          - '16.9'
          - '16.3'
          - '16.0'
          - '15'
          - '15.5'
          - '15.0'
          - '0.14'
 
    steps:
      - uses: actions/checkout@v2
      - uses: ljharb/actions/node/install@main
        name: 'nvm install ${{ matrix.node-version }} && npm install'
        with:
          node-version: ${{ matrix.node-version }}
          skip-ls-check: ${{ !startsWith(matrix.node-version, '5.') && !startsWith(matrix.node-version, '4.') && 'true' || 'false' }}
      - uses: actions/cache@v2
        id: cache
        with:
          path: |
            lib
            esm
            test-build
          key: ${{ runner.os }}-${{ hashFiles('package.json', 'src/**', 'test/**', 'scripts/buildCSS.js') }}
      - run: npm run react
        env:
          REACT: ${{ matrix.react }}
      - run: npm run tests-only
        env:
          REACT: ${{ matrix.react }}
      - uses: codecov/codecov-action@v2
 
  node:
    timeout-minutes: 30
    name: 'node.js'
    needs: [majors]
    runs-on: latchkey-small
    steps:
      - run: 'echo tests completed'
 

What changed

2 third-party actions are referenced by a movable tag. Pin them 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:

This workflow runs 4 jobs (11 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow