Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PR comments #3

Merged
merged 15 commits into from
Aug 1, 2024
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

permissions:
contents: read
pull-requests: write

jobs:
test-typescript:
Expand Down Expand Up @@ -59,6 +60,9 @@ jobs:
with:
lcov-file: './__tests__/lcov-test-2.info'
excluded-files: '**/*.g.dart, **/*.freezed.dart, **/.realm.dart'
step-summary: true
pr-comment: true
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Print Output
id: output
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: CodeQL

on:
pull_request:
branches:
- main
push:
branches:
- main
schedule:
- cron: '31 7 * * 3'
# pull_request:
# branches:
# - main
# push:
# branches:
# - main
# schedule:
# - cron: '31 7 * * 3'
workflow_call:

permissions:
actions: read
Expand Down
98 changes: 92 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,105 @@ or run output.
## Example for configuration

```yaml
- name: LCOV parser
id: lcov-result
uses: Richter-Consulting/wd-lcov-reporter
with:
lcov-file: './coverage/lcov.info'
excluded-files: '**/*.g.dart, **/*.freezed.dart, **/.realm.dart'
permissions:
pull-requests: write

jobs:
coverage:
- name: LCOV parser
id: lcov-result
uses: Richter-Consulting/wd-lcov-reporter@v1
with:
# Coverage file path
lcov-file: './coverage/lcov.info'
# Optional: Files to exclude from coverage report
excluded-files: '**/*.g.dart, **/*.freezed.dart, **/.realm.dart'
# Optional (default: 'true): Report coverage as step summary
step-summary: 'true'
# Optional (default: 'false): Reoprt coverage on PR
# (with update of the comment)
pr-comment: 'true'
# Optional: GitHub token to write the PR comment
# (also requires premission to do so)
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Coverage output
run: |
echo "${{ steps.lcov-result.outputs.coverage }}"
echo "${{ steps.lcov-result.outputs.markdown-table }}"
```

### Configuration parameters

#### `lcov-file`

Path to the lcov file to parse (currently only one file supported).

#### `excluded-files`

Comma separated list of files, that should be excluded from code coverade
report. Common globes can be used here:

- `**`: folder globe (e.g. `**/email.dart` would match `foo/email.dart` but also
`foo/bar/foo-bar/email.dart`)
- `*`: filename globe (e.g. `**/email-*-validation.dart` would match
`email-domain-validation.dart` but not `emailvalidation.dart`)

#### `step-summary`

Publish the coverage table to step summary (optional - default: `true`)

#### `pr-comment`

Publish the coverage table as PR comment. On new push, the comment is updated
(optional - default: `false`)

##### Example

<!-- markdownlint-disable -->

---

# Coverage Summary

Overall coverage: **22.83 %**

<details><summary>Detailed coverage</summary>

| File | Line Coverage | Function Coverage | Branch Coverage |
| ------------------- | ------------- | ----------------- | --------------- |
| lib/email.dar | 100.00% | 0.00% | 0.00% |
| lib/exceptions.dart | 40.00% | 0.00% | 0.00% |

</details>

---

#### `github-token`

<!-- markdownlint-enable -->

GitHub token, required only to comment on PR. This is also required the write
permission on PR (see configuration example). If PR comment is disabled, the
token is not needed.

### Overall coverage result

22.83

### Mardown Table result

| File | Line Coverage | Function Coverage | Branch Coverage |
| ------------------- | ------------- | ----------------- | --------------- |
| lib/email.dart | 100.00% | 0.00% | 0.00% |
| lib/exceptions.dart | 40.00% | 0.00% | 0.00% |

## TODO

- [x] Parse lcov file, so it is easier to handle the results
- [x] Provide following outputs
- Markdown table with code coverage per test file
- Overall coverage
- [x] Add possibility to "comment" on PR
- [x] Add possibility for run output
- [ ] Add templates
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ inputs:
excluded-files:
description: 'List of files to exclude from coverage, "," (comma) separated'
required: false
step-summary:
description: 'Add the coverage table to the step summary'
required: false
default: 'true'
pr-comment:
description: 'Add the coverage table as PR comment'
required: false
default: 'false'
github-token:
description: 'GitHub token to use for PR comment'
required: false

# Define your outputs here.
outputs:
Expand Down
Loading
Loading