Skip to content
Latchkey

Build & Test workflow (react/create-react-app)

The Build & Test workflow from react/create-react-app, explained and optimized by Latchkey.

C

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 →
Source: react/create-react-app.github/workflows/build-and-test.ymlLicense MITView source

What it does

This is the Build & Test workflow from the react/create-react-app 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: 'Build & Test'

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    name: 'Build (${{ matrix.os }}, Node ${{ matrix.node }})'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - 'ubuntu-latest'
        node:
          - '16'
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          cache: 'npm'
      - name: Install dependencies
        run: npm ci --prefer-offline
      - name: Build
        run: npm run build

  integration:
    name: 'Integration Tests (${{ matrix.os }}, Node ${{ matrix.node }})'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - 'ubuntu-latest'
          - 'macos-latest'
          - 'windows-latest'
        node:
          - '16'
    steps:
      - uses: actions/checkout@v3
      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          cache: 'npm'
      - name: Install dependencies
        run: npm ci --prefer-offline
      # The integration tests are run with yarn, so we need to install it.
      - name: Install yarn
        run: npm i -g yarn
      - name: Run integration tests
        run: npm run test:integration

  e2e-simple:
    name: E2E Simple
    uses: ./.github/workflows/e2e-base.yml
    with:
      testScript: 'tasks/e2e-simple.sh'

  e2e-installs:
    name: E2E Installs
    uses: ./.github/workflows/e2e-base.yml
    with:
      testScript: 'tasks/e2e-installs.sh'

  e2e-kitchensink:
    name: E2E Kitchensink
    uses: ./.github/workflows/e2e-base.yml
    with:
      testScript: 'tasks/e2e-kitchensink.sh'

The same workflow, on Latchkey

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

name: 'Build & Test'
 
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
    name: 'Build (${{ matrix.os }}, Node ${{ matrix.node }})'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - 'ubuntu-latest'
        node:
          - '16'
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          cache: 'npm'
      - name: Install dependencies
        run: npm ci --prefer-offline
      - name: Build
        run: npm run build
 
  integration:
    timeout-minutes: 30
    name: 'Integration Tests (${{ matrix.os }}, Node ${{ matrix.node }})'
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - 'ubuntu-latest'
          - 'macos-latest'
          - 'windows-latest'
        node:
          - '16'
    steps:
      - uses: actions/checkout@v3
      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          cache: 'npm'
      - name: Install dependencies
        run: npm ci --prefer-offline
      # The integration tests are run with yarn, so we need to install it.
      - name: Install yarn
        run: npm i -g yarn
      - name: Run integration tests
        run: npm run test:integration
 
  e2e-simple:
    timeout-minutes: 30
    name: E2E Simple
    uses: ./.github/workflows/e2e-base.yml
    with:
      testScript: 'tasks/e2e-simple.sh'
 
  e2e-installs:
    timeout-minutes: 30
    name: E2E Installs
    uses: ./.github/workflows/e2e-base.yml
    with:
      testScript: 'tasks/e2e-installs.sh'
 
  e2e-kitchensink:
    timeout-minutes: 30
    name: E2E Kitchensink
    uses: ./.github/workflows/e2e-base.yml
    with:
      testScript: 'tasks/e2e-kitchensink.sh'
 

What changed

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 5 jobs (7 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