Skip to content

Commit 28d8e62

Browse files
author
Jacob Bowdoin
committed
final test before release
1 parent f58cef4 commit 28d8e62

3 files changed

Lines changed: 29 additions & 35 deletions

File tree

README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,36 @@
22

33
A GitHub action to comment on a commit on GitHub with a simple test coverage summary from Karma.
44

5-
Repurposed from Commit Comment by Peter Evans
6-
![Commit Comment Example](https://github.com/peter-evans/commit-comment/blob/master/comment-example.png?raw=true)
7-
8-
## Usage
5+
## Usage with Karma + Angular
6+
1. Add `"codeCoverage": true,` under test > options in angular.json
7+
2. In your karma.conf.js set coverageIstanbulReporter.reports to include `json-summary` and save it to the /coverage directory if using the sample setup below
8+
3. Use in your workflow as illustrated below:
99

1010
```yml
11-
- name: Create commit comment
12-
uses: jacobbowdoin/comment-test-coverage@v1
11+
name: test-pull-request
12+
on: [pull_request]
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v1
19+
20+
- name: Run Jasmine tests
21+
run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
22+
23+
- name: Comment Test Coverage on Commit
24+
uses: jacobbowdoin/comment-test-coverage@1
1325
with:
1426
token: ${{ secrets.GITHUB_TOKEN }}
15-
body: |
16-
This is a multi-line test comment
17-
- With GitHub **Markdown**
18-
- Created by [comment-test-coverage][1]
19-
20-
[1]: https://github.com/jacobbowdoin/comment-test-coverage
27+
path: coverage/coverage-summary.json
2128
```
2229
2330
## Parameters
2431
25-
- `token` (**required**) - The GitHub authentication token
26-
- `body` (**required**) - The contents of the comment.
27-
28-
29-
## Evaluating environment variables
30-
31-
Environment variables can be evaluated in the `body` input as follows.
32+
- `token` (**required**) - The GitHub authentication token (workflows automatically set this for you, nothing needed here)
33+
- `path` (**required**) - Path to your coverage-summary.json file
3234

33-
```yml
34-
- name: Create commit comment
35-
uses: jacobbowdoin/comment-test-coverage@v1
36-
with:
37-
token: ${{ secrets.GITHUB_TOKEN }}
38-
body: |
39-
My env var: ${process.env.MY_ENV_VAR}
40-
```
4135

4236
## License
4337

dist/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,16 @@ async function run() {
392392
const sha = process.env.GITHUB_SHA;
393393
core.debug(`SHA: ${sha}`);
394394

395-
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/`)
395+
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/${inputs.path}`)
396396
const data = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/${inputs.path}`, 'utf8');
397397
const json = JSON.parse(data);
398398
console.log(json);
399399

400400
const coverage = `==== **Test Coverage** ====
401401
Statements: ${json.total.statements.pct}% ( ${json.total.statements.covered}/${json.total.statements.total} )
402-
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered}/${json.total.branches.total} )
403-
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered}/${json.total.functions.total} )
404-
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered}/${json.total.lines.total} )`
402+
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered} /${json.total.branches.total} )
403+
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered} /${json.total.functions.total} )
404+
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered} /${json.total.lines.total} )`
405405

406406
await request(
407407
`POST /repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}/comments`,

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ async function run() {
1414
const sha = process.env.GITHUB_SHA;
1515
core.debug(`SHA: ${sha}`);
1616

17-
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/`)
17+
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/${inputs.path}`)
1818
const data = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/${inputs.path}`, 'utf8');
1919
const json = JSON.parse(data);
2020
console.log(json);
2121

2222
const coverage = `==== **Test Coverage** ====
2323
Statements: ${json.total.statements.pct}% ( ${json.total.statements.covered}/${json.total.statements.total} )
24-
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered}/${json.total.branches.total} )
25-
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered}/${json.total.functions.total} )
26-
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered}/${json.total.lines.total} )`
24+
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered} /${json.total.branches.total} )
25+
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered} /${json.total.functions.total} )
26+
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered} /${json.total.lines.total} )`
2727

2828
await request(
2929
`POST /repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}/comments`,

0 commit comments

Comments
 (0)