Skip to content
Latchkey

Package usage workflow (janl/mustache.js)

The Package usage workflow from janl/mustache.js, explained and optimized by Latchkey.

F

CI health: F - at risk

Point runs-on at Latchkey and get caching, 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: janl/mustache.js.github/workflows/usage.ymlLicense MITView source

What it does

This is the Package usage workflow from the janl/mustache.js 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: Package usage

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14.x
      - name: npm install and build
        run: |
          npm install
          npm run build
      - name: Store build-output for later
        uses: actions/upload-artifact@v2
        with:
          name: build-output
          path: |
            mustache.js
            mustache.mjs

  package:
    runs-on: ubuntu-latest

    needs: build
    steps:
      - uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14.x
      - name: Get build-output from build step
        uses: actions/download-artifact@v2
        with:
          name: build-output
      - name: Create package tarball
        run: |
          export ARCHIVE_FILENAME=$(npm pack | tail -n 1)
          mv $ARCHIVE_FILENAME mustache.tgz
      - name: Store package tarball for later
        uses: actions/upload-artifact@v2
        with:
          name: package-output
          path: mustache.tgz

  common-js-usage:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x, 15.x]

    needs: package
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Get package tarball from package step
        uses: actions/download-artifact@v2
        with:
          name: package-output
      - name: Package, install and test
        run: |
          export UNPACK_DESTINATION=$(mktemp -d)
          mv mustache.tgz $UNPACK_DESTINATION
          cp test/module-systems/commonjs-test.js $UNPACK_DESTINATION
          cd $UNPACK_DESTINATION
          npm install mustache.tgz
          node commonjs-test.js

  esm-usage:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x, 15.x]

    needs: package
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Get package tarball from package step
        uses: actions/download-artifact@v2
        with:
          name: package-output
      - name: Package, install and test
        run: |
          export UNPACK_DESTINATION=$(mktemp -d)
          mv mustache.tgz $UNPACK_DESTINATION
          cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION
          cp test/module-systems/esm-test-exports.mjs $UNPACK_DESTINATION
          cd $UNPACK_DESTINATION
          npm install mustache.tgz
          node esm-test.mjs
          node esm-test-exports.mjs

  browser-usage:
    runs-on: ubuntu-latest

    needs: build
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - name: Get build-output from build step
        uses: actions/download-artifact@v2
        with:
          name: build-output
      - name: Install and test
        run: |
          npm ci
          npx mocha test/module-systems/browser-test.js

  deno-usage:
    runs-on: ubuntu-latest

    needs: build
    steps:
      - uses: actions/checkout@v1
      - uses: denolib/setup-deno@master
        with:
          deno-version: 'v1.0.0'
      - name: Get build-output from build step
        uses: actions/download-artifact@v2
        with:
          name: build-output
      - run: deno --version
      - run: deno test --allow-net=deno.land test/module-systems/deno-test.ts

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: Package usage
 
on: [push, pull_request]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    steps:
      - uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          cache: 'npm'
          node-version: 14.x
      - name: npm install and build
        run: |
          npm install
          npm run build
      - name: Store build-output for later
        uses: actions/upload-artifact@v2
        with:
          name: build-output
          path: |
            mustache.js
            mustache.mjs
 
  package:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    needs: build
    steps:
      - uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          cache: 'npm'
          node-version: 14.x
      - name: Get build-output from build step
        uses: actions/download-artifact@v2
        with:
          name: build-output
      - name: Create package tarball
        run: |
          export ARCHIVE_FILENAME=$(npm pack | tail -n 1)
          mv $ARCHIVE_FILENAME mustache.tgz
      - name: Store package tarball for later
        uses: actions/upload-artifact@v2
        with:
          name: package-output
          path: mustache.tgz
 
  common-js-usage:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x, 15.x]
 
    needs: package
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          cache: 'npm'
          node-version: ${{ matrix.node-version }}
      - name: Get package tarball from package step
        uses: actions/download-artifact@v2
        with:
          name: package-output
      - name: Package, install and test
        run: |
          export UNPACK_DESTINATION=$(mktemp -d)
          mv mustache.tgz $UNPACK_DESTINATION
          cp test/module-systems/commonjs-test.js $UNPACK_DESTINATION
          cd $UNPACK_DESTINATION
          npm install mustache.tgz
          node commonjs-test.js
 
  esm-usage:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    strategy:
      matrix:
        node-version: [14.x, 15.x]
 
    needs: package
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          cache: 'npm'
          node-version: ${{ matrix.node-version }}
      - name: Get package tarball from package step
        uses: actions/download-artifact@v2
        with:
          name: package-output
      - name: Package, install and test
        run: |
          export UNPACK_DESTINATION=$(mktemp -d)
          mv mustache.tgz $UNPACK_DESTINATION
          cp test/module-systems/esm-test.mjs $UNPACK_DESTINATION
          cp test/module-systems/esm-test-exports.mjs $UNPACK_DESTINATION
          cd $UNPACK_DESTINATION
          npm install mustache.tgz
          node esm-test.mjs
          node esm-test-exports.mjs
 
  browser-usage:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    needs: build
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
          cache: 'npm'
          node-version: 12.x
      - name: Get build-output from build step
        uses: actions/download-artifact@v2
        with:
          name: build-output
      - name: Install and test
        run: |
          npm ci
          npx mocha test/module-systems/browser-test.js
 
  deno-usage:
    timeout-minutes: 30
    runs-on: latchkey-small
 
    needs: build
    steps:
      - uses: actions/checkout@v1
      - uses: denolib/setup-deno@master
        with:
          deno-version: 'v1.0.0'
      - name: Get build-output from build step
        uses: actions/download-artifact@v2
        with:
          name: build-output
      - run: deno --version
      - run: deno test --allow-net=deno.land test/module-systems/deno-test.ts
 

What changed

1 third-party action is referenced by a movable tag. Pin it 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 6 jobs (10 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