GitHub Actions Workflow Template for Go
A complete, caching-enabled GitHub Actions workflow for Go. Drop it in .github/workflows/ci.yml and adjust.
This template builds and tests a Go project with dependency caching and sensible defaults. It uses setup-go module caching.
The workflow
.github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: true
- run: go vet ./...
- run: go build ./...
- run: go test -race ./...What it does
- Caches modules and build cache
- Runs vet, build, and test with the race detector
Run it cheaper
Change runs-on: ubuntu-latest to a Latchkey label to run this same workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.
Related guides
Go "checksum mismatch" / "SECURITY ERROR" in go.sum - Fix in CIFix Go "verifying module: checksum mismatch" and "SECURITY ERROR" in CI - a module hash no longer matches go.…
How to Speed Up GitHub Actions: 9 High-Impact TacticsMake GitHub Actions faster: caching, parallelization, test splitting, Docker layer caching, slimmer images, a…