Very simple action to run code coverage checking for go projects
Copy and paste the following snippet into your .yml file.
- name: paloaltonetworks/cov
Cov is a simple code coverage checker for Golang. It's like codacy or codecov (at least regarding features that people usually want), but not SaaS, in a few lines of code.
It has no reports other than a tree view showing which package is up to standard and which are not, the coverage and the required threshold. The idea is to block merging and let people fix locally the coverage with any tool they like.
It will report as a status check the status of the run.
This repository contains a Github action that can be used directly with your
Github workflow. You need to make sure one of your steps generates a coverage
file (usually using
go test -coverprofile=coverage.out) then add a new step:
name: build-go on: push: branches: - master pull_request_target: jobs: build: steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 - name: test run: go test -coverprofile=coverage.out ./... - uses: PaloAltoNetworksfirstname.lastname@example.org
There are several parameters you can tweak:
Repository main branch
The tool needs to know which branch is your main one in order to be able to run
coverage on the pull requests patch. (default:
uses: PaloAltoNetworksemail@example.com with: main_branch: master
The tool needs to know where your coverage file has been generated. The path is
relative to your repository root (default:
uses: PaloAltoNetworksfirstname.lastname@example.org with: cov_file: unit_coverage.out
You can configure what is the minimum coverage target a patch must have in order
to be considered up to standard. Note that you must give the percentage as a
uses: PaloAltoNetworksemail@example.com with: cov_threshold: "80"
This is a debugging flag that allows to force the action to use a different
version of the cov tool. You should not need to touch this. (default:
uses: PaloAltoNetworksfirstname.lastname@example.org with: cov_version: master
Ignore some files
If you have some code you would like cov to ignore (for instance, autogenerated
or example code), you can create a file named
.covignore at the root of your
repository. The syntax uses classic glob syntax.
Note that cov uses the full go package name. So you need to either write the
full package, or use a
github.com/me/mypackage/ignored/* **/pkgs/api/* **/example/* **/something/**/something
You can install cov locally:
go install github.com/PaloAltoNetworks/cov@latest
Or you can grab a release from the releases page.
Analyzes coverage Usage: cov cover.out... [flags] Flags: -b, --branch string The branch to use to check the patch coverage against. Example: master -f, --filter strings The filters to use for coverage lookup -h, --help help for cov -i, --ignore strings Define patterns to ignore matching files. -q, --quiet Do not print details, just the verdict --send-status string If set, send a status check. format: [repo]/[owner]@[sha] --send-token string If set, use this token to send the status. If empty, $GITHUB_TOKEN will be used -t, --threshold int The target of coverage in percent that is requested -e, --threshold-exit-code int Set the exit code on coverage threshold miss (default 1) --version show version
--branch flag is used, a diff will be done between your current
branch and the given branch to identify the files you changed, and only look for
the coverage of that diff.
You can pass several coverage files, they all will be merged.
You can filter for a given package or any substring.
--threshold flag is set, cov will check if the coverage is greater or
equal to that value. It will exit with the code passed as
You can ignore files matching some patterns using the
--ignore option. If you
use this parameter, the
.covignore file will be ignored.
Show coverage for all coverage files:
Show coverage for a pull request against master:
cov --branch master coverage.out
Ignore all files in
cov --ignore "**/autogen/api/*" --ignore "**/examples/*" coverage.out
Check for a minimum coverage, but don't exit with code 1:
cov --threshold 80 --threshold-exit-code 0 coverage.out