Test examples on trigger using node 14.x workflow (jaredpalmer/razzle)
The Test examples on trigger using node 14.x workflow from jaredpalmer/razzle, 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 Test examples on trigger using node 14.x workflow from the jaredpalmer/razzle 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: Test examples on trigger using node 14.x
on:
workflow_dispatch:
inputs:
npm_tag:
description: 'The npm tag for create razzle app'
default: 'development'
jest_filter:
description: 'The filter for jest tests'
default: 'simple'
package_manager:
description: 'The package manager to use, yalc with yarn default'
default: 'yalc'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [14.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
webpack: ["webpack@4.46.0 html-webpack-plugin@4.5.2" , "webpack@5.24.0 html-webpack-plugin@5.2.0"]
name: Test on node ${{ matrix.node-version }} and ${{ matrix.os }} with ${{ matrix.webpack }}
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H:%M:%S')"
- name: Log date
run: echo "${{ steps.date.outputs.date }}"
- name: Set default run status
run: echo "::set-output name=last_run_status::default" > last_run_status
- name: Restore last run status
id: last_run
uses: actions/cache@v2
with:
path: |
last_run_status
key: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ steps.date.outputs.date }}
restore-keys: |
${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-
- name: Set last run status
id: last_run_status
run: cat last_run_status
- name: Checkout ref
uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_dispatch.ref }}
- name: Use Node.js ${{ matrix.node-version }}
if: steps.last_run_status.outputs.last_run_status != 'success'
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install yalc globally
if: steps.last_run_status.outputs.last_run_status != 'success'
run: npm install -g yalc
- name: Install elm globally
if: steps.last_run_status.outputs.last_run_status != 'success'
run: yarn global add elm
- name: Restore lerna
if: steps.last_run_status.outputs.last_run_status != 'success'
id: cache
uses: actions/cache@v2
with:
path: |
node_modules
*/*/node_modules
key: ${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ hashFiles('**/yarn.lock') }}
- name: Install and bootstrap packages
if: steps.cache.outputs.cache-hit != 'true' && steps.last_run_status.outputs.last_run_status != 'success'
run: yarn install --frozen-lockfile --ignore-engines --network-timeout 1000000
- name: Install ${{ matrix.webpack }}
if: steps.cache.outputs.cache-hit != 'true' && steps.last_run_status.outputs.last_run_status != 'success'
run: yarn add -WD ${{ matrix.webpack }} --ignore-engines --network-timeout 1000000
- name: Run tests
id: test_run
if: steps.last_run_status.outputs.last_run_status != 'success'
run: yarn test:examples -t ${{ github.event.inputs.jest_filter }} --runInBand
env:
WEBPACK_DEPS: "${{ matrix.webpack }}"
NPM_TAG: "${{ github.event.inputs.npm_tag }}"
PACKAGE_MANAGER: "${{ github.event.inputs.package_manager }}"
WARNINGS_ERRORS_DISABLE: true
- name: Upload test artifacts
uses: actions/upload-artifact@v2
if: ${{ always() && steps.last_run_status.outputs.last_run_status != 'success' }}
with:
name: ${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ github.event.inputs.npm_tag }}-${{ github.event.inputs.jest_filter }}-${{ github.event.inputs.package_manager }}
path: test-artifacts/
- name: Save run status
if: steps.last_run_status.outputs.last_run_status != 'success'
run: echo "::set-output name=last_run_status::${{ steps.test_run.outcome }}" > last_run_status
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: Test examples on trigger using node 14.x on: workflow_dispatch: inputs: npm_tag: description: 'The npm tag for create razzle app' default: 'development' jest_filter: description: 'The filter for jest tests' default: 'simple' package_manager: description: 'The package manager to use, yalc with yarn default' default: 'yalc' jobs: build: timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: node-version: [14.x] os: [ubuntu-latest, windows-latest, macOS-latest] webpack: ["webpack@4.46.0 html-webpack-plugin@4.5.2" , "webpack@5.24.0 html-webpack-plugin@5.2.0"] name: Test on node ${{ matrix.node-version }} and ${{ matrix.os }} with ${{ matrix.webpack }} steps: - name: Get current date id: date run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H:%M:%S')" - name: Log date run: echo "${{ steps.date.outputs.date }}" - name: Set default run status run: echo "::set-output name=last_run_status::default" > last_run_status - name: Restore last run status id: last_run uses: actions/cache@v2 with: path: | last_run_status key: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ steps.date.outputs.date }} restore-keys: | ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}- - name: Set last run status id: last_run_status run: cat last_run_status - name: Checkout ref uses: actions/checkout@v2 with: ref: ${{ github.event.workflow_dispatch.ref }} - name: Use Node.js ${{ matrix.node-version }} if: steps.last_run_status.outputs.last_run_status != 'success' uses: actions/setup-node@v1 with: cache: 'npm' node-version: ${{ matrix.node-version }} - name: Install yalc globally if: steps.last_run_status.outputs.last_run_status != 'success' run: npm install -g yalc - name: Install elm globally if: steps.last_run_status.outputs.last_run_status != 'success' run: yarn global add elm - name: Restore lerna if: steps.last_run_status.outputs.last_run_status != 'success' id: cache uses: actions/cache@v2 with: path: | node_modules */*/node_modules key: ${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ hashFiles('**/yarn.lock') }} - name: Install and bootstrap packages if: steps.cache.outputs.cache-hit != 'true' && steps.last_run_status.outputs.last_run_status != 'success' run: yarn install --frozen-lockfile --ignore-engines --network-timeout 1000000 - name: Install ${{ matrix.webpack }} if: steps.cache.outputs.cache-hit != 'true' && steps.last_run_status.outputs.last_run_status != 'success' run: yarn add -WD ${{ matrix.webpack }} --ignore-engines --network-timeout 1000000 - name: Run tests id: test_run if: steps.last_run_status.outputs.last_run_status != 'success' run: yarn test:examples -t ${{ github.event.inputs.jest_filter }} --runInBand env: WEBPACK_DEPS: "${{ matrix.webpack }}" NPM_TAG: "${{ github.event.inputs.npm_tag }}" PACKAGE_MANAGER: "${{ github.event.inputs.package_manager }}" WARNINGS_ERRORS_DISABLE: true - name: Upload test artifacts uses: actions/upload-artifact@v2 if: ${{ always() && steps.last_run_status.outputs.last_run_status != 'success' }} with: name: ${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.webpack }}-${{ github.event.inputs.npm_tag }}-${{ github.event.inputs.jest_filter }}-${{ github.event.inputs.package_manager }} path: test-artifacts/ - name: Save run status if: steps.last_run_status.outputs.last_run_status != 'success' run: echo "::set-output name=last_run_status::${{ steps.test_run.outcome }}" > last_run_status
What changed
- 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.
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 (6 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.