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 actually want), but not SaaS in a few line of code. It can be used in a integration pipeline to validate pull request coverage.
This repository contains a github action that can be used directly with your github workflow (check below)
go install github.com/PaloAltoNetworks/cov@latest
Or you can get 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 -t, --threshold int The target of coverage in percent that is requested
--branch BASE is used a diff will be done between your current branch
and the branch passed as base to identify the files you changed.
You can pass several coverage files, they all will be merged.
You can filter for a given package or any substring.
--threshold X is set, the output will be colored given that target and the return will be 1 if target is not reached.
You can ignore files matching some patterns using the
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
Note: Your pull branch must be aligned with latest change of the base branch
You can use this repository as a Github Action for your workflows. You simply
need to make sure one of your step 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: jobs: build: steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 - name: test run: go test -coverprofile=coverage.out ./... - uses: PaloAltoNetworks/cov@master with: cov_version: latest cov_file: coverage.out cov_threshold: "70" main_branch: main
All parameters are optionals. The default values are shown below, but they can all be ommited if they are good enough for you.