Debian Codegraph @

contrib/make-coverage-badge

raw
1 #!/usr/bin/env bash
2
3 text=${1:-coverage}
4 textwidth=$(($(echo -n "$text"|wc -m) * 7 + 6))
5 numwidth=54
6 totalwidth=$(($textwidth + $numwidth))
7
8 coverage=$(grep -m 1 'headerCovTableEntry[a-zA-Z].*[0-9]*' Libidn2-*-coverage/index.html|sed 's/^.*>\([0-9]\+\.[0-9]\+\).*/\1/');
9 coverage=$(printf %.2f $coverage)
10 inum=$(echo $coverage|cut -d'.' -f1)
11 if [ -z "$inum" ]; then inum="0"; fi
12 coverage="$coverage%"
13
14 # https://www.w3.org/TR/SVG11/types.html#ColorKeywords
15 if [ $inum -ge 90 ]; then
16 # color="lawngreen"
17 color="#4c1"
18 elif [ $inum -ge 80 ]; then
19 color="yellow"
20 elif [ $inum -ge 70 ]; then
21 color="orange"
22 else
23 color="red"
24 fi
25
26 cat <<EOF >badge.svg
27 <svg xmlns="http://www.w3.org/2000/svg" width="${totalwidth}" height="20">
28 <linearGradient id="b" x2="0" y2="100%">
29 <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
30 <stop offset="1" stop-opacity=".1"/>
31 </linearGradient>
32 <mask id="a">
33 <rect width="${totalwidth}" height="20" rx="3" fill="#fff"/>
34 </mask>
35 <g mask="url(#a)">
36 <path fill="#555" d="M0 0h${textwidth}v20H0z"/>
37 <path fill="${color}" d="M${textwidth} 0h${numwidth}v20H${textwidth}z"/>
38 <path fill="url(#b)" d="M0 0h${totalwidth}v20H0z"/>
39 </g>
40 <g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,Geneva,sans-serif" font-size="11">
41 <text x="$(($textwidth / 2))" y="15" fill="#010101" fill-opacity=".3">${text}</text>
42 <text x="$(($textwidth / 2))" y="14">${text}</text>
43 <text x="$(($textwidth + $numwidth / 2))" y="15" fill="#010101" fill-opacity=".3">${coverage}</text>
44 <text x="$(($textwidth + $numwidth / 2))" y="14">${coverage}</text>
45 </g>
46 </svg>
47 EOF