diff --git a/README.md b/README.md index 3ff3638..e379e39 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 40042da..b96deb2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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`, diff --git a/index.js b/index.js index 3cda64f..a15a105 100644 --- a/index.js +++ b/index.js @@ -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`,