@backstage-community/plugin-code-coverage-backend 0.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1605 -0
- package/README.md +256 -0
- package/dist/index.cjs.js +650 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/migrations/20210302_init.js +65 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# code-coverage-backend
|
|
2
|
+
|
|
3
|
+
This is the backend part of the `code-coverage` plugin. It takes care of processing various coverage formats and standardizing them into a single json format, used by the frontend.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# From your Backstage root directory
|
|
9
|
+
yarn --cwd packages/backend add @backstage-community/plugin-code-coverage-backend
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
First create a `codecoverage.ts` file here: `packages/backend/src/plugins`. Now add the following as its content:
|
|
13
|
+
|
|
14
|
+
```diff
|
|
15
|
+
diff --git a/packages/backend/src/plugins/codecoverage.ts b/packages/backend/src/plugins/codecoverage.ts
|
|
16
|
+
--- /dev/null
|
|
17
|
+
+++ b/packages/backend/src/plugins/codecoverage.ts
|
|
18
|
+
@@ -0,0 +1,15 @@
|
|
19
|
+
+import { createRouter } from '@backstage-community/plugin-code-coverage-backend';
|
|
20
|
+
+import { Router } from 'express';
|
|
21
|
+
+import { PluginEnvironment } from '../types';
|
|
22
|
+
+
|
|
23
|
+
+export default async function createPlugin(
|
|
24
|
+
+ env: PluginEnvironment,
|
|
25
|
+
+): Promise<Router> {
|
|
26
|
+
+ return await createRouter({
|
|
27
|
+
+ config: env.config,
|
|
28
|
+
+ discovery: env.discovery,
|
|
29
|
+
+ database: env.database,
|
|
30
|
+
+ urlReader: env.reader,
|
|
31
|
+
+ logger: env.logger,
|
|
32
|
+
+ });
|
|
33
|
+
+}
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Finally we need to load the plugin in `packages/backend/src/index.ts`, make the following edits:
|
|
38
|
+
|
|
39
|
+
```diff
|
|
40
|
+
diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts
|
|
41
|
+
--- a/packages/backend/src/index.ts
|
|
42
|
+
+++ b/packages/backend/src/index.ts
|
|
43
|
+
@@ -28,6 +28,7 @@ import scaffolder from './plugins/scaffolder';
|
|
44
|
+
import proxy from './plugins/proxy';
|
|
45
|
+
import techdocs from './plugins/techdocs';
|
|
46
|
+
import search from './plugins/search';
|
|
47
|
+
+import codeCoverage from './plugins/codecoverage';
|
|
48
|
+
import { PluginEnvironment } from './types';
|
|
49
|
+
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
|
|
50
|
+
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
|
|
51
|
+
@@ -85,6 +86,9 @@ async function main() {
|
|
52
|
+
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
|
|
53
|
+
const searchEnv = useHotMemoize(module, () => createEnv('search'));
|
|
54
|
+
const appEnv = useHotMemoize(module, () => createEnv('app'));
|
|
55
|
+
+ const codeCoverageEnv = useHotMemoize(module, () =>
|
|
56
|
+
+ createEnv('code-coverage'),
|
|
57
|
+
+ );
|
|
58
|
+
|
|
59
|
+
const apiRouter = Router();
|
|
60
|
+
apiRouter.use('/catalog', await catalog(catalogEnv));
|
|
61
|
+
@@ -93,6 +97,7 @@ async function main() {
|
|
62
|
+
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
|
|
63
|
+
apiRouter.use('/proxy', await proxy(proxyEnv));
|
|
64
|
+
apiRouter.use('/search', await search(searchEnv));
|
|
65
|
+
+ apiRouter.use('/code-coverage', await codeCoverage(codeCoverageEnv));
|
|
66
|
+
|
|
67
|
+
apiRouter.use(notFoundHandler());
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## New Backend System
|
|
71
|
+
|
|
72
|
+
The code coverage backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up:
|
|
73
|
+
|
|
74
|
+
In your `packages/backend/src/index.ts` make the following changes:
|
|
75
|
+
|
|
76
|
+
```diff
|
|
77
|
+
+ backend.add(import('@backstage-community/plugin-code-coverage-backend'));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Configuring your entity
|
|
81
|
+
|
|
82
|
+
In order to use this plugin, you must set the `backstage.io/code-coverage` annotation.
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
metadata:
|
|
86
|
+
annotations:
|
|
87
|
+
backstage.io/code-coverage: enabled
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
There's a feature to only include files that are in VCS in the coverage report, this is helpful to not count generated files for example. To enable this set the `backstage.io/code-coverage` annotation to `scm-only`.
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
metadata:
|
|
94
|
+
annotations:
|
|
95
|
+
backstage.io/code-coverage: scm-only
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Note: It may be required to set the [`backstage.io/source-location` annotation](https://backstage.io/docs/features/software-catalog/well-known-annotations#backstageiosource-location), however this should generally not be needed.
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
### Adding a Cobertura report
|
|
103
|
+
|
|
104
|
+
POST a Cobertura XML file to `/report`
|
|
105
|
+
|
|
106
|
+
Example:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
// curl -X POST -H "Content-Type:text/xml" -d @cobertura.xml "localhost:7007/api/code-coverage/report?entity=component:default/entity-name&coverageType=cobertura"
|
|
110
|
+
{
|
|
111
|
+
"links": [
|
|
112
|
+
{
|
|
113
|
+
"href": "http://localhost:7007/api/code-coverage/report?entity=component:default/entity-name",
|
|
114
|
+
"rel": "coverage"
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Adding a JaCoCo report
|
|
121
|
+
|
|
122
|
+
POST a JaCoCo XML file to `/report`
|
|
123
|
+
|
|
124
|
+
Example:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
// curl -X POST -H "Content-Type:text/xml" -d @jacoco.xml "localhost:7007/api/code-coverage/report?entity=component:default/entity-name&coverageType=jacoco"
|
|
128
|
+
{
|
|
129
|
+
"links": [
|
|
130
|
+
{
|
|
131
|
+
"href": "http://localhost:7007/api/code-coverage/report?entity=component:default/entity-name",
|
|
132
|
+
"rel": "coverage"
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Adding a LCOV report
|
|
139
|
+
|
|
140
|
+
POST a LCOV INFO file to `/report`
|
|
141
|
+
|
|
142
|
+
Example:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
// curl -X POST -H "Content-Type:text/plain" -d @coverage.info "localhost:7007/api/code-coverage/report?entity=component:default/entity-name&coverageType=lcov"
|
|
146
|
+
{
|
|
147
|
+
"links": [
|
|
148
|
+
{
|
|
149
|
+
"href": "http://localhost:7007/api/code-coverage/report?entity=component:default/entity-name",
|
|
150
|
+
"rel": "coverage"
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Reading json coverage
|
|
157
|
+
|
|
158
|
+
GET `/report`
|
|
159
|
+
|
|
160
|
+
Example:
|
|
161
|
+
|
|
162
|
+
```json
|
|
163
|
+
// curl localhost:7007/api/code-coverage/report?entity=component:default/entity-name
|
|
164
|
+
{
|
|
165
|
+
"aggregate": {
|
|
166
|
+
"branch": {
|
|
167
|
+
"available": 0,
|
|
168
|
+
"covered": 0,
|
|
169
|
+
"missed": 0,
|
|
170
|
+
"percentage": 0
|
|
171
|
+
},
|
|
172
|
+
"line": {
|
|
173
|
+
"available": 5,
|
|
174
|
+
"covered": 4,
|
|
175
|
+
"missed": 1,
|
|
176
|
+
"percentage": 80
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"entity": {
|
|
180
|
+
"kind": "Component",
|
|
181
|
+
"name": "entity-name",
|
|
182
|
+
"namespace": "default"
|
|
183
|
+
},
|
|
184
|
+
"files": [
|
|
185
|
+
{
|
|
186
|
+
"branchHits": {},
|
|
187
|
+
"filename": "main.go",
|
|
188
|
+
"lineHits": {
|
|
189
|
+
"117": 12,
|
|
190
|
+
"142": 8,
|
|
191
|
+
"34": 8,
|
|
192
|
+
"42": 0,
|
|
193
|
+
"58": 6
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Coverage history
|
|
201
|
+
|
|
202
|
+
GET `/history`
|
|
203
|
+
|
|
204
|
+
Example
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
// curl localhost:7007/api/code-coverage/history?entity=component:default/entity-name
|
|
208
|
+
{
|
|
209
|
+
"entity": {
|
|
210
|
+
"kind": "Component",
|
|
211
|
+
"name": "entity-name",
|
|
212
|
+
"namespace": "default"
|
|
213
|
+
},
|
|
214
|
+
"history": [
|
|
215
|
+
{
|
|
216
|
+
"branch": {
|
|
217
|
+
"available": 0,
|
|
218
|
+
"covered": 0,
|
|
219
|
+
"missed": 0,
|
|
220
|
+
"percentage": 0
|
|
221
|
+
},
|
|
222
|
+
"line": {
|
|
223
|
+
"available": 299,
|
|
224
|
+
"covered": 116,
|
|
225
|
+
"missed": 183,
|
|
226
|
+
"percentage": 38.8
|
|
227
|
+
},
|
|
228
|
+
"timestamp": 1615490766141
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"branch": {
|
|
232
|
+
"available": 0,
|
|
233
|
+
"covered": 0,
|
|
234
|
+
"missed": 0,
|
|
235
|
+
"percentage": 0
|
|
236
|
+
},
|
|
237
|
+
"line": {
|
|
238
|
+
"available": 299,
|
|
239
|
+
"covered": 116,
|
|
240
|
+
"missed": 183,
|
|
241
|
+
"percentage": 38.8
|
|
242
|
+
},
|
|
243
|
+
"timestamp": 1615406307929
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Configuration
|
|
250
|
+
|
|
251
|
+
Configure the plugin in your `app-config.yaml`:
|
|
252
|
+
|
|
253
|
+
```yaml
|
|
254
|
+
codeCoverage:
|
|
255
|
+
bodySizeLimit: 100kb # Defaults to 100kb, see https://www.npmjs.com/package/body-parser#limit
|
|
256
|
+
```
|