testing:coverage
About 772 wordsAbout 3 min
testing:coverage
Unit Test Coverage, calculates the coverage based on unit test result reports and reports badge data.
You can view the coverage badge data of the latest 100 commits by branch in the repository's Insights page in the form of charts.
Tips
For coverage data reported by pipelines triggered by events related to Pull Requests (except pull_request.merged), switch to the pull request view to see the unit test insights curve.
Applicable Events
Full Coverage
Parsed from local coverage report files, currently recognizing the following report formats:
json(js)(recommended)json-summarylcov(recommended)jacocogolang
Incremental Coverage
Parameters
The list below gives an overview of all testing:coverage parameters.
- key: Coverage data key used to distinguish multiple coverage sets
- name: Coverage name shown in the badge; pairs with
key - pattern: Glob pattern to locate report files
- lines: Full-coverage threshold; fails the pipeline if below
- diffLines: Incremental-coverage threshold; fails the pipeline if below
- allowExts: Whitelist of file extensions included in the coverage calculation
- lang: Set to
goforgolangreports to avoid calculation errors - breakIfNoCoverage: Whether to fail when no coverage report is found
Detailed descriptions for each parameter are provided below.
key
- type:
String - required:
false
Coverage data key values, used to distinguish between different types of coverage data, such as frontend, backend, etc.
- Up to
256characters - Up to
30different keys per repository - When a key is specified, the coverage data is only written into the meta map, and the top-level value (default full/incremental coverage) is no longer recorded. The default coverage data is only recorded when no key is specified.
name
- type:
String - required:
false
Coverage data names, used for display in badges, correspond one-to-one with coverage data keys. When a key does not exist, the name will be ignored.
For example: key: frontend, name: frontend coverage
pattern
- type:
String - required:
false
In Glob format, specifies the location of the coverage report file relative to the current working directory. If not provided, it will try to find the following files in the current directory (including subdirectories): coverage.json, jacoco*.xml, lcov.info,*.lcov.
lines
- type:
Number - required:
false
Specifies the full coverage red line. If the full coverage percentage is less than this value, the workflow will be blocked from exiting the pipeline.
diffLines
- type:
Number - required:
false
Specifies the incremental coverage red line. If the incremental coverage percentage is less than this value, the workflow will be blocked from exiting the pipeline. Events like pull_request, pull_request.update, pull_request.target support calculating incremental coverage results, while other events only calculate full coverage.
allowExts
- type:
String - required:
false
Whitelist of code file types to be included in coverage calculation, separated by commas, e.g., .json, .ts, .js. If not provided, all files in the report will be included in the calculation.
lang
- type:
String - required:
false
When the coverage report target format is golang, specify this parameter as go to avoid calculation errors. This parameter can be ignored in other cases.
breakIfNoCoverage
- type:
Boolean - required:
false
Whether to throw an error and terminate the process if no coverage report file is found.
Output Results
{
// Code line coverage, e.g., 100. Value is NA if calculation fails.
"lines": 100,
// Incremental code line coverage, e.g., 100. Value is NA if calculation fails.
"diff_pct": 100
}Configuration Examples
main:
push:
- stages:
- name: coverage
type: testing:coverage
options:
breakIfNoCoverage: false
exports:
lines: LINES
- name: result
script: echo $LINES