Skip to content

GitHub Actions

Add gocov/gocov-action after your test step and grant the job id-token: write; it needs no secret at all:

permissions:
  contents: read
  id-token: write
steps:
  - run: go test ./... -covermode=atomic -coverprofile=coverage.out
  - uses: gocov/gocov-action@v1
    with:
      files: coverage.out

The one prerequisite: the repository's workspace (its GitHub org or user) is registered on gocov and connected through the gocov GitHub App. The repository itself needs no setup — its first upload registers it.

  • No toolchain needed. The action downloads the pinned CLI binary for the runner and verifies its checksum, so the same 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_request runs.
  • files takes a comma-separated list and globs. Several files become one report, so they share a format — see Several files.

Uploading without a token

On your own repository's push and same-repo pull request builds, the uploader asks GitHub for a short-lived, signed identity token that proves which repository the run belongs to; the server verifies it against GitHub and accepts the upload. Nothing to create in the settings UI, nothing to paste, nothing to rotate.

The workspace connection it relies on also posts the PR comment and check run: OIDC replaces only the upload token, and publishing still goes through that App identity, so the reported status looks exactly like a token upload (it is not marked unverified).

A few things follow from how the identity token works:

  • The token's audience is bound to your gocov server, so a token minted for another service can't be replayed here. When self-hosting, set the action's server input (the CLI's -server) so the audience matches your instance.
  • A pasted GOCOV_TOKEN always takes precedence, so an existing setup is never surprised. Without one the uploader uses OIDC when the job has the id-token permission, and on a pull request run with neither, tokenless fork-PR verification.
  • A rejected OIDC upload never fails the build: the job logs the reason and exits 0, except under fail-on-gate.

Using an upload token instead

If you'd rather use a secret, set GOCOV_TOKEN as an organization secret (or a repository secret) holding your workspace's upload token, and pass it to the action:

- run: go test ./... -covermode=atomic -coverprofile=coverage.out
- uses: gocov/gocov-action@v1
  with:
    files: coverage.out
    token: ${{ secrets.GOCOV_TOKEN }}

The job then needs no id-token permission.

Options

input meaning
files coverage file(s) to upload — comma-separated, globs allowed
token the workspace upload token; leave it out when the job uploads via OIDC
part names one slice of a matrix or multi-job build — see Parts
ignore glob patterns for files to leave out, comma-separated or one per line — see Ignoring files
server only when self-hosting: your instance's URL. On the hosted service the server is implicit
fail-on-error true (the default) fails the job when installing the CLI or uploading fails; false only warns. A fork PR's tokenless upload that is refused never fails the job
fail-on-gate true fails the job, with exit status 3, when the commit fails its coverage gate, whatever fail-on-error says — see Blocking merges on coverage
version the gocov CLI release to download; the default is the one that action release was tested against

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:

permissions:
  contents: read
  id-token: write
steps:
  - run: go test ./... -covermode=atomic -coverprofile=coverage.out
  - run: go run github.com/gocov/gocov/cmd/gocov@latest upload coverage.out

With an upload token instead, pass the secret to the step:

- 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.

The upload step can also fail on the gate itself, connected or not: with fail-on-gate: true a commit that fails its gate fails the job, a fork's pull request included. Pair it with fail-on-error: false and an upload that does not land only warns, while the gate still stops the job.

Under fail-on-gate a refused OIDC upload counts as an upload that failed, since its gate went unchecked; fail-on-error decides whether it fails the job or warns. A fork PR's tokenless upload that is refused still never fails the job.

- uses: gocov/gocov-action@v1
  with:
    files: coverage.out
    fail-on-error: false
    fail-on-gate: true