Skip to content
Latchkey

json-to-go tests workflow (mholt/json-to-go)

The json-to-go tests workflow from mholt/json-to-go, explained and optimized by Latchkey.

D

CI health: D - needs work

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

Grade your own workflow free or run it on Latchkey →
Source: mholt/json-to-go.github/workflows/node-tests.ymlLicense MITView source

What it does

This is the json-to-go tests workflow from the mholt/json-to-go 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: json-to-go tests

on:  # yamllint disable-line rule:truthy
  workflow_call:
  workflow_dispatch:
  push:
    branches:
      - "master"
      - "main"
  pull_request:

jobs:
  run-tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x]

    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Run tests
        run: |
          node json-to-go.test.js

      - name: Run json-to-go using stdin
        shell: bash
        run: |
          set -eEuo pipefail
          got=$(node json-to-go.js < tests/double-nested-objects.json)
          exp=$(cat tests/double-nested-objects.go)
          echo "got: '${got}'"
          [[ "${got}" == "${exp}" ]]

      - name: Run json-to-go with a file
        shell: bash
        run: |
          set -eEuo pipefail
          got=$(node json-to-go.js tests/double-nested-objects.json)
          exp=$(cat tests/double-nested-objects.go)
          echo "got: '${got}'"
          [[ "${got}" == "${exp}" ]]

      - name: Check correct error handling using stdin
        shell: bash
        run: |
          ! node json-to-go.js <<< "error"

      - name: Check correct error handling with a file
        shell: bash
        run: |
          ! node json-to-go.js <(echo "error")

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: json-to-go tests
 
on:  # yamllint disable-line rule:truthy
  workflow_call:
  workflow_dispatch:
  push:
    branches:
      - "master"
      - "main"
  pull_request:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  run-tests:
    timeout-minutes: 30
    runs-on: latchkey-small
    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x]
 
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          cache: 'npm'
          node-version: ${{ matrix.node-version }}
 
      - name: Run tests
        run: |
          node json-to-go.test.js
 
      - name: Run json-to-go using stdin
        shell: bash
        run: |
          set -eEuo pipefail
          got=$(node json-to-go.js < tests/double-nested-objects.json)
          exp=$(cat tests/double-nested-objects.go)
          echo "got: '${got}'"
          [[ "${got}" == "${exp}" ]]
 
      - name: Run json-to-go with a file
        shell: bash
        run: |
          set -eEuo pipefail
          got=$(node json-to-go.js tests/double-nested-objects.json)
          exp=$(cat tests/double-nested-objects.go)
          echo "got: '${got}'"
          [[ "${got}" == "${exp}" ]]
 
      - name: Check correct error handling using stdin
        shell: bash
        run: |
          ! node json-to-go.js <<< "error"
 
      - name: Check correct error handling with a file
        shell: bash
        run: |
          ! node json-to-go.js <(echo "error")
 

What changed

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.

Actions used in this workflow