Skip to content
Latchkey

Build and Coverage workflow (nutsdb/nutsdb)

The Build and Coverage workflow from nutsdb/nutsdb, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get run de-duplication, 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: nutsdb/nutsdb.github/workflows/go.ymlLicense Apache-2.0View source

What it does

This is the Build and Coverage workflow from the nutsdb/nutsdb 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)
# This workflow will build a golang project and generate coverage
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Build and Coverage

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:

  build-and-coverage:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
    - uses: actions/checkout@v3

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.24.x'

    - name: Cache Go modules
      uses: actions/cache@v3
      with:
        path: |
          ~/.cache/go-build
          ~/go/pkg/mod
        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-

    - name: Clean test directories
      run: |
        sudo rm -rf /tmp/nutsdb* || true
        sudo rm -rf /tmp/test-hintfile* || true

    - name: Build project
      run: go build -v ./...

    - name: Run coverage tests
      run: |
        # Set longer timeout for coverage collection
        timeout 25m go test -race -timeout 20m -coverprofile=_coverage.out -covermode=atomic ./...
        cat _coverage.out | grep -v github.com/nutsdb/nutsdb/examples > coverage.out

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v5
      with:
        files: ./coverage.out
        flags: unittests
        name: codecov-umbrella
        fail_ci_if_error: true
        gcov_ignore: examples
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

The same workflow, on Latchkey

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

# This workflow will build a golang project and generate coverage
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
 
name: Build and Coverage
 
on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
 
  build-and-coverage:
    runs-on: latchkey-small
    timeout-minutes: 30
    steps:
    - uses: actions/checkout@v3
 
    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.24.x'
 
    - name: Cache Go modules
      uses: actions/cache@v3
      with:
        path: |
          ~/.cache/go-build
          ~/go/pkg/mod
        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-
 
    - name: Clean test directories
      run: |
        sudo rm -rf /tmp/nutsdb* || true
        sudo rm -rf /tmp/test-hintfile* || true
 
    - name: Build project
      run: go build -v ./...
 
    - name: Run coverage tests
      run: |
        # Set longer timeout for coverage collection
        timeout 25m go test -race -timeout 20m -coverprofile=_coverage.out -covermode=atomic ./...
        cat _coverage.out | grep -v github.com/nutsdb/nutsdb/examples > coverage.out
 
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v5
      with:
        files: ./coverage.out
        flags: unittests
        name: codecov-umbrella
        fail_ci_if_error: true
        gcov_ignore: examples
      env:
        CODECOV_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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow