Best way to include coverage percentage in a GitHub README.md

48 views
Skip to first unread message

Paul Hammant

unread,
May 8, 2019, 11:01:18 AM5/8/19
to JaCoCo and EclEmma Users
So I've run JaCoCo via the maven plugin, and am trying to pluck out the instruction percentage.

Here's what I have for the NN percentage figure:

cat target/site/jacoco/index.html | xmlstarlet format --indent-tab | xmlstarlet sel   -N x="http://www.w3.org/1999/xhtml"   -t   -m "//x:tfoot"   -v . | grep % | head -1 | xargs | tr -d '%' 

Then, I'll take an template SVG with the figure in it like so:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xl="http://www.w3.org/1999/xlink" version="1.1" viewBox="314.084 115 32.832 30" width="32.832" height="30">
  <defs>
    <font-face font-family="Helvetica Neue" font-size="16" panose-1="2 0 5 3 0 0 0 2 0 4" units-per-em="1000" underline-position="-100" underline-thickness="50" slope="0" x-height="517" cap-height="714" ascent="951.9958" descent="-212.99744" font-weight="400">
      <font-face-src>
        <font-face-name name="HelveticaNeue"/>
      </font-face-src>
    </font-face>
  </defs>
  <g id="Canvas_1" fill-opacity="1" stroke="none" stroke-dasharray="none" fill="none" stroke-opacity="1">
    <title>Canvas 1</title>
    <g id="Canvas_1: Layer 1">
      <title>Layer 1</title>
      <g id="Graphic_2">
        <text transform="translate(319.084 120)" fill="black">
          <tspan font-family="Helvetica Neue" font-size="16" font-weight="400" fill="black" x="0" y="15">NN</tspan>
        </text>
      </g>
    </g>
  </g>
</svg>

.. and replace the NN (using sed) to make an SVG with the number in it, and refer to that image as "coverage-percentage.svg" in the README. I'll need to check it in again. Obviously the file only gets committed when the coverage percenage actually changes.

Is there a better way, anyone has evolved? Maybe the SVG piece is solid, and there's a better way of plucking the coverage out the HTML build report (the total is not in the CSV).

Evgeny Mandrikov

unread,
May 8, 2019, 12:56:57 PM5/8/19
to JaCoCo and EclEmma Users


On Wednesday, May 8, 2019 at 5:01:18 PM UTC+2, Paul Hammant wrote:
Is there a better way, anyone has evolved? Maybe the SVG piece is solid, and there's a better way of plucking the coverage out the HTML build report (the total is not in the CSV).

IMO better way is to process XML, totals are available in it:

example.png


Paul Hammant

unread,
May 11, 2019, 2:40:28 AM5/11/19
to JaCoCo and EclEmma Users
Yeah, you're right, but I have finished it and operationalized it for HTML now: https://twitter.com/paul_hammant/status/1127100345920970752

I wish I could make a setting for JaCoCo's maven plugin to change from NN percentages to NN.n. I scoured the docs and GH issues and couldn't see how.

- Paul

Evgeny Mandrikov

unread,
May 13, 2019, 6:39:22 AM5/13/19
to JaCoCo and EclEmma Users
There is no such option and this use-case clearly doesn't justify introduction of it, because HTML report is not for parsing - parse XML.
Or even simply apply XSLT transformation on it - https://github.com/jacoco/jacoco/pull/488#issuecomment-280295541
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages