Skip to content
Latchkey

Run tests workflow (uber-go/mock)

The Run tests workflow from uber-go/mock, 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: uber-go/mock.github/workflows/test.yamlLicense Apache-2.0View source

What it does

This is the Run tests workflow from the uber-go/mock repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Run tests
on:
  push:
    branches: ['*']
  pull_request:
    branches: ['*']

permissions:
  contents: read

jobs:
  go:
    strategy:
      matrix:
        go-version: [1.24.x, 1.25.x] # oldest version that can build go mock and official supported go versions
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}
    steps:

    - name: Checkout code
      uses: actions/checkout@v3

    - name: Install Go
      uses: actions/setup-go@v4
      with:
        go-version: ${{ matrix.go-version }}
        cache-dependency-path: '**/go.sum'

    - name: Vet and build
      run: |
        go vet ./...
        go build ./...

    - name: Install mockgen
      run: |
        go install go.uber.org/mock/mockgen

    - name: Run test script
      run: |
        ./ci/test.sh
        ./ci/check_panic_handling.sh

    - name: Run Go Tests
      run: |
        for i in $(find $PWD -name go.mod ! -path "$PWD/bazel/go.mod"); do
          pushd $(dirname $i)
          go test ./...
          popd
        done 

  bazel:
    strategy:
      matrix:
        os:
          - macos
          - ubuntu
    runs-on: ${{ matrix.os }}-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Bazel
        uses: bazel-contrib/setup-bazel@0.10.0
        with:
          # Avoid downloading Bazel every time.
          bazelisk-cache: true
          # Store build cache per workflow.
          disk-cache: ${{ github.workflow }}
          # Share repository cache between workflows.
          repository-cache: true

      - name: Run Bazel tests
        run: |
          cd bazel && bazel test //...

The same workflow, on Latchkey

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

name: Run tests
on:
  push:
    branches: ['*']
  pull_request:
    branches: ['*']
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  go:
    timeout-minutes: 30
    strategy:
      matrix:
        go-version: [1.24.x, 1.25.x] # oldest version that can build go mock and official supported go versions
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}
    steps:
 
    - name: Checkout code
      uses: actions/checkout@v3
 
    - name: Install Go
      uses: actions/setup-go@v4
      with:
        go-version: ${{ matrix.go-version }}
        cache-dependency-path: '**/go.sum'
 
    - name: Vet and build
      run: |
        go vet ./...
        go build ./...
 
    - name: Install mockgen
      run: |
        go install go.uber.org/mock/mockgen
 
    - name: Run test script
      run: |
        ./ci/test.sh
        ./ci/check_panic_handling.sh
 
    - name: Run Go Tests
      run: |
        for i in $(find $PWD -name go.mod ! -path "$PWD/bazel/go.mod"); do
          pushd $(dirname $i)
          go test ./...
          popd
        done 
 
  bazel:
    timeout-minutes: 30
    strategy:
      matrix:
        os:
          - macos
          - ubuntu
    runs-on: ${{ matrix.os }}-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
 
      - name: Setup Bazel
        uses: bazel-contrib/setup-bazel@0.10.0
        with:
          # Avoid downloading Bazel every time.
          bazelisk-cache: true
          # Store build cache per workflow.
          disk-cache: ${{ github.workflow }}
          # Share repository cache between workflows.
          repository-cache: true
 
      - name: Run Bazel tests
        run: |
          cd bazel && bazel test //...
 

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 2 jobs (4 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