22 Nov, 2026Aishwarya Palta
Go Builds and Tests on Monk CI: A Caching Guide
Run Go builds and tests on Monk CI with a practical GitHub Actions workflow. Reuse modules and compilation while choosing when tests must execute again.
Run Go builds and tests on Monk CI using setup-go caching, while keeping test execution explicit. Reusing downloaded modules and compiled packages can avoid repeated work; reusing a successful test result answers a different question.
Our developer preference is to separate those decisions, especially when tests depend on services outside the repository.
What does the workflow need?
Complete the Monk CI setup, then use a repository with a root-level go.mod, committed go.sum and public dependencies. This example assumes tests need no external services.
Save this as .github/workflows/go-ci.yml:
name: Go CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
check:
runs-on: monkci-ubuntu-24.04-4
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- run: go mod download
- run: go build ./...
- run: go test -count=1 ./...Adjust the branch and timeout to your project. Keep required race checks, build tags and integration suites when adapting the example.
The setup-go documentation explains version selection and caching. Here, go.sum explicitly supplies the dependency-file hash; go-version-file reads the toolchain requirement from go.mod. Follow your organization’s action-pinning policy and runner compatibility requirements.
Which caches are reused?
- Module cache: downloaded dependencies.
- Build cache: reusable compilation work.
- Test-result cache: successful results that may avoid executing tests again.
Use go env GOMODCACHE GOCACHE to inspect the first two locations. Monk CI’s cache backend supports the standard action configuration.
Why use -count=1?
go test -count=1 ./... disables test-result reuse while retaining compilation caching. Go documents this behavior in its test command reference.
That makes execution explicit when an external database or service can change independently of source files. It does not create those services or eliminate flaky behavior.
Compare the same commit with cold and warm caches, recording download, build and test durations separately. Keep test flags identical across runners and consult the runner-size guide before increasing compute.
Takeaway: cache reusable work, and decide deliberately whether a previous test result is sufficient evidence for this run.