GitHub Actions¶
Add gocov/gocov-action after your test step:
- run: go test ./... -covermode=atomic -coverprofile=coverage.out
- uses: gocov/gocov-action@v1
with:
files: coverage.out
token: ${{ secrets.GOCOV_TOKEN }}
Set GOCOV_TOKEN as an organization secret (or a repository secret) holding your workspace's
upload token.
That's the whole setup:
- No toolchain needed. The action downloads the pinned CLI binary for the runner and verifies its checksum, so the
same three lines work whatever language your tests are written in — only the
files:path changes. Languages & formats lists what each test tool writes. - Everything is auto-detected: commit, branch, repo and PR number, including the PR head SHA on
pull_requestruns. filestakes a comma-separated list and globs.
Options¶
| input | meaning |
|---|---|
files |
coverage file(s) to upload — comma-separated, globs allowed |
token |
the workspace upload token |
part |
names one slice of a matrix or multi-job build — see Parts |
server |
only when self-hosting: your instance's URL. On the hosted service the server is implicit |
Fork pull requests¶
Workflow runs for PRs opened from forks cannot read secrets.GOCOV_TOKEN — GitHub withholds secrets from fork code.
On a public repo whose workspace is connected through the gocov GitHub App that's fine: with no
token available the uploader switches to tokenless mode and the server verifies the workflow run itself through the
App. Fork contributors see the PR comment and check run without any setup;
Coverage in pull requests has the details and limits.
A tokenless upload never fails the build: if it is refused (App not installed, private repo, verification failed), the job logs the reason and exits 0.
Without the action¶
On a runner that already has Go, the CLI also runs straight from source — no marketplace dependency:
- run: go run github.com/gocov/gocov/cmd/gocov@latest upload coverage.out
env:
GOCOV_TOKEN: ${{ secrets.GOCOV_TOKEN }}
Or download the prebuilt binary like any other CI does.
Blocking merges on coverage¶
With the workspace connected, every upload sets a commit status and a check run on the PR. To make
the coverage gate block merges, require gocov or gocov coverage under
Settings → Branches → Require status checks to pass.