You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add GitHub Actions usage; make start.sh CI-agnostic
Document a GitHub Actions workflow and the plugin's environment variables, and
rework scripts/start.sh to run under any CI (generic vars with Vela fallbacks).
Copy file name to clipboardExpand all lines: README.md
+105-1Lines changed: 105 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Currently, this plugin supports two coverage file format.
21
21
* jacoco for jvm based languages like java,kotlin,scala
22
22
* cobertura can be used for golang projects using [gocov-xml](https://github.com/AlekSi/gocov-xml) utility
23
23
24
-
This plugin works out of box for [Vela](https://github.com/go-vela),a CI/CD open-sourced by target
24
+
This plugin works out of the box with [Vela](https://github.com/go-vela) (a CI/CD platform open-sourced by Target), [GitHub Actions](#github-actions-usage), and any CI that can run a container.
25
25
26
26
## VELA Usage
27
27
@@ -94,6 +94,110 @@ Once you have coverage.xml same can be passed as an input to plugin shown below
94
94
|gh_api_key| false | | api key to auth for posting coverage comments<br><br>if not set, coverage details will not be commented on PR |
95
95
|module | false | \<empty string\> | sub-module to use if operating inside a multi-module project (e.g. gradle multi-project build) |
96
96
97
+
## GitHub Actions Usage
98
+
99
+
On GitHub Actions you generate the coverage report in a step, then run the plugin
100
+
image with the PR diff piped to its stdin. Posting the comment uses the built-in
101
+
`GITHUB_TOKEN`, so the job needs `pull-requests: write`.
102
+
103
+
Leave the base URL unset for public github.com (it defaults to
104
+
`https://api.github.com`). For GitHub Enterprise set `PARAMETER_GH_API_BASE_URL`
105
+
to your API root, e.g. `https://git.example.com/api/v3`.
106
+
107
+
### Go (cobertura)
108
+
109
+
[gocover-cobertura](https://github.com/boumenot/gocover-cobertura) converts a Go
110
+
coverage profile to cobertura in a single step (run via `go run`, nothing to install).
111
+
112
+
```yaml
113
+
name: pr-code-coverage
114
+
on:
115
+
pull_request:
116
+
117
+
permissions:
118
+
contents: read
119
+
pull-requests: write
120
+
121
+
jobs:
122
+
coverage:
123
+
runs-on: ubuntu-latest
124
+
# GITHUB_TOKEN is read-only on fork PRs, so restrict to same-repo PRs.
For JVM projects, generate a jacoco report instead and set
166
+
`PARAMETER_COVERAGE_TYPE=jacoco`, `PARAMETER_COVERAGE_FILE` to the jacoco XML, and
167
+
`PARAMETER_SOURCE_DIRS`to your source dir(s) (e.g. `src/main/java`).
168
+
169
+
### Environment variables
170
+
171
+
Outside Vela, configure the plugin with these environment variables (Vela's
172
+
`parameters:` map to the same `PARAMETER_*` names automatically):
173
+
174
+
| variable | required | description |
175
+
|---|---|---|
176
+
| `PARAMETER_COVERAGE_TYPE` | yes | `jacoco` or `cobertura` |
177
+
| `PARAMETER_COVERAGE_FILE` | yes | path to the coverage report |
178
+
| `PARAMETER_SOURCE_DIRS` | yes | comma-separated source dirs (see the cobertura `<source>` note above) |
179
+
| `PARAMETER_MODULE` | no | sub-module path in a multi-module project |
180
+
| `PARAMETER_GH_API_KEY` | no | token used to post the PR comment (`GITHUB_TOKEN` on Actions); `PLUGIN_GH_API_KEY` is also accepted. If unset, results only print to the console |
181
+
| `PARAMETER_GH_API_BASE_URL` | no | GitHub API root; defaults to `https://api.github.com`. For Enterprise use `https://HOST/api/v3` |
182
+
| `PARAMETER_DEBUG` | no | `true` for verbose path-matching logs |
183
+
| `BUILD_PULL_REQUEST_NUMBER` | no\* | PR number to comment on |
184
+
| `REPOSITORY_ORG` | no\* | repository owner |
185
+
| `REPOSITORY_NAME` | no\* | repository name |
186
+
187
+
\* required together for the PR comment; if any is missing the plugin only prints to the console.
188
+
189
+
### Using the container entrypoint directly
190
+
191
+
The image's default entrypoint (`scripts/start.sh`) can compute the diff for you
192
+
in any CI or a plain `docker run`. Point it at the target branch and it fetches,
193
+
diffs, and pipes the result to the plugin:
194
+
195
+
| variable | description |
196
+
|---|---|
197
+
| `PARAMETER_TARGET_BRANCH` | branch to diff against (Vela uses `VELA_PULL_REQUEST_TARGET` as a fallback) |
0 commit comments