Skip to content

CLI reference

gocov upload [flags] <coverage file>...
gocov report [flags]
gocov mcp [flags]
gocov version

The CLI uploads one coverage report per invocation, auto-detecting everything it can: the format from the file's content, and repo, commit, branch and PR id from Bitbucket Pipelines, GitHub Actions, GitLab CI or CircleCI environment variables, falling back to git.

Several files

A step that leaves more than one coverage file hands them all to one invocation, and they become one report: a line any of the files covers is covered.

gocov upload cover/unit.out cover/integration.out

Uploaded one invocation each instead, they would land in the same part, where each upload replaces the one before it and only the last file would count. The files of one invocation share a format; reports of different formats are different parts — see Several languages in one repo. The whole request may be 64 MB and carry 100 files.

With several Go profiles that are not all of the module in go.mod — one per module of a monorepo — the CLI sends no path prefix and says so; the server then matches their paths by their endings. Give each module its own part to keep the match exact.

Installing

Flags

flag default meaning
-token $GOCOV_TOKEN the workspace/repo upload token. Optional when the CI job can mint an OIDC identity token, or in a GitHub Actions pull_request run — see without a token
-server $GOCOV_SERVER, else the hosted service the gocov instance to upload to — only needed when self-hosting
-repo auto-detect repo slug, workspace/repo
-commit auto-detect commit SHA. The one value that has no fallback: if detection fails, the upload asks for it
-branch auto-detect branch name
-pr auto-detect pull request id; enables diff coverage
-format detect from content go, lcov, jacoco, cobertura, clover, simplecov, opencover or xccov
-path-prefix from go.mod for Go, the checkout for OpenCover and xccov prefix mapping profile paths to repo paths, e.g. the Go module path — see below
-part $GOCOV_PART, else default names this slice of the commit's coverage when several jobs upload — see Parts
-ignore $GOCOV_IGNORE, else none leave matching files out of the report, e.g. cmd/preview/**; repeatable or comma-separated — see Ignoring files
-fail-on-gate off exit with status 3 when the server reports a failed coverage gate, and 4 when an upload sent without a token does not land — see exit code

Environment variables

variable equivalent flag
GOCOV_TOKEN -token
GOCOV_SERVER -server
GOCOV_PART -part
GOCOV_IGNORE -ignore

GOCOV_PART is handy for matrix jobs that already expose the variant in the environment. GOCOV_IGNORE takes several patterns separated by commas or newlines. Flags win over the environment.

Reading a report

gocov report prints a commit's report back: the totals and, for a pull request, the changed lines no test ran — what you, or a coding agent working on the change, need in order to add the missing tests.

$ gocov report
github/acme/widgets @ 7aa8f01 (feature, PR 247)
coverage: 88.0% (+0.4% vs c54dc2c), 2 parts
diff coverage: 82.6% (19/23 changed lines)
uncovered changed lines:
  cmd/gocov/oidc.go: 49-50, 57-58
report: https://app.gocov.dev/uploads/1114?parts=merged

It finds the forge, repo and commit the way upload does — the CI environment, else git (the origin remote and HEAD) — so run it after the commit's CI has uploaded. In a pull request's CI it finds the PR too, and reads the commit as that PR's build saw it: the PR's diff coverage and gate verdict, even when the default branch built the same commit and keeps it. A public report needs no credential. A private repo is read with the credential its upload uses, found in the same order: -token/$GOCOV_TOKEN, then in CI the forge's OIDC token. A coding agent that runs in the repo's CI therefore reads the report with nothing more to set up. Anywhere else, give it the token. Coding agents has the loop and the instructions to give an agent.

flag default meaning
-forge auto-detect github, gitlab or bitbucket; needed for a self-managed GitLab
-repo auto-detect repo slug, workspace/repo
-commit auto-detect commit SHA
-branch none report the newest commit on this branch instead
-pr auto-detect pull request id: read the commit as that PR's build saw it; ignored with -branch
-token $GOCOV_TOKEN the repo's or its workspace's upload token, to read a private repo
-json off print the API's JSON answer as is
-server $GOCOV_SERVER, else the hosted service the gocov instance to read from

Serving reports over MCP

gocov mcp serves the same report to an MCP client (an editor or a desktop agent) over stdio, for clients that cannot run gocov report themselves. It offers one tool, get_report, whose optional arguments forge, repo, commit, branch, pr_id and format (text or json) mirror the flags above. Whatever is left out is detected in the directory the client starts the server in. It takes -server and -token like gocov report, and finds a credential the same way. Coding agents shows how to register it. A client that takes a URL instead of a command uses the server's own /mcp, which signs its user in through the browser instead of taking a token.

Uploading without a token

When no -token/$GOCOV_TOKEN is set, the CLI tries two secret-free paths in order before giving up:

  1. OIDC. If the CI job can provide an OIDC identity token — GitHub Actions with permissions: id-token: write, Bitbucket Pipelines with oidc.audiences, or GitLab CI with an id_tokens entry named GOCOV_ID_TOKEN — the CLI sends it in place of the token, scoped to the gocov server's audience. The server verifies the forge's signature and the repository the token names, so the upload is fully verified — not marked unverified. The repository's workspace must be connected to its forge with a connection that still works; otherwise the upload is refused with oidc_not_connected and the reason. This is the recommended setup for a repo's own push and same-repo PR builds; see GitHub Actions, Bitbucket Pipelines and GitLab CI.
  2. Tokenless fork-PR (below), for the fork pull request that has neither a secret nor an id-token.

An explicit token always wins, so existing setups are untouched. A rejected OIDC upload does not fail the build: the CLI prints one line with the server's reason (gocov: OIDC upload rejected — …) and exits 0 — or 4 under -fail-on-gate, where the step is the gate.

Tokenless fork-PR uploads

In a GitHub Actions pull_request workflow with no token set — the fork-PR situation, where secrets are withheld — the CLI uploads tokenless: it sends the workflow run's identity (run id, attempt, PR number, head SHA, fork) and the server verifies the run with GitHub through the repo's App installation. Works on public repos with the gocov GitHub App connected; anywhere else a missing token stays an error.

In tokenless mode an upload that is refused or fails does not fail the build: the CLI prints one line with the server's reason (gocov: tokenless upload rejected — …) and exits 0 — or 4 under -fail-on-gate, where the step is the gate.

-path-prefix

Diff coverage matches the paths in the profile against the paths in the PR's diff. When the profile records paths under a prefix the repo doesn't have — a Go module path, a CI checkout directory — set -path-prefix to that prefix so the two line up. For Go profiles the CLI fills it from go.mod automatically; for OpenCover and xccov reports, which record every file by its absolute path, it fills in the git checkout directory when the report's paths lie under it. JaCoCo's package-qualified paths are matched by suffix and usually need nothing. Symptoms and details: Why coverage changed.

Output and exit code

A successful upload prints the totals the server computed — coverage, delta, how many files the ignore patterns dropped (when any did), diff coverage, and the status of each forge surface (build status, pr comment, code insights: posted, skipped with the reason, or queued when another upload of the same commit was pushing and carries this one — see parts) plus the gate verdict:

uploaded: 82.0% (1230/1500 statements), delta +0.4%
ignored: 3 files
diff coverage: 91.7% (22/24 changed lines)
build status: posted
pr comment: posted
gate: passed

When the commit's coverage arrives in parts, the totals are the commit's merged report, not the one file this step uploaded. The output names the part it uploaded and the parts the figure was merged from so far, so the first part to land doesn't read as the commit's final coverage:

uploaded part: web
commit coverage: 95.0% (1158/1219 statements), delta +10.3%
merged from 1 part so far: web

When the last part lands, its step prints the complete figure (merged from 2 parts so far: go, web). Uploads without a -part print the single uploaded: line above.

A part the repository carries forward and this commit did not upload counts among the merged parts, and a further line names the commit each one came from:

uploaded part: web
commit coverage: 81.7% (49/60 statements)
merged from 2 parts so far: e2e, web
carried forward: e2e from c4a7e2e

When the server built the commit's merged report with a caveat — two parts that disagree on a PR's changed lines, whose diff coverage is then merged as a safe lower bound — a warning: line under the totals says so. A warning never fails the step.

gocov upload exits with one of five codes:

exit code meaning
0 the upload landed — or, without -fail-on-gate, it was refused or failed while uploading without a token, which never fails the build
1 any other error, and the upload did not land: the server could not be reached or refused it, the token was rejected, the file is not coverage the CLI can read, the command line is incomplete
2 a flag the CLI does not know or cannot read
3 only with -fail-on-gate: the upload landed and the commit failed its coverage gate
4 only with -fail-on-gate: an upload sent without a token was refused or failed, so the gate was not checked

Without -fail-on-gate a failed gate is only reported — gate: failed: … in the output — and the exit code stays 0. With it, the CLI also prints gocov: coverage gate failed: … to standard error and exits 3, which is how a pipeline step turns the gate into a hard failure even without forge-side merge blocking.

With it, an upload sent without a token that does not land also prints gocov: coverage gate not checked: … and exits 4, so an unchecked gate never reads as a passed one. It is not 1, so a pipeline can still let it pass where a refusal is expected, as on a fork's pull request.

A step that should never fail over coverage plumbing, but must stop on the gate, lets 1 and 4 pass and keeps 3:

status=0
gocov upload -fail-on-gate coverage.out || status=$?
if [ "$status" -eq 3 ]; then exit 3; fi   # the gate failed: stop here
# otherwise carry on, whether the upload landed or not

gocov report and gocov mcp use only 0 and 1.

The raw HTTP endpoint underneath, for anything the CLI doesn't cover, is documented in API & badge.