File tree Expand file tree Collapse file tree 5 files changed +56
-2
lines changed Expand file tree Collapse file tree 5 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 19
19
- name : Check totals 🛡
20
20
run : node bin/check-total --min 90
21
21
22
+ - name : Update code coverage badge 🥇
23
+ run : node bin/update-badge
24
+
22
25
- name : Semantic Release 🚀
23
26
uses : cycjimmy/semantic-release-action@v2
24
27
env :
Original file line number Diff line number Diff line change 1
- # check-code-coverage [ ![ ci status] [ ci image ]] [ ci url ]
1
+ # check-code-coverage [ ![ ci status] [ ci image ]] [ ci url ] ![ mock coverage ] ( https://img.shields.io/badge/code--coverage-100-brightgreen )
2
2
> Utilities for checking the coverage produced by NYC against extra or missing files
3
3
4
4
## Use
@@ -30,5 +30,19 @@ check-total
30
30
check-total --from coverage/coverage-summary.json --min 80
31
31
```
32
32
33
+ ## update-badge
34
+
35
+ If your README.md includes Shields.io badge, like this
36
+
37
+ 
38
+
39
+ You can update it using statements covered percentage from ` coverage/coverage-summary.json ` by running
40
+
41
+ ``` shell
42
+ update-badge
43
+ ```
44
+
45
+ Related project: [ dependency-version-badge] ( https://github.com/bahmutov/dependency-version-badge )
46
+
33
47
[ ci image ] : https://github.com/bahmutov/check-code-coverage/workflows/ci/badge.svg?branch=master
34
48
[ ci url ] : https://github.com/bahmutov/check-code-coverage/actions
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ // @ts -check
3
+
4
+ const path = require ( 'path' )
5
+ const fs = require ( 'fs' )
6
+
7
+ function updateBadge ( ) {
8
+ const coverageFilename = path . join ( process . cwd ( ) , 'coverage' , 'coverage-summary.json' )
9
+ const coverage = require ( coverageFilename )
10
+ const pct = coverage . total . statements . pct
11
+
12
+ const readmeFilename = path . join ( process . cwd ( ) , 'README.md' )
13
+ const readmeText = fs . readFileSync ( readmeFilename , 'utf8' )
14
+
15
+ function replaceShield ( ) {
16
+ // note, Shields.io escaped '-' with '--'
17
+ const coverageRe = new RegExp (
18
+ 'https://img\\.shields\\.io/badge/code--coverage-(\\d+)-brightgreen' ,
19
+ )
20
+ const coverageBadge = `https://img.shields.io/badge/code--coverage-${ pct } -brightgreen`
21
+
22
+ const updatedReadmeText = readmeText . replace (
23
+ coverageRe ,
24
+ coverageBadge ,
25
+ )
26
+ return updatedReadmeText
27
+ }
28
+
29
+ const maybeChangedText = replaceShield ( )
30
+ if ( maybeChangedText !== readmeText ) {
31
+ console . log ( 'saving updated readme with coverage %d%%' , pct )
32
+ fs . writeFileSync ( readmeFilename , maybeChangedText , 'utf8' )
33
+ }
34
+ }
35
+
36
+ updateBadge ( )
Original file line number Diff line number Diff line change 6
6
"bin" : {
7
7
"check-coverage" : " bin/check-coverage.js" ,
8
8
"only-covered" : " bin/only-covered.js" ,
9
- "check-total" : " bin/check-total.js"
9
+ "check-total" : " bin/check-total.js" ,
10
+ "update-badge" : " bin/update-badge.js"
10
11
},
11
12
"files" : [
12
13
" bin"
You can’t perform that action at this time.
0 commit comments