Skip to content
Latchkey

Run Tests workflow (labstack/echo)

The Run Tests workflow from labstack/echo, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get 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: labstack/echo.github/workflows/echo.ymlLicense MITView source

What it does

This is the Run Tests workflow from the labstack/echo 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: Run Tests

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  workflow_dispatch:

permissions:
  contents: read # to fetch code (actions/checkout)

env:
  LATEST_GO_VERSION: "1.26"

  # https://github.com/actions/checkout/commit/df4cb1c069e1874edd31b4311f1884172cec0e10
  CHECKOUT_ACTION: &checkout_action actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6

  # https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16
  SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6

  # https://github.com/codecov/codecov-action/commit/fb8b3582c8e4def4969c97caa2f19720cb33a72f
  CODECOV_ACTION: &codecov_action codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        # Each major Go release is supported until there are two newer major releases. https://golang.org/doc/devel/release.html#policy
        # Echo tests with last four major releases (unless there are pressing vulnerabilities)
        # As we depend on `golang.org/x/` libraries which only support the last 2 Go releases, we could have situations when
        # we derive from the last four major releases promise.
        go: ["1.25", "1.26"]
    name: ${{ matrix.os }} @ Go ${{ matrix.go }}
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout Code
        uses: *checkout_action

      - name: Set up Go ${{ matrix.go }}
        uses: *setup_go_action
        with:
          go-version: ${{ matrix.go }}

      - name: Run Tests
        run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./...

      - name: Upload coverage to Codecov
        if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest'
        uses: *codecov_action
        with:
          token:
          fail_ci_if_error: false

  benchmark:
    needs: test
    name: Benchmark comparison
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code (Previous)
        uses: *checkout_action
        with:
          ref: ${{ github.base_ref }}
          path: previous

      - name: Checkout Code (New)
        uses: *checkout_action
        with:
          path: new

      - name: Set up Go
        uses: *setup_go_action
        with:
          go-version: ${{ env.LATEST_GO_VERSION }}

      - name: Install Dependencies
        run: go install golang.org/x/perf/cmd/benchstat@latest

      - name: Run Benchmark (Previous)
        run: |
          cd previous
          go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt

      - name: Run Benchmark (New)
        run: |
          cd new
          go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt

      - name: Run Benchstat
        run: |
          benchstat previous/benchmark.txt new/benchmark.txt

The same workflow, on Latchkey

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

name: Run Tests
 
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  workflow_dispatch:
 
permissions:
  contents: read # to fetch code (actions/checkout)
 
env:
  LATEST_GO_VERSION: "1.26"
 
  # https://github.com/actions/checkout/commit/df4cb1c069e1874edd31b4311f1884172cec0e10
  CHECKOUT_ACTION: &checkout_action actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
 
  # https://github.com/actions/setup-go/commit/924ae3a1cded613372ab5595356fb5720e22ba16
  SETUP_GO_ACTION: &setup_go_action actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
 
  # https://github.com/codecov/codecov-action/commit/fb8b3582c8e4def4969c97caa2f19720cb33a72f
  CODECOV_ACTION: &codecov_action codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  test:
    timeout-minutes: 30
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        # Each major Go release is supported until there are two newer major releases. https://golang.org/doc/devel/release.html#policy
        # Echo tests with last four major releases (unless there are pressing vulnerabilities)
        # As we depend on `golang.org/x/` libraries which only support the last 2 Go releases, we could have situations when
        # we derive from the last four major releases promise.
        go: ["1.25", "1.26"]
    name: ${{ matrix.os }} @ Go ${{ matrix.go }}
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout Code
        uses: *checkout_action
 
      - name: Set up Go ${{ matrix.go }}
        uses: *setup_go_action
        with:
          go-version: ${{ matrix.go }}
 
      - name: Run Tests
        run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
 
      - name: Upload coverage to Codecov
        if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest'
        uses: *codecov_action
        with:
          token:
          fail_ci_if_error: false
 
  benchmark:
    timeout-minutes: 30
    needs: test
    name: Benchmark comparison
    runs-on: latchkey-small
    steps:
      - name: Checkout Code (Previous)
        uses: *checkout_action
        with:
          ref: ${{ github.base_ref }}
          path: previous
 
      - name: Checkout Code (New)
        uses: *checkout_action
        with:
          path: new
 
      - name: Set up Go
        uses: *setup_go_action
        with:
          go-version: ${{ env.LATEST_GO_VERSION }}
 
      - name: Install Dependencies
        run: go install golang.org/x/perf/cmd/benchstat@latest
 
      - name: Run Benchmark (Previous)
        run: |
          cd previous
          go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
 
      - name: Run Benchmark (New)
        run: |
          cd new
          go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
 
      - name: Run Benchstat
        run: |
          benchstat previous/benchmark.txt new/benchmark.txt
 

What changed

This workflow runs 2 jobs (7 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.