CircleCI¶
gocov has an orb: one gocov/upload step after your tests, which downloads the gocov CLI, checks its sha256 and hands
it the report.
-
Have an organization admin switch on Allow uncertified public orbs under Organization Settings → Security, once per organization. CircleCI refuses every orb it has not certified itself until then; if that is not an option for you, upload without the orb.
-
Add
GOCOV_TOKENunder Project Settings → Environment Variables, holding your workspace's upload token. To share it across projects, put it in a context instead and name the context on the job. -
Upload from the job that runs the tests:
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:
- test
Only the test command and files change for other languages — Languages & formats lists what each
test tool writes. files takes a comma-separated list and globs; several files become one report, so they share a
format — see Several files. The step runs on Linux and macOS executors, on x86 and Arm alike.
Commit, branch, repo and pull request number are auto-detected from CircleCI's own variables, and the upload's page
links back to the CircleCI job it came from. When self-hosting, pass server: https://gocov.example.com to the step,
or add GOCOV_SERVER beside the token, holding your instance's URL.
gocov/gocov@1 follows the newest 1.x release of the orb, and each of those installs the gocov CLI release it was
tested with.
Options¶
| parameter | meaning |
|---|---|
files |
coverage file(s) to upload — comma-separated, globs allowed; coverage.out when left out |
token |
the name of the variable that holds the upload token, when it is not GOCOV_TOKEN |
server |
only when self-hosting: your instance's URL. On the hosted service the server is implicit |
part |
names one slice of a build split across jobs — see Parts |
ignore |
glob patterns for files to leave out, comma-separated, on top of the repo's own — see Ignoring files |
fail_on_error |
false turns a failed download or upload into a warning; the step fails over one by default |
fail_on_gate |
true fails the job, with exit status 3, when the commit fails its coverage gate — see Blocking merges on coverage |
version |
the gocov CLI release to download; the default is the one that orb release was tested against |
The same list, with each default, is on the orb's registry page.
Pull requests¶
The pull request number is what turns on diff coverage and the comment on the pull request, so it matters when CircleCI provides it:
- GitHub and Bitbucket Cloud projects get the pull request's URL in
CIRCLE_PULL_REQUEST, filled in as the pipeline starts. A push made before the pull request was opened therefore uploads as a branch build, and the pull request gets its comment on the next push. CircleCI's Only build pull requests setting closes that gap: a branch then builds once it has a pull request, and the default branch still builds on every push. - The default branch never uploads as a pull request, even when CircleCI names one for it — it does whenever the default branch is itself the head of a pull request, a release PR for instance. Its build keeps the branch's trend, badge and baseline instead, so such a pull request gets no comment from CircleCI.
- GitLab projects get no variable that names the merge request. Their uploads carry the commit's coverage and its
status, without diff coverage; uploading from GitLab CI gives both. A project inside a subgroup
also has to name itself, which the orb has no parameter for: upload without the orb, with
upload -repo group/subgroup/project …. CircleCI passes no path for such a project, and the checkout only tells the last two names.
Fork pull requests¶
CircleCI builds pull requests from forks only when Build forked pull requests is on, and it keeps the project's environment variables out of those builds, so they have no upload token. The orb's step says so, uploads nothing and passes: a contributor's build does not fail over coverage. The pull request gets its coverage once a build of a branch in your own repository uploads it.
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.
Several jobs, one commit¶
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: part: backend on the step in one job, part: frontend in the other.
Blocking merges on coverage¶
With the workspace connected, every upload sets a gocov status on the commit. To make the
coverage gate block merges, require that status where your forge decides what may merge: branch
protection on GitHub, merge checks on Bitbucket.
The step can also fail on the gate itself, connected or not:
With fail_on_gate, a commit that fails its gate fails the job with exit status 3, even with
fail_on_error: false. An upload that did not land fails it with 1, unless fail_on_error: false turns that into
a warning.
Without the orb¶
The orb only downloads the CLI and runs it, and a run step can do the same. Use it where the organization cannot
allow uncertified orbs, or to pass the CLI a flag the orb has no parameter for:
version: 2.1
jobs:
test:
docker:
- image: cimg/go:1.27
steps:
- checkout
- run: go test ./... -covermode=atomic -coverprofile=coverage.out
- run:
name: Upload coverage
command: |
curl -fsSLO https://github.com/gocov/gocov/releases/download/v0.42.0/gocov-linux-amd64
curl -fsSL https://github.com/gocov/gocov/releases/download/v0.42.0/checksums.txt \
| grep ' gocov-linux-amd64$' | sha256sum -c -
chmod +x gocov-linux-amd64
./gocov-linux-amd64 upload coverage.out
workflows:
test:
jobs:
- test
On an Arm resource class, download gocov-linux-arm64 instead; a Windows executor, which the orb does not run on,
takes gocov-windows-amd64.exe from the same release. This step has no token on a
fork's pull request and fails there with no upload credential; to keep those builds green,
start its command with:
A part is upload -part backend …, and the gate fails the job with upload -fail-on-gate ….
Coming from the Codecov orb¶
The codecov/upload step becomes gocov/upload, and the orb's line under orbs: changes with it:
# before
orbs:
codecov: codecov/codecov@6.1.0
jobs:
test:
steps:
- checkout
- run: pytest --cov --cov-report=xml
- codecov/upload:
files: coverage.xml
flags: unit
# after
orbs:
gocov: gocov/gocov@1
jobs:
test:
steps:
- checkout
- run: pytest --cov --cov-report=xml
- gocov/upload:
files: coverage.xml
part: unit
codecov/upload parameter |
gocov/upload |
Notes |
|---|---|---|
token |
token |
Both take the name of the variable that holds the token: CODECOV_TOKEN by default there, GOCOV_TOKEN here. |
files |
files |
Comma-separated, globs allowed. |
flags |
part |
One part per step: reports that should add up each get a step of their own. |
fail_on_error (default false) |
fail_on_error (default true) |
A failed gocov upload fails the step unless you turn this off. |
slug, sha, branch, pr |
— | Detected from CircleCI's variables. |
The rest of the move — codecov.yml, the required checks and the badge — is in
Migrating from Codecov or Coveralls.