Skip to content
Latchkey

Go workflow (goccy/go-json)

The Go workflow from goccy/go-json, 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: goccy/go-json.github/workflows/go.ymlLicense MITView source

What it does

This is the Go workflow from the goccy/go-json 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: Go
on:
  push:
    branches:
      - master
  pull_request:
jobs:
  build:
    name: Build on limited environment
    runs-on: ubuntu-latest
    steps:
    - name: checkout
      uses: actions/checkout@v3
    - name: build
      run: docker compose run go-json

  test:
    name: Test
    strategy:
      matrix:
        os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
        go-version: [ "1.19", "1.20", "1.21" ]
    runs-on: ${{ matrix.os }}
    steps:
    - name: setup Go ${{ matrix.go-version }}
      uses: actions/setup-go@v3
      with:
        go-version: ${{ matrix.go-version }}
    - name: checkout
      uses: actions/checkout@v3
    - name: simple test
      run: go test -v ./... -count=1
    - name: test with GC pressure
      run: go test -v ./... -count=1
      env:
        GOGC: 1
    - name: test with race detector
      run: go test -v -race ./... -count=1

  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: setup Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
      - name: lint
        run: |
          make lint
  bench:
    name: Benchmark
    runs-on: ubuntu-latest
    steps:
      - name: setup Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
      - name: checkout ( feature )
        uses: actions/checkout@v3
      - name: run benchmark ( feature )
        run: cd benchmarks && go test -bench GoJson | tee $HOME/new.txt
      - name: install benchstat
        run: go install golang.org/x/perf/cmd/benchstat@latest
      - name: checkout ( master )
        uses: actions/checkout@v3
        with:
          ref: master
      - name: run benchmark ( master )
        run: cd benchmarks && go test -bench GoJson | tee $HOME/old.txt
      - name: compare benchmark results
        run: benchstat $HOME/old.txt $HOME/new.txt

  coverage:
    name: Coverage
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: setup Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
      - name: measure coverage
        run: make cover
      - uses: codecov/codecov-action@v4
        with:
          fail_ci_if_error: true
          verbose: true
          token: ${{ secrets.CODECOV_TOKEN }}

The same workflow, on Latchkey

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

name: Go
on:
  push:
    branches:
      - master
  pull_request:
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
    name: Build on limited environment
    runs-on: latchkey-small
    steps:
    - name: checkout
      uses: actions/checkout@v3
    - name: build
      run: docker compose run go-json
 
  test:
    timeout-minutes: 30
    name: Test
    strategy:
      matrix:
        os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
        go-version: [ "1.19", "1.20", "1.21" ]
    runs-on: ${{ matrix.os }}
    steps:
    - name: setup Go ${{ matrix.go-version }}
      uses: actions/setup-go@v3
      with:
        go-version: ${{ matrix.go-version }}
    - name: checkout
      uses: actions/checkout@v3
    - name: simple test
      run: go test -v ./... -count=1
    - name: test with GC pressure
      run: go test -v ./... -count=1
      env:
        GOGC: 1
    - name: test with race detector
      run: go test -v -race ./... -count=1
 
  lint:
    timeout-minutes: 30
    name: Lint
    runs-on: latchkey-small
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: setup Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
      - name: lint
        run: |
          make lint
  bench:
    timeout-minutes: 30
    name: Benchmark
    runs-on: latchkey-small
    steps:
      - name: setup Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
      - name: checkout ( feature )
        uses: actions/checkout@v3
      - name: run benchmark ( feature )
        run: cd benchmarks && go test -bench GoJson | tee $HOME/new.txt
      - name: install benchstat
        run: go install golang.org/x/perf/cmd/benchstat@latest
      - name: checkout ( master )
        uses: actions/checkout@v3
        with:
          ref: master
      - name: run benchmark ( master )
        run: cd benchmarks && go test -bench GoJson | tee $HOME/old.txt
      - name: compare benchmark results
        run: benchstat $HOME/old.txt $HOME/new.txt
 
  coverage:
    timeout-minutes: 30
    name: Coverage
    runs-on: latchkey-small
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: setup Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
      - name: measure coverage
        run: make cover
      - uses: codecov/codecov-action@v4
        with:
          fail_ci_if_error: true
          verbose: true
          token: ${{ secrets.CODECOV_TOKEN }}
 

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.

This workflow runs 5 jobs (13 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