Skip to content

Commit 0eeb450

Browse files
committed
add -0dp and -1p options
1 parent 1894bb2 commit 0eeb450

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed

.github/workflows/ci.yml

+10
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ jobs:
2828
with:
2929
script: |
3030
core.setFailed('Incorrect coverage-pct: ${{ steps.coverage.outputs.coverage-pct }}')
31+
- if: steps.coverage.outputs.coverage-pct-0dp != '67'
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
core.setFailed('Incorrect coverage-pct-0dp: ${{ steps.coverage.outputs.coverage-pct-0dp }}')
36+
- if: steps.coverage.outputs.coverage-pct-1dp != '66.7'
37+
uses: actions/github-script@v7
38+
with:
39+
script: |
40+
core.setFailed('Incorrect coverage-pct-1dp: ${{ steps.coverage.outputs.coverage-pct-1dp }}')

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
coverage:
5050
runs-on: ubuntu-latest
5151
steps:
52-
- uses: actions/checkout@v3
52+
- uses: actions/checkout@v4
5353
with:
5454
# default fetch-depth is insufficent to find previous coverage notes
5555
fetch-depth: 10
@@ -87,14 +87,14 @@ If you want to generate a badge to put in the readme, you could add an extra ste
8787

8888
```yaml
8989
- name: Update coverage badge
90-
uses: schneegans/dynamic-badges-action@v1.3.0
90+
uses: schneegans/dynamic-badges-action@v1.7.0
9191
if: github.ref_name == 'main'
9292
with:
9393
auth: ${{ secrets.COVERAGE_GIST_SECRET }}
9494
gistID: 788ds7a07299ab2728a33
9595
filename: coverage.json
9696
label: Go Coverage
97-
message: ${{ steps.coverage.outputs.coverage-pct }}%
97+
message: ${{ steps.coverage.outputs.coverage-pct-1dp }}%
9898
color: ${{ steps.coverage.outputs.meets-threshold == 'true' && 'green' || 'red' }}
9999
```
100100

action.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ outputs:
5858
gocov-agg-pathname:
5959
description: 'The full pathname of the aggregated .cov coverage data'
6060
coverage-pct:
61-
description: 'The coverage figure for the whole project. e.g "83.4"'
61+
description: 'The coverage figure for the whole project. e.g "83.478"'
62+
coverage-pct-0dp:
63+
description: 'The coverage figure for the whole project rounded to the nearest integer. e.g "83"'
64+
coverage-pct-1dp:
65+
description: 'The coverage figure for the whole project rounded to 1 decimal place. e.g "83.5"'
6266
meets-threshold:
6367
description: 'Set to true if the current coverage is greater than coverage-threshold'
6468
coverage-last-pct:
6569
description: 'The prior coverage percentage'
70+
coverage-last-pct-0dp:
71+
description: 'The prior coverage percentage rounded to the nearest integer'
72+
coverage-last-pct-1dp:
73+
description: 'The prior coverage percentage rounded to 1 decimal place'
6674
coverage-last-sha:
6775
description: 'Commit sha prior coverage was recorded at'
6876
coverage-delta:

dist/index.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,15 @@ async function generateReport() {
440440

441441
core.startGroup('Set output values');
442442
core.setOutput('coverage-pct', stats.current.coverage_pct);
443+
core.setOutput('coverage-pct-0dp', stats.current.coverage_pct.toFixed(0));
444+
core.setOutput('coverage-pct-1dp', stats.current.coverage_pct.toFixed(1));
443445
core.setOutput('package-count', stats.current.pkg_count);
444446
core.setOutput('uncovered-packages', stats.current.no_tests);
445447

446448
core.setOutput('coverage-delta', stats.deltaPct);
447449
core.setOutput('coverage-last-pct', stats.prior.coverage_pct);
450+
core.setOutput('coverage-last-pct-0dp', stats.prior.coverage_pct ? stats.prior.coverage_pct.toFixed(0) : '0');
451+
core.setOutput('coverage-last-pct-1dp', stats.prior.coverage_pct ? stats.prior.coverage_pct.toFixed(1) : '0.0');
448452
core.setOutput('coverage-last-sha', stats.prior.sha);
449453
core.setOutput('meets-threshold', stats.meetsThreshold);
450454
core.setOutput('gocov-pathname', current.gocovPathname);

test-go-module/mod.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ func ReturnColor(code string) string {
88
return "#00f"
99
case "green":
1010
return "#0f0"
11+
case "white":
12+
return "#fff"
1113
default:
1214
panic("invalid color")
1315
}

0 commit comments

Comments
 (0)