Skip to content

Commit

Permalink
final test before release
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-8 committed Dec 17, 2019
1 parent f58cef4 commit 28d8e62
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
48 changes: 21 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,36 @@

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

Repurposed from Commit Comment by Peter Evans
![Commit Comment Example](https://github.com/peter-evans/commit-comment/blob/master/comment-example.png?raw=true)

## Usage
## Usage with Karma + Angular
1. Add `"codeCoverage": true,` under test > options in angular.json
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
3. Use in your workflow as illustrated below:

```yml
- name: Create commit comment
uses: jacobbowdoin/comment-test-coverage@v1
name: test-pull-request
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v1

- name: Run Jasmine tests
run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI

- name: Comment Test Coverage on Commit
uses: jacobbowdoin/comment-test-coverage@1
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
This is a multi-line test comment
- With GitHub **Markdown**
- Created by [comment-test-coverage][1]
[1]: https://github.com/jacobbowdoin/comment-test-coverage
path: coverage/coverage-summary.json
```
## Parameters
- `token` (**required**) - The GitHub authentication token
- `body` (**required**) - The contents of the comment.


## Evaluating environment variables

Environment variables can be evaluated in the `body` input as follows.
- `token` (**required**) - The GitHub authentication token (workflows automatically set this for you, nothing needed here)
- `path` (**required**) - Path to your coverage-summary.json file

```yml
- name: Create commit comment
uses: jacobbowdoin/comment-test-coverage@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
My env var: ${process.env.MY_ENV_VAR}
```

## License

Expand Down
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,16 @@ async function run() {
const sha = process.env.GITHUB_SHA;
core.debug(`SHA: ${sha}`);

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

const coverage = `==== **Test Coverage** ====
Statements: ${json.total.statements.pct}% ( ${json.total.statements.covered}/${json.total.statements.total} )
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered}/${json.total.branches.total} )
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered}/${json.total.functions.total} )
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered}/${json.total.lines.total} )`
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered} /${json.total.branches.total} )
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered} /${json.total.functions.total} )
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered} /${json.total.lines.total} )`

await request(
`POST /repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}/comments`,
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ async function run() {
const sha = process.env.GITHUB_SHA;
core.debug(`SHA: ${sha}`);

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

const coverage = `==== **Test Coverage** ====
Statements: ${json.total.statements.pct}% ( ${json.total.statements.covered}/${json.total.statements.total} )
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered}/${json.total.branches.total} )
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered}/${json.total.functions.total} )
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered}/${json.total.lines.total} )`
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered} /${json.total.branches.total} )
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered} /${json.total.functions.total} )
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered} /${json.total.lines.total} )`

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

0 comments on commit 28d8e62

Please sign in to comment.