Skip to content

Commit

Permalink
add -0dp and -1p options
Browse files Browse the repository at this point in the history
  • Loading branch information
gwatts committed Mar 24, 2024
1 parent 1894bb2 commit 0eeb450
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ jobs:
with:
script: |
core.setFailed('Incorrect coverage-pct: ${{ steps.coverage.outputs.coverage-pct }}')
- if: steps.coverage.outputs.coverage-pct-0dp != '67'
uses: actions/github-script@v7
with:
script: |
core.setFailed('Incorrect coverage-pct-0dp: ${{ steps.coverage.outputs.coverage-pct-0dp }}')
- if: steps.coverage.outputs.coverage-pct-1dp != '66.7'
uses: actions/github-script@v7
with:
script: |
core.setFailed('Incorrect coverage-pct-1dp: ${{ steps.coverage.outputs.coverage-pct-1dp }}')
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# default fetch-depth is insufficent to find previous coverage notes
fetch-depth: 10
Expand Down Expand Up @@ -87,14 +87,14 @@ If you want to generate a badge to put in the readme, you could add an extra ste

```yaml
- name: Update coverage badge
uses: schneegans/dynamic-badges-action@v1.3.0
uses: schneegans/dynamic-badges-action@v1.7.0
if: github.ref_name == 'main'
with:
auth: ${{ secrets.COVERAGE_GIST_SECRET }}
gistID: 788ds7a07299ab2728a33
filename: coverage.json
label: Go Coverage
message: ${{ steps.coverage.outputs.coverage-pct }}%
message: ${{ steps.coverage.outputs.coverage-pct-1dp }}%
color: ${{ steps.coverage.outputs.meets-threshold == 'true' && 'green' || 'red' }}
```

Expand Down
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ outputs:
gocov-agg-pathname:
description: 'The full pathname of the aggregated .cov coverage data'
coverage-pct:
description: 'The coverage figure for the whole project. e.g "83.4"'
description: 'The coverage figure for the whole project. e.g "83.478"'
coverage-pct-0dp:
description: 'The coverage figure for the whole project rounded to the nearest integer. e.g "83"'
coverage-pct-1dp:
description: 'The coverage figure for the whole project rounded to 1 decimal place. e.g "83.5"'
meets-threshold:
description: 'Set to true if the current coverage is greater than coverage-threshold'
coverage-last-pct:
description: 'The prior coverage percentage'
coverage-last-pct-0dp:
description: 'The prior coverage percentage rounded to the nearest integer'
coverage-last-pct-1dp:
description: 'The prior coverage percentage rounded to 1 decimal place'
coverage-last-sha:
description: 'Commit sha prior coverage was recorded at'
coverage-delta:
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,15 @@ async function generateReport() {

core.startGroup('Set output values');
core.setOutput('coverage-pct', stats.current.coverage_pct);
core.setOutput('coverage-pct-0dp', stats.current.coverage_pct.toFixed(0));
core.setOutput('coverage-pct-1dp', stats.current.coverage_pct.toFixed(1));
core.setOutput('package-count', stats.current.pkg_count);
core.setOutput('uncovered-packages', stats.current.no_tests);

core.setOutput('coverage-delta', stats.deltaPct);
core.setOutput('coverage-last-pct', stats.prior.coverage_pct);
core.setOutput('coverage-last-pct-0dp', stats.prior.coverage_pct ? stats.prior.coverage_pct.toFixed(0) : '0');
core.setOutput('coverage-last-pct-1dp', stats.prior.coverage_pct ? stats.prior.coverage_pct.toFixed(1) : '0.0');
core.setOutput('coverage-last-sha', stats.prior.sha);
core.setOutput('meets-threshold', stats.meetsThreshold);
core.setOutput('gocov-pathname', current.gocovPathname);
Expand Down
2 changes: 2 additions & 0 deletions test-go-module/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ func ReturnColor(code string) string {
return "#00f"
case "green":
return "#0f0"
case "white":
return "#fff"
default:
panic("invalid color")
}
Expand Down

0 comments on commit 0eeb450

Please sign in to comment.