Skip to content

Commit

Permalink
Add support for Go coverage files (#7)
Browse files Browse the repository at this point in the history
- Add util for finding longest common subpath (used to strip off Go
  module names to leave source file path)
- Move covered file path manipulation into each coverage parser
  • Loading branch information
ggilder authored Jun 16, 2023
1 parent 843c918 commit a5671c0
Show file tree
Hide file tree
Showing 18 changed files with 12,145 additions and 106 deletions.
42 changes: 8 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ Generate code coverage annotation in pull request within Github Action Workflow

## Inputs


| Key | Required | Default | Description |
| -------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------- |
| `GITHUB_TOKEN` | **yes** | - | Github Token generated by Github Action workflow. You can pass this in as `${{secrets.GITHUB_TOKEN}}` |
| `COVERAGE_FILE_PATH` | **yes** | - | Location of coverage file that was generated |
| `COVERAGE_FORMAT` | **no** | lcov | Format of coverage file. May be either `lcov` or `clover`. |
| `COVERAGE_FORMAT` | **no** | lcov | Format of coverage file. May be `lcov`, `clover`, or `go` |

## Example
```yaml
Expand All @@ -28,54 +27,29 @@ Generate code coverage annotation in pull request within Github Action Workflow
COVERAGE_FILE_PATH: "./coverage/lcov.info"
```
## Code in Main
## Contributing
> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
> First, you'll need to have a reasonably modern version of `node` handy, ideally 16 or newer. Older versions will change the format of `package-lock.json`.

Install the dependencies
Install the dependencies:
```bash
$ npm install
```

Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```

Run the tests :heavy_check_mark:
Run formatting and linting, build the typescript and package it for distribution, and run tests:
```bash
$ npm test
...
$ npm run all
```


## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
Make sure you commit the `dist/` folder or CI will fail.

## Validate

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
You can validate the action while developing by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))

```yaml
uses: ./
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
COVERAGE_FILE_PATH: "./coverage/lcov.info"
```

See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
217 changes: 217 additions & 0 deletions __tests__/fixtures/gocoverage.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
mode: set
github.com/ggilder/bitrot/bitrot.go:57.54,59.16 2 1
github.com/ggilder/bitrot/bitrot.go:59.16,61.3 1 0
github.com/ggilder/bitrot/bitrot.go:62.2,62.18 1 1
github.com/ggilder/bitrot/bitrot.go:65.57,67.26 2 1
github.com/ggilder/bitrot/bitrot.go:67.26,69.3 1 0
github.com/ggilder/bitrot/bitrot.go:70.2,72.16 3 1
github.com/ggilder/bitrot/bitrot.go:72.16,74.3 1 0
github.com/ggilder/bitrot/bitrot.go:75.2,80.16 4 1
github.com/ggilder/bitrot/bitrot.go:80.16,82.3 1 0
github.com/ggilder/bitrot/bitrot.go:85.2,86.16 2 1
github.com/ggilder/bitrot/bitrot.go:86.16,88.3 1 0
github.com/ggilder/bitrot/bitrot.go:89.2,89.27 1 1
github.com/ggilder/bitrot/bitrot.go:89.27,95.3 5 1
github.com/ggilder/bitrot/bitrot.go:98.2,99.16 2 1
github.com/ggilder/bitrot/bitrot.go:99.16,102.3 2 0
github.com/ggilder/bitrot/bitrot.go:104.2,106.12 2 1
github.com/ggilder/bitrot/bitrot.go:109.57,111.26 2 1
github.com/ggilder/bitrot/bitrot.go:111.26,113.3 1 0
github.com/ggilder/bitrot/bitrot.go:114.2,116.16 3 1
github.com/ggilder/bitrot/bitrot.go:116.16,118.3 1 0
github.com/ggilder/bitrot/bitrot.go:119.2,124.16 4 1
github.com/ggilder/bitrot/bitrot.go:124.16,126.3 1 0
github.com/ggilder/bitrot/bitrot.go:128.2,129.16 2 1
github.com/ggilder/bitrot/bitrot.go:129.16,131.3 1 0
github.com/ggilder/bitrot/bitrot.go:133.2,133.27 1 1
github.com/ggilder/bitrot/bitrot.go:133.27,136.3 2 1
github.com/ggilder/bitrot/bitrot.go:138.2,143.17 5 1
github.com/ggilder/bitrot/bitrot.go:143.17,146.3 2 1
github.com/ggilder/bitrot/bitrot.go:146.8,148.3 1 1
github.com/ggilder/bitrot/bitrot.go:150.2,150.12 1 1
github.com/ggilder/bitrot/bitrot.go:153.56,155.26 2 1
github.com/ggilder/bitrot/bitrot.go:155.26,157.3 1 0
github.com/ggilder/bitrot/bitrot.go:158.2,160.16 3 1
github.com/ggilder/bitrot/bitrot.go:160.16,162.3 1 0
github.com/ggilder/bitrot/bitrot.go:164.2,165.16 2 1
github.com/ggilder/bitrot/bitrot.go:165.16,167.3 1 0
github.com/ggilder/bitrot/bitrot.go:169.2,170.16 2 1
github.com/ggilder/bitrot/bitrot.go:170.16,172.3 1 0
github.com/ggilder/bitrot/bitrot.go:174.2,175.16 2 1
github.com/ggilder/bitrot/bitrot.go:175.16,177.3 1 0
github.com/ggilder/bitrot/bitrot.go:179.2,184.17 5 1
github.com/ggilder/bitrot/bitrot.go:184.17,187.3 2 1
github.com/ggilder/bitrot/bitrot.go:187.8,189.3 1 1
github.com/ggilder/bitrot/bitrot.go:191.2,191.12 1 1
github.com/ggilder/bitrot/bitrot.go:194.71,196.26 2 1
github.com/ggilder/bitrot/bitrot.go:196.26,198.3 1 0
github.com/ggilder/bitrot/bitrot.go:199.2,203.16 4 1
github.com/ggilder/bitrot/bitrot.go:203.16,205.3 1 0
github.com/ggilder/bitrot/bitrot.go:207.2,208.16 2 1
github.com/ggilder/bitrot/bitrot.go:208.16,210.3 1 0
github.com/ggilder/bitrot/bitrot.go:212.2,213.16 2 1
github.com/ggilder/bitrot/bitrot.go:213.16,215.3 1 0
github.com/ggilder/bitrot/bitrot.go:217.2,218.16 2 1
github.com/ggilder/bitrot/bitrot.go:218.16,220.3 1 0
github.com/ggilder/bitrot/bitrot.go:222.2,222.24 1 1
github.com/ggilder/bitrot/bitrot.go:222.24,225.3 2 1
github.com/ggilder/bitrot/bitrot.go:226.2,226.24 1 1
github.com/ggilder/bitrot/bitrot.go:226.24,229.3 2 0
github.com/ggilder/bitrot/bitrot.go:231.2,236.17 5 1
github.com/ggilder/bitrot/bitrot.go:236.17,239.3 2 0
github.com/ggilder/bitrot/bitrot.go:239.8,241.3 1 1
github.com/ggilder/bitrot/bitrot.go:243.2,243.12 1 1
github.com/ggilder/bitrot/bitrot.go:246.60,247.20 1 1
github.com/ggilder/bitrot/bitrot.go:247.20,249.3 1 0
github.com/ggilder/bitrot/bitrot.go:252.95,254.16 2 0
github.com/ggilder/bitrot/bitrot.go:254.16,255.13 1 0
github.com/ggilder/bitrot/bitrot.go:259.13,264.27 3 0
github.com/ggilder/bitrot/bitrot.go:264.27,267.3 2 0
github.com/ggilder/bitrot/bitrot.go:268.2,298.16 7 0
github.com/ggilder/bitrot/bitrot.go:298.16,300.24 1 0
github.com/ggilder/bitrot/bitrot.go:300.24,302.4 1 0
github.com/ggilder/bitrot/bitrot.go:303.3,303.13 1 0
github.com/ggilder/bitrot/checksum.go:16.70,18.16 2 1
github.com/ggilder/bitrot/checksum.go:18.16,20.3 1 0
github.com/ggilder/bitrot/checksum.go:21.2,25.8 1 1
github.com/ggilder/bitrot/checksum.go:28.48,30.16 2 1
github.com/ggilder/bitrot/checksum.go:30.16,32.3 1 0
github.com/ggilder/bitrot/checksum.go:33.2,34.16 2 1
github.com/ggilder/bitrot/checksum.go:34.16,36.3 1 0
github.com/ggilder/bitrot/checksum.go:37.2,37.29 1 1
github.com/ggilder/bitrot/checksum.go:40.44,41.6 1 1
github.com/ggilder/bitrot/checksum.go:41.6,44.34 3 1
github.com/ggilder/bitrot/checksum.go:44.34,46.4 1 0
github.com/ggilder/bitrot/checksum.go:47.3,48.20 2 1
github.com/ggilder/bitrot/checksum.go:48.20,50.4 1 1
github.com/ggilder/bitrot/comparison_report.go:12.76,15.2 2 1
github.com/ggilder/bitrot/comparison_report.go:17.55,19.2 1 1
github.com/ggilder/bitrot/comparison_report.go:21.56,23.25 2 1
github.com/ggilder/bitrot/comparison_report.go:23.25,25.3 1 1
github.com/ggilder/bitrot/comparison_report.go:25.8,27.3 1 1
github.com/ggilder/bitrot/comparison_report.go:28.2,39.10 9 1
github.com/ggilder/bitrot/comparison_report.go:42.55,49.2 1 1
github.com/ggilder/bitrot/comparison_report.go:51.88,54.2 2 1
github.com/ggilder/bitrot/comparison_report.go:56.88,58.29 2 1
github.com/ggilder/bitrot/comparison_report.go:58.29,60.3 1 1
github.com/ggilder/bitrot/comparison_report.go:61.2,61.10 1 1
github.com/ggilder/bitrot/comparison_report.go:64.59,66.2 1 1
github.com/ggilder/bitrot/comparison_report.go:68.57,73.32 5 1
github.com/ggilder/bitrot/comparison_report.go:73.32,75.3 1 1
github.com/ggilder/bitrot/comparison_report.go:76.2,76.10 1 1
github.com/ggilder/bitrot/config.go:42.30,44.16 2 1
github.com/ggilder/bitrot/config.go:44.16,46.17 2 0
github.com/ggilder/bitrot/config.go:46.17,48.14 1 0
github.com/ggilder/bitrot/config.go:51.2,54.3 1 1
github.com/ggilder/bitrot/config.go:57.50,59.46 2 1
github.com/ggilder/bitrot/config.go:59.46,60.26 1 1
github.com/ggilder/bitrot/config.go:60.26,62.4 1 1
github.com/ggilder/bitrot/config.go:64.2,64.14 1 1
github.com/ggilder/bitrot/config.go:67.53,68.30 1 1
github.com/ggilder/bitrot/config.go:68.30,70.3 1 1
github.com/ggilder/bitrot/config.go:71.2,71.26 1 1
github.com/ggilder/bitrot/manifest.go:26.66,28.16 2 1
github.com/ggilder/bitrot/manifest.go:28.16,30.3 1 0
github.com/ggilder/bitrot/manifest.go:32.2,36.8 1 1
github.com/ggilder/bitrot/manifest.go:41.52,45.16 3 1
github.com/ggilder/bitrot/manifest.go:45.16,47.3 1 0
github.com/ggilder/bitrot/manifest.go:48.2,49.16 2 1
github.com/ggilder/bitrot/manifest.go:49.16,51.3 1 0
github.com/ggilder/bitrot/manifest.go:52.2,52.37 1 1
github.com/ggilder/bitrot/manifest.go:55.45,58.2 2 0
github.com/ggilder/bitrot/manifest.go:60.89,62.87 2 1
github.com/ggilder/bitrot/manifest.go:62.87,63.17 1 1
github.com/ggilder/bitrot/manifest.go:63.17,65.4 1 0
github.com/ggilder/bitrot/manifest.go:67.3,67.38 1 1
github.com/ggilder/bitrot/manifest.go:67.38,68.20 1 1
github.com/ggilder/bitrot/manifest.go:68.20,71.5 1 1
github.com/ggilder/bitrot/manifest.go:72.4,72.14 1 1
github.com/ggilder/bitrot/manifest.go:75.3,75.30 1 1
github.com/ggilder/bitrot/manifest.go:75.30,78.18 3 1
github.com/ggilder/bitrot/manifest.go:78.18,80.5 1 0
github.com/ggilder/bitrot/manifest.go:82.4,84.18 3 1
github.com/ggilder/bitrot/manifest.go:84.18,86.5 1 0
github.com/ggilder/bitrot/manifest.go:87.4,90.5 1 1
github.com/ggilder/bitrot/manifest.go:93.3,93.13 1 1
github.com/ggilder/bitrot/manifest.go:95.2,95.16 1 1
github.com/ggilder/bitrot/manifest.go:95.16,97.3 1 0
github.com/ggilder/bitrot/manifest.go:98.2,98.21 1 1
github.com/ggilder/bitrot/manifest_comparison.go:26.79,30.2 3 1
github.com/ggilder/bitrot/manifest_comparison.go:32.48,34.2 1 1
github.com/ggilder/bitrot/manifest_comparison.go:36.52,43.2 1 1
github.com/ggilder/bitrot/manifest_comparison.go:45.43,47.19 1 1
github.com/ggilder/bitrot/manifest_comparison.go:47.19,49.3 1 1
github.com/ggilder/bitrot/manifest_comparison.go:52.2,52.45 1 1
github.com/ggilder/bitrot/manifest_comparison.go:52.45,54.23 2 1
github.com/ggilder/bitrot/manifest_comparison.go:54.23,56.4 1 1
github.com/ggilder/bitrot/manifest_comparison.go:60.2,60.55 1 1
github.com/ggilder/bitrot/manifest_comparison.go:60.55,62.40 1 1
github.com/ggilder/bitrot/manifest_comparison.go:62.40,63.12 1 1
github.com/ggilder/bitrot/manifest_comparison.go:67.3,67.47 1 1
github.com/ggilder/bitrot/manifest_comparison.go:67.47,68.12 1 1
github.com/ggilder/bitrot/manifest_comparison.go:72.3,72.54 1 1
github.com/ggilder/bitrot/manifest_comparison.go:75.2,75.22 1 1
github.com/ggilder/bitrot/manifest_comparison.go:78.89,80.22 2 1
github.com/ggilder/bitrot/manifest_comparison.go:80.22,82.3 1 1
github.com/ggilder/bitrot/manifest_comparison.go:84.2,84.44 1 1
github.com/ggilder/bitrot/manifest_comparison.go:84.44,86.3 1 1
github.com/ggilder/bitrot/manifest_comparison.go:86.8,87.43 1 1
github.com/ggilder/bitrot/manifest_comparison.go:87.43,90.4 1 1
github.com/ggilder/bitrot/manifest_comparison.go:90.9,93.4 1 1
github.com/ggilder/bitrot/manifest_comparison.go:96.2,96.13 1 1
github.com/ggilder/bitrot/manifest_comparison.go:99.96,101.19 2 1
github.com/ggilder/bitrot/manifest_comparison.go:101.19,103.3 1 1
github.com/ggilder/bitrot/manifest_comparison.go:105.2,108.41 2 1
github.com/ggilder/bitrot/manifest_comparison.go:108.41,109.22 1 1
github.com/ggilder/bitrot/manifest_comparison.go:109.22,111.9 2 1
github.com/ggilder/bitrot/manifest_comparison.go:115.2,115.13 1 1
github.com/ggilder/bitrot/manifest_comparison.go:118.83,119.42 1 1
github.com/ggilder/bitrot/manifest_comparison.go:119.42,120.61 1 1
github.com/ggilder/bitrot/manifest_comparison.go:120.61,122.4 1 1
github.com/ggilder/bitrot/manifest_comparison.go:124.2,124.11 1 1
github.com/ggilder/bitrot/manifest_storage.go:42.55,44.2 1 1
github.com/ggilder/bitrot/manifest_storage.go:46.67,49.39 3 1
github.com/ggilder/bitrot/manifest_storage.go:49.39,51.17 2 1
github.com/ggilder/bitrot/manifest_storage.go:51.17,53.4 1 0
github.com/ggilder/bitrot/manifest_storage.go:55.3,58.5 1 1
github.com/ggilder/bitrot/manifest_storage.go:61.2,61.21 1 1
github.com/ggilder/bitrot/manifest_storage.go:64.65,66.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:66.16,68.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:70.2,71.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:71.16,73.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:74.2,77.57 3 1
github.com/ggilder/bitrot/manifest_storage.go:77.57,79.17 2 1
github.com/ggilder/bitrot/manifest_storage.go:79.17,81.4 1 0
github.com/ggilder/bitrot/manifest_storage.go:82.8,84.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:86.2,86.12 1 1
github.com/ggilder/bitrot/manifest_storage.go:89.81,91.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:91.16,93.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:95.2,96.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:96.16,98.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:99.2,101.29 2 1
github.com/ggilder/bitrot/manifest_storage.go:101.29,103.3 1 1
github.com/ggilder/bitrot/manifest_storage.go:104.2,104.45 1 1
github.com/ggilder/bitrot/manifest_storage.go:107.76,109.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:109.16,111.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:113.2,115.16 3 1
github.com/ggilder/bitrot/manifest_storage.go:115.16,117.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:118.2,118.23 1 1
github.com/ggilder/bitrot/manifest_storage.go:121.97,124.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:124.16,126.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:127.2,128.16 2 1
github.com/ggilder/bitrot/manifest_storage.go:128.16,130.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:131.2,131.8 1 1
github.com/ggilder/bitrot/manifest_storage.go:134.64,138.16 3 1
github.com/ggilder/bitrot/manifest_storage.go:138.16,140.3 1 0
github.com/ggilder/bitrot/manifest_storage.go:143.2,144.57 2 1
github.com/ggilder/bitrot/manifest_storage.go:144.57,148.17 3 1
github.com/ggilder/bitrot/manifest_storage.go:148.17,150.4 1 0
github.com/ggilder/bitrot/manifest_storage.go:151.3,151.52 1 1
github.com/ggilder/bitrot/manifest_storage.go:152.8,155.17 2 1
github.com/ggilder/bitrot/manifest_storage.go:155.17,157.4 1 0
github.com/ggilder/bitrot/manifest_storage.go:158.3,158.24 1 1
github.com/ggilder/bitrot/manifest_storage.go:158.24,160.4 1 0
github.com/ggilder/bitrot/manifest_storage.go:163.2,163.25 1 1
github.com/ggilder/bitrot/manifest_storage.go:166.62,170.2 3 1
github.com/ggilder/bitrot/manifest_storage.go:172.87,178.2 1 1
github.com/ggilder/bitrot/manifest_storage.go:181.40,186.2 4 1
6 changes: 3 additions & 3 deletions __tests__/utils/__snapshots__/clover.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`should parse Clover file 1`] = `
Array [
Object {
"file": "/var/www/html/app/Actions/MyAction.php",
"file": "app/Actions/MyAction.php",
"functions": Object {
"details": Array [
Object {
Expand Down Expand Up @@ -165,7 +165,7 @@ Array [
"title": "App\\\\Actions\\\\MyAction",
},
Object {
"file": "/var/www/html/app/Console/Kernel.php",
"file": "app/Console/Kernel.php",
"functions": Object {
"details": Array [
Object {
Expand All @@ -190,7 +190,7 @@ Array [
"title": "App\\\\Console\\\\Kernel",
},
Object {
"file": "/var/www/html/app/Events/MyEvent.php",
"file": "app/Events/MyEvent.php",
"functions": Object {
"details": Array [
Object {
Expand Down
Loading

0 comments on commit a5671c0

Please sign in to comment.