Upload test coverage to gocov from CircleCI — Go, JavaScript/TypeScript, Java/Kotlin, Python, PHP, Ruby, .NET, Swift and more, with the format detected from the file: diff coverage on pull requests, commit statuses, a coverage gate and a README badge, on the hosted service or your own server.
Full documentation: docs.gocov.dev — in particular CircleCI, the coverage gate and parts for split builds.
version: 2.1
orbs:
gocov: gocov/gocov@1
jobs:
test:
docker:
- image: cimg/go:1.27
steps:
- checkout
- run: go test ./... -covermode=atomic -coverprofile=coverage.out
- gocov/upload:
files: coverage.out
workflows:
test:
jobs:
- testThen add GOCOV_TOKEN under Project Settings → Environment Variables,
holding your workspace's upload token from
app.gocov.dev. To share it across projects, put it
in a context instead and name the context on the job.
Only the test command and files change for other languages —
Languages & formats lists what each
test tool writes.
The step downloads the pinned gocov CLI release for the executor and
verifies its sha256 against the release's checksums.txt, so there is no
toolchain to install. Commit, branch, repository and pull request are
detected by the CLI from CircleCI's own variables, and the upload's page on
gocov links back to the CircleCI job it came from.
gocov's orb is not one of CircleCI's certified orbs, and CircleCI refuses
any other orb until an organization admin switches on Allow uncertified
public orbs under Organization Settings → Security. Every
organization that uses the orb has to do this once. Where that is not an
option, the plain run step in
CircleCI does the same job without an
orb.
| Parameter | Default | Usage |
|---|---|---|
files |
coverage.out |
Coverage file(s) to upload, comma-separated, shell globs allowed (coverage.out, cover/*.out). See several files. |
token |
GOCOV_TOKEN |
Name of the environment variable that holds the upload token: the variable's name, never the token itself. |
part |
Label for this upload when a commit's coverage is split across jobs; the server merges the parts for the same commit. See parts. | |
ignore |
Glob patterns for files to leave out of the report, comma-separated (cmd/preview/**,*_mock.go). See ignoring files. |
|
server |
gocov server URL, when self-hosting. Left empty, the upload goes to GOCOV_SERVER where the job has that variable, and to https://app.gocov.dev otherwise. |
|
fail_on_error |
true |
Fail the step when installing the CLI or uploading fails. Set false to only warn. See when the step fails. |
fail_on_gate |
false |
Fail the step, with exit status 3, when the commit fails its coverage gate. See failing the job on the gate. |
version |
v0.42.0 |
gocov CLI release to install. The default is the one this orb release was tested against. A CLI older than v0.42.0 uploads several files one at a time, and only the last one counts. |
The token is never a parameter's value: the step reads it from the variable
token names, so it never appears in the pipeline's configuration. part,
ignore and server can also be left
to the GOCOV_PART, GOCOV_IGNORE and GOCOV_SERVER environment
variables of the job or a context; a parameter that is set wins.
Linux and macOS executors are supported, on amd64 and arm64. The step needs
a POSIX sh, curl or wget, and sha256sum or shasum; CircleCI's
cimg/* images have them, and so does plain Alpine. ** in files matches across
directories where the step runs under bash 4 or newer, as it does on
CircleCI's Linux images. Windows executors are not supported; use the
plain download recipe there.
The pull request is what turns on diff coverage and the
comment on the pull request. On
GitHub and Bitbucket Cloud projects CircleCI names it as the pipeline
starts, so a push made before the pull request was opened uploads as a
branch build; CircleCI's Only build pull requests setting closes that
gap. GitLab projects get no variable that names the merge request, and one
inside a subgroup cannot be named from CircleCI's variables at all: the
orb passes the CLI no repository, so upload from such a project with the
plain run step and -repo. CircleCI
has the details.
CircleCI builds pull requests from forks only when the project's Build
forked pull requests setting is on, and keeps the project's secrets out
of those builds. They have no upload token, and
on CircleCI there is no other way to authenticate an upload. So when the
token is missing and the build is of a fork's pull request, the step prints
why, uploads nothing and passes, before anything is downloaded: a
contributor's build never breaks over coverage, whatever fail_on_error
and fail_on_gate say. The pull request gets its coverage when a
maintainer's push builds it from a branch of the project itself.
Leave Pass secrets to builds from forked pull requests off: it would hand the token, and every other secret of the project, to code from any fork. A project that turns it on does get the upload on fork builds too.
fail_on_error is on by default, as an honest failure is worth seeing:
- A missing token on a build of the project's own (a branch, a tag, a pull request from the same repository) is a setup mistake, and fails the step.
- So does a CLI that cannot be downloaded or does not match its checksum
(it is then never run),
filesmatching nothing, and an upload the server refuses.
With fail_on_error: false each of these prints a warning and the step
passes, for pipelines that must never stop over coverage plumbing. Neither
setting applies to a fork's build without a token, which always passes, or
to a failed gate under fail_on_gate, which always fails.
A commit that fails its
coverage gate is reported as
failing, and the upload step still passes. With fail_on_gate the step
fails too, so the gate stops the pipeline with no status check to set up on
the forge:
- gocov/upload:
files: coverage.out
fail_on_error: false # a failed upload only warns
fail_on_gate: true # a failed gate fails the jobThe step then exits with status 3, after the gate: line that says why,
where an upload that failed exits 1. Several files are one upload, with
one verdict. In a split build the gate is judged
as each part arrives and can fail until the last one lands, so set
fail_on_gate only on a job that uploads after the others.
The files files matches are sent as one upload, and the server merges
them into one report: a line any of them covers is covered. That suits a
test run that writes one profile per package or per test suite:
- gocov/upload:
files: cover/*.outThe files of one upload must share a coverage format; the CLI refuses a
mix. Upload reports of different formats in separate steps, each with its
own part, as in split builds.
A gocov CLI older than v0.42.0 takes one file per upload: the step then uploads the files one by one, each replacing the one before, so only the last one counts, and it prints a warning saying so.
When a commit's coverage comes from more than one job, give each upload its own part and gocov merges them instead of letting the last one win:
jobs:
backend:
docker:
- image: cimg/go:1.27
steps:
- checkout
- run: go test ./... -covermode=atomic -coverprofile=coverage.out
- gocov/upload:
files: coverage.out
part: backend
frontend:
docker:
- image: cimg/node:lts
steps:
- checkout
- run: npm ci && npm test -- --coverage
- gocov/upload:
files: coverage/lcov.info
part: frontendA part whose job runs only on some changes is missing from the commits that skip it, and their total leaves it out. List that part under Carried parts in the repository's gocov settings, and those commits take it from the last upload that measured it instead — see Carrying a part forward.
- gocov/upload:
files: coverage.out
server: https://gocov.example.comOr leave server out and set GOCOV_SERVER beside the token, in the
project's settings or in the context. The token is your instance's; token
names another variable when it is not called GOCOV_TOKEN:
- gocov/upload:
files: coverage.out
token: MY_GOCOV_TOKENgocov/gocov@1 follows the newest 1.x release; @1.0.0 pins one. Each
release of the orb installs one gocov CLI release (the version default);
CHANGELOG.md says which.
The orb is kept unpacked under src/, as CircleCI's orb tooling expects:
@orb.yml, one file per command and per usage example, and the shell the
command runs in src/scripts/upload.sh, included into the command when the
orb is packed.
bash test/upload_test.sh # the script's logic, under sh and bash; no network
bash test/e2e.sh # the pinned CLI, downloaded, against a fake server
./scripts/check-pins.sh # every mention of the pinned CLI agrees
circleci orb pack src > orb.yml && circleci orb validate orb.ymltest/e2e.sh says how to run it in a Docker image, and against a CLI that
is not released yet. The pipeline in .circleci/ runs all of the above,
then the packed orb itself on CircleCI, on amd64 and arm64, and publishes
the version a vX.Y.Z tag names once those pass. On every branch it also
uploads this repository's own coverage (selftest/, a few lines of Go
that exist for this) to app.gocov.dev with the orb, so each change is
tried against the hosted service too.
A release follows a gocov release by itself: gocov opens a pull request
here that pins the new CLI and writes the next version as the newest
## X.Y.Z heading of CHANGELOG.md, labeled release. Merging it tags
that version (.github/workflows/tag-on-release-merge.yml), and the tag's
pipeline publishes it. A change merged in between writes its changelog
lines under ## Unreleased, and that pull request moves them under the
new heading.
MIT. The orb is a thin wrapper around the gocov CLI and is deliberately MIT-licensed so it never pulls AGPL terms into your pipeline; the gocov server remains separately licensed.