Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

A continuous integration plugin to allow detecting code coverage for only the lines changed in a PR.

License

Notifications You must be signed in to change notification settings

target/pull-request-code-coverage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pull-request-code-coverage

A continuous integration plugin to allow detecting code coverage for only the lines changed in a PR.

Sometimes when working to get a repo to an acceptable level of code coverage, it can be hard to tell if one change is covered enough. This plugin will look at just the lines changed in the PR and report code coverage for only those lines.

This plugin will output the coverage details to the CI/CD step's console. A sample Vela step console

This plugin as well as has the ability to comment on the PR with a summary of the coverage details.

Currently, this plugin supports two coverage file format.

  • jacoco for jvm based languages like java,kotlin,scala
  • cobertura can be used for golang projects using gocov-xml utility

This plugin works out of box for Vela,a CI/CD open-sourced by target

VELA Usage

Jvm based projects

For java/koltin based projects you need jacoco files that goes as an input to this plugin. How to generate jacoco files is outside the scope of this project. Once you have that jacoco file, you can pass that path to coverage_file parameter as shown below

- name: check-pr-code-coverage
   image: docker.target.com/app/pull-request-code-coverage
   pull: true
   ruleset:
     event: [pull_request]
   parameters:
     coverage_type: jacoco
     coverage_file: some-sub-module/build/reports/jacoco/test/jacocoTestReport.xml
     source_dirs:
       - src/main/java
       - src/main/kotlin
     gh_api_base_url: https://git.target.com
     module: some-sub-module
   secrets:
     - source: pull_request_api_key
       target: plugin_gh_api_key

Golang based projects

You can use gocov-xml utility to generate coverage.xml

 - go get github.com/axw/gocov/gocov
 - go get github.com/AlekSi/gocov-xml
 - go test -v -coverpkg=./... -coverprofile=coverage.txt ./...
 - go tool cover -func=coverage.txt
 - gocov convert coverage.txt | gocov-xml > ./coverage.xml

Once you have coverage.xml same can be passed as an input to plugin shown below

- name: check-pr-code-coverage
   image: docker.target.com/app/pull-request-code-coverage
   pull: true
   ruleset:
     event: [pull_request]
   parameters:
     coverage_type: cobertura
     #coverage.xml generated in above step
     coverage_file: coverage.xml
     source_dirs:
       - /vela/src/github.com/targetOSS/pull-request-code-coverage
     gh_api_base_url: https://git.target.com
   secrets:
     - source: pull_request_api_key
       target: plugin_gh_api_key

Parameters

param required default description
coverage_type true supported values: jacoco, cobertura

sets the coverage file format
coverage_file true path to where the coverage file will be located, relative to the working dir
source_dirs true array of source dirs, relative to the working dir
gh_api_base_url false base url of the gh api for posting coverage comments

if not set, coverage details will not be commented on PR
gh_api_key false api key to auth for posting coverage comments

if not set, coverage details will not be commented on PR
module false <empty string> sub-module to use if operating inside a multi-module project (e.g. gradle multi-project build)

Development

This project needs go (>= 1.17) to be installed. Make sure you run

  • make format
  • make lint

before submitting a PR

License

This project is licensed under the Apache License, Version 2.0.

About

A continuous integration plugin to allow detecting code coverage for only the lines changed in a PR.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages