Docs

Go coverage

Go emits cover profiles. Convert the profile to LCOV before uploading it to 9to5 coverage.

Install dependencies

go install github.com/jandelgado/gcov2lcov@latest

Generate coverage

go test ./... -coverprofile=coverage.out
gcov2lcov -infile=coverage.out -outfile=coverage.lcov

GitHub Actions workflow

Add COVERAGE_UPLOAD_TOKEN as a GitHub secret and upload the converted LCOV file. The action uses the default upload endpoint unless you provide an optional endpoint override.

name: coverage

on:
  pull_request:
  push:

jobs:
  coverage:
    if: github.event_name == 'pull_request' || github.ref_name == github.event.repository.default_branch
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: "1.23"
          cache: true
      - run: go test ./... -coverprofile=coverage.out
      - run: go install github.com/jandelgado/gcov2lcov@latest
      - run: gcov2lcov -infile=coverage.out -outfile=coverage.lcov
      - name: Upload coverage
        uses: 9to5/9to5-coverage-action@v1
        with:
          token: ${{ secrets.COVERAGE_UPLOAD_TOKEN }}
          path: coverage.lcov

Pull request behavior

After conversion to LCOV, Go coverage uploads produce the same project and patch checks as JavaScript and TypeScript projects.

Troubleshooting

If package paths do not line up with pull request files, run the workflow from the repository root and avoid moving the coverage file between checkouts.