Skip to content

Commit 692a8ef

Browse files
committed
feat(build/pipelines): add go/covdata pipeline
It leverages a go binary built with coverage instrumentation using the -cover build flag alongside its coverage data genreated to produce a statements by functions based report via the go tool covdata. Signed-off-by: Massimiliano Giovagnoli <massimiliano.giovagnoli@chainguard.dev>
1 parent 2a6744d commit 692a8ef

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

pkg/build/pipelines/go/README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
12
<!-- start:pipeline-reference-gen -->
23
# Pipeline Reference
34

45

56
- [go/build](#gobuild)
67
- [go/bump](#gobump)
8+
- [go/covdata](#gocovdata)
79
- [go/install](#goinstall)
810

911
## go/build
@@ -19,7 +21,7 @@ Run a build using the go compiler
1921
| buildmode | false | The -buildmode flag value. See "go help buildmode" for more information. | default |
2022
| deps | false | space separated list of go modules to update before building. example: github.com/foo/bar@v1.2.3 | |
2123
| experiments | false | A comma-separated list of Golang experiment names (ex: loopvar) to use when building the binary. | |
22-
| extra-args | false | A space-separated list of extra arguments for go build command. | |
24+
| extra-args | false | A space-separated list of extra arguments to pass to the go build command. | |
2325
| go-package | false | The go package to install | go |
2426
| install-dir | false | Directory where binaries will be installed | bin |
2527
| ldflags | false | List of [pattern=]arg to append to the go compiler with -ldflags | |
@@ -49,6 +51,17 @@ Bump go deps to a certain version
4951
| tidy | false | Run go mod tidy command before and after the bump | true |
5052
| tidy-compat | false | Set the go version for which the tidied go.mod and go.sum files should be compatible | |
5153

54+
## go/covdata
55+
56+
Get coverage data with the covdata go tool
57+
58+
### Inputs
59+
60+
| Name | Required | Description | Default |
61+
| ---- | -------- | ----------- | ------- |
62+
| cover-dir | false | The GOCOVERDIR path where coverage data files have been generated. It's required to be set as environment variable as well before running the Go binary. | /home/build |
63+
| package | false | The go package to install | go |
64+
5265
## go/install
5366

5467
Run a build using the go compiler
@@ -71,4 +84,4 @@ Run a build using the go compiler
7184
| version | false | Package version to install. This can be a version tag (v1.0.0), a commit hash or another ref (eg latest or HEAD). | |
7285

7386

74-
<!-- end:pipeline-reference-gen -->
87+
<!-- end:pipeline-reference-gen -->

pkg/build/pipelines/go/covdata.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Get coverage data with the covdata go tool
2+
3+
# Leave go off here, some packages pin to an older version. Let's just assume this gets injected elsewhere.
4+
needs:
5+
packages:
6+
- ${{inputs.package}}
7+
- busybox
8+
9+
inputs:
10+
package:
11+
description: The go package to install
12+
default: go
13+
cover-dir:
14+
description: The GOCOVERDIR path where coverage data files have been generated. It's required to be set as environment variable as well before running the Go binary.
15+
default: /home/build
16+
17+
pipeline:
18+
- runs: |
19+
cov=$(go tool covdata func -i ${{inputs.cover-dir}} | tail -1 | awk '{print $NF}' | sed 's|%||g')
20+
echo "Statements coverage: ${cov}%"

0 commit comments

Comments
 (0)