Skip to content

Commit a796faf

Browse files
author
Sascha Nowak
committed
FEATURE: Add clover code coverage action
1 parent 176b339 commit a796faf

17 files changed

Lines changed: 11718 additions & 976 deletions

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
- uses: actions/checkout@v3
2222
- uses: ./
2323
with:
24-
milliseconds: 1000
24+
filename: __tests__/clover.xml

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/gallium

CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 142 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,168 @@
1-
<p align="center">
2-
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
3-
</p>
1+
# Code Coverage Summary
2+
3+
A GitHub Action that reads Clover format code coverage files from your test
4+
suite and outputs a markdown summary. This summary can be posted as a Pull
5+
Request comment or included in Release Notes by other actions to give you an
6+
immediate insight into the health of your code without using a third-party site.
7+
Code Coverage Summary is designed for use with any test framework that outputs
8+
coverage in Clover XML format.
9+
The action has a build in feature to group coverage by package. This currently
10+
works with composer.json only.
11+
12+
## Inputs
13+
14+
### `filename`
15+
**Required**
16+
17+
A path to the code coverage file to analyse. Also supports using glob patterns to match multiple files. If there are any spaces in a path or filename this value must be in quotes.
18+
19+
20+
## Outputs
21+
22+
23+
### Markdown Example
24+
25+
<table>
26+
<tr>
27+
<th colspan="8">Code Coverage
28+
<tr>
29+
<th colspan="1">Package
30+
<th colspan="2">Lines
31+
<th colspan="2">Functions
32+
<th colspan="2">Classes
33+
<th colspan="1">Health
34+
<tr>
35+
<td>unknown
36+
<td align="center">96%
37+
<td align="right">26/27
38+
<td align="center">83%
39+
<td align="right">5/6
40+
<td align="center">93%
41+
<td align="right">31/33
42+
<td align="center">✅
43+
<tr>
44+
<td><strong>Summary
45+
<td align="center"><strong>96%
46+
<td align="right"><strong>26/27
47+
<td align="center"><strong>83%
48+
<td align="right"><strong>5/6
49+
<td align="center"><strong>93%
50+
<td align="right"><strong>31/33
51+
<td align="center"><strong>✅
52+
</table>
53+
<details>
54+
<summary>Code Coverage details</summary>
55+
<table>
56+
<tr>
57+
<th colspan="8">Code Coverage
58+
<tr>
59+
<th colspan="1">Class
60+
<th colspan="2">Lines
61+
<th colspan="2">Functions
62+
<th colspan="2">Classes
63+
<th colspan="1">Health
64+
<tr>
65+
<td colspan="8"><strong>unknown
66+
<tr>
67+
<td>Netlogix\Nxdummy\Exception\OptionNotFoundException
68+
<td align="center">NaN%
69+
<td align="right">0/0
70+
<td align="center">NaN%
71+
<td align="right">0/0
72+
<td align="center">NaN%
73+
<td align="right">0/0
74+
<td align="center">❌
75+
<tr>
76+
<td>Netlogix\Nxdummy\Options\MiddlewareOptions
77+
<td align="center">90%
78+
<td align="right">10/11
79+
<td align="center">66%
80+
<td align="right">2/3
81+
<td align="center">85%
82+
<td align="right">12/14
83+
<td align="center">✅
84+
<tr>
85+
<td>Netlogix\Nxdummy\Utility\UriUtility
86+
<td align="center">100%
87+
<td align="right">16/16
88+
<td align="center">100%
89+
<td align="right">3/3
90+
<td align="center">100%
91+
<td align="right">19/19
92+
<td align="center">🚀
93+
<tr>
94+
<td><strong>Summary
95+
<td align="center"><strong>96%
96+
<td align="right"><strong>26/27
97+
<td align="center"><strong>83%
98+
<td align="right"><strong>5/6
99+
<td align="center"><strong>93%
100+
<td align="right"><strong>31/33
101+
<td align="center"><strong>✅
102+
</table>
103+
</details>
104+
105+
## Usage
4106

5-
# Create a JavaScript Action using TypeScript
6-
7-
Use this template to bootstrap the creation of a TypeScript action.:rocket:
8-
9-
This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.
10-
11-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
12-
13-
## Create an action from this template
14-
15-
Click the `Use this Template` and provide the new repo details for your action
16-
17-
## Code in Main
18-
19-
> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
20-
21-
Install the dependencies
22-
```bash
23-
$ npm install
107+
```yaml
108+
name: Code Coverage Summary Report
109+
uses: saschanowak/CloverCodeCoverageSummary@v0.1.0
110+
with:
111+
filename: clover.xml
24112
```
25113
26-
Build the typescript and package it for distribution
27-
```bash
28-
$ npm run build && npm run package
114+
Add the following to your workflow to include the summary in the job summary:
115+
```yaml
116+
name: 'Add Code Coverage to Job Summary'
117+
run: cat code-coverage-results-merged.md >> $GITHUB_STEP_SUMMARY
29118
```
30119
31-
Run the tests :heavy_check_mark:
32-
```bash
33-
$ npm test
34-
35-
PASS ./index.test.js
36-
✓ throws invalid number (3ms)
37-
wait 500 ms (504ms)
38-
test runs (95ms)
39-
40-
...
120+
Add the following to your workflow to post the summary as a Pull Request comment:
121+
```yaml
122+
name: 'Add Code Coverage as PR Comment'
123+
uses: marocchino/sticky-pull-request-comment@v2
124+
if: github.event_name == 'pull_request'
125+
with:
126+
recreate: true
127+
path: code-coverage-results-merged.md
41128
```
42129
43-
## Change action.yml
130+
## Version Numbers
44131
45-
The action.yml defines the inputs and output for your action.
132+
Version numbers will be assigned according to the [Semantic Versioning](https://semver.org/) scheme.
133+
This means, given a version number MAJOR.MINOR.PATCH, we will increment the:
46134
47-
Update the action.yml with your name, description, inputs and outputs for your action.
135+
1. MAJOR version when we make incompatible API changes
136+
2. MINOR version when we add functionality in a backwards compatible manner
137+
3. PATCH version when we make backwards compatible bug fixes
48138
49-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
50139
51-
## Change the Code
140+
## Contributing
52141
53-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
142+
### Report Bugs
54143
55-
```javascript
56-
import * as core from '@actions/core';
57-
...
144+
Please make sure the bug is not already reported by searching existing [issues].
58145
59-
async function run() {
60-
try {
61-
...
62-
}
63-
catch (error) {
64-
core.setFailed(error.message);
65-
}
66-
}
146+
If you're unable to find an existing issue addressing the problem please [open a new one][new-issue]. Be sure to include a title and clear description, as much relevant information as possible, a workflow sample and any logs demonstrating the problem.
67147
68-
run()
69-
```
70148
71-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
149+
### Suggest an Enhancement
72150
73-
## Publish to a distribution branch
151+
Please [open a new issue][new-issue].
74152
75-
Actions are run from GitHub repos so we will checkin the packed dist folder.
76153
77-
Then run [ncc](https://github.com/zeit/ncc) and push the results:
78-
```bash
79-
$ npm run package
80-
$ git add dist
81-
$ git commit -a -m "prod dependencies"
82-
$ git push origin releases/v1
83-
```
154+
### Submit a Pull Request
84155
85-
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.
156+
Discuss your idea first, so that your changes have a good chance of being merged in.
86157
87-
Your action is now published! :rocket:
158+
Submit your pull request against the `main` branch.
88159

89-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
160+
Pull requests that include documentation and relevant updates to README.md are merged faster, because you won't have to wait for somebody else to complete your contribution.
90161

91-
## Validate
92-
93-
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
94-
95-
```yaml
96-
uses: ./
97-
with:
98-
milliseconds: 1000
99-
```
100162

101-
See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
163+
## License
102164

103-
## Usage:
165+
Code Coverage Summary is available under the MIT license, see the [LICENSE](LICENSE) file for more info.
104166

105-
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
167+
[issues]: https://github.com/irongut/CodeCoverageSummary/issues
168+
[new-issue]: https://github.com/irongut/CodeCoverageSummary/issues/new

__tests__/data/clover.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1681063500">
3+
<project timestamp="1681063500">
4+
<file name="Extensions/nxdummy/Classes/Exception/OptionNotFoundException.php">
5+
<class name="Netlogix\Nxdummy\Exception\OptionNotFoundException" namespace="global">
6+
<metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
7+
</class>
8+
<metrics loc="13" ncloc="13" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
9+
</file>
10+
<file name="Extensions/nxdummy/Classes/Options/MiddlewareOptions.php">
11+
<class name="Netlogix\Nxdummy\Options\MiddlewareOptions" namespace="global">
12+
<metrics complexity="5" methods="3" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="11" coveredstatements="10" elements="14" coveredelements="12"/>
13+
</class>
14+
<metrics loc="47" ncloc="47" classes="1" methods="3" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="11" coveredstatements="10" elements="14" coveredelements="12"/>
15+
</file>
16+
<file name="Extensions/nxdummy/Classes/Utility/UriUtility.php">
17+
<class name="Netlogix\Nxdummy\Utility\UriUtility" namespace="global">
18+
<metrics complexity="3" methods="3" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="16" coveredstatements="16" elements="19" coveredelements="19"/>
19+
</class>
20+
<metrics loc="50" ncloc="50" classes="1" methods="3" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="16" coveredstatements="16" elements="19" coveredelements="19"/>
21+
</file>
22+
<metrics files="3" loc="110" ncloc="110" classes="2" methods="6" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="27" coveredstatements="26" elements="33" coveredelements="31"/>
23+
</project>
24+
</coverage>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
<table>
3+
<tr>
4+
<th colspan="8">Code Coverage
5+
<tr>
6+
<th colspan="1">Package
7+
<th colspan="2">Lines
8+
<th colspan="2">Functions
9+
<th colspan="2">Classes
10+
<th colspan="1">Health
11+
<tr>
12+
<td>unknown
13+
<td align="center">96%
14+
<td align="right">26/27
15+
<td align="center">83%
16+
<td align="right">5/6
17+
<td align="center">93%
18+
<td align="right">31/33
19+
<td align="center">✅
20+
<tr>
21+
<td><strong>Summary
22+
<td align="center"><strong>96%
23+
<td align="right"><strong>26/27
24+
<td align="center"><strong>83%
25+
<td align="right"><strong>5/6
26+
<td align="center"><strong>93%
27+
<td align="right"><strong>31/33
28+
<td align="center"><strong>✅
29+
</table>
30+
<details>
31+
<summary>Code Coverage details</summary>
32+
<table>
33+
<tr>
34+
<th colspan="8">Code Coverage
35+
<tr>
36+
<th colspan="1">Class
37+
<th colspan="2">Lines
38+
<th colspan="2">Functions
39+
<th colspan="2">Classes
40+
<th colspan="1">Health
41+
<tr>
42+
<td colspan="8"><strong>unknown
43+
<tr>
44+
<td>Netlogix\Nxdummy\Exception\OptionNotFoundException
45+
<td align="center">NaN%
46+
<td align="right">0/0
47+
<td align="center">NaN%
48+
<td align="right">0/0
49+
<td align="center">NaN%
50+
<td align="right">0/0
51+
<td align="center">❌
52+
<tr>
53+
<td>Netlogix\Nxdummy\Options\MiddlewareOptions
54+
<td align="center">90%
55+
<td align="right">10/11
56+
<td align="center">66%
57+
<td align="right">2/3
58+
<td align="center">85%
59+
<td align="right">12/14
60+
<td align="center">✅
61+
<tr>
62+
<td>Netlogix\Nxdummy\Utility\UriUtility
63+
<td align="center">100%
64+
<td align="right">16/16
65+
<td align="center">100%
66+
<td align="right">3/3
67+
<td align="center">100%
68+
<td align="right">19/19
69+
<td align="center">🚀
70+
<tr>
71+
<td><strong>Summary
72+
<td align="center"><strong>96%
73+
<td align="right"><strong>26/27
74+
<td align="center"><strong>83%
75+
<td align="right"><strong>5/6
76+
<td align="center"><strong>93%
77+
<td align="right"><strong>31/33
78+
<td align="center"><strong>✅
79+
</table>
80+
</details>
81+

0 commit comments

Comments
 (0)