Skip to content

Commit 7a36fea

Browse files
authored
Merge pull request #3295 from buildkite/ming/te-3708-follow-up
TE-3708-follow-up: Use go test -cover to generate coverage report
2 parents 56b13bb + 478f618 commit 7a36fea

File tree

3 files changed

+78
-17
lines changed

3 files changed

+78
-17
lines changed

.buildkite/pipeline.yml

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ steps:
2323
key: test-linux-amd64
2424
command: ".buildkite/steps/tests.sh"
2525
parallelism: 2
26-
artifact_paths: junit-*.xml
26+
artifact_paths:
27+
- junit-*.xml
28+
- "coverage/**/*"
2729
plugins:
2830
- docker-compose#v4.14.0:
2931
config: .buildkite/docker-compose.yml
@@ -33,14 +35,14 @@ steps:
3335
- test-collector#v1.2.0:
3436
files: "junit-*.xml"
3537
format: "junit"
36-
- artifacts#v1.9.0:
37-
upload: "cover.{html,out}"
3838

3939
- name: ":linux: Linux ARM64 Tests"
4040
key: test-linux-arm64
4141
command: ".buildkite/steps/tests.sh"
4242
parallelism: 2
43-
artifact_paths: junit-*.xml
43+
artifact_paths:
44+
- junit-*.xml
45+
- "coverage/**/*"
4446
agents:
4547
queue: $AGENT_RUNNERS_LINUX_ARM64_QUEUE
4648
plugins:
@@ -52,15 +54,15 @@ steps:
5254
- test-collector#v1.2.0:
5355
files: "junit-*.xml"
5456
format: "junit"
55-
- artifacts#v1.9.0:
56-
upload: "cover.{html,out}"
5757

5858
- name: ":satellite: Detect Data Races"
5959
key: test-race-linux-arm64
6060
command: ".buildkite/steps/tests.sh -race"
6161
# Extra parallelism because this data race test is slow
6262
parallelism: 3
63-
artifact_paths: junit-*.xml
63+
artifact_paths:
64+
- junit-*.xml
65+
- "coverage/**/*"
6466
agents:
6567
queue: $AGENT_RUNNERS_LINUX_ARM64_QUEUE
6668
plugins:
@@ -72,22 +74,71 @@ steps:
7274
- test-collector#v1.2.0:
7375
files: "junit-*.xml"
7476
format: "junit"
75-
- artifacts#v1.9.0:
76-
upload: "cover.{html,out}"
7777

7878
- name: ":windows: Windows AMD64 Tests"
7979
key: test-windows
8080
command: "bash .buildkite\\steps\\tests.sh"
8181
parallelism: 2
82-
artifact_paths: junit-*.xml
82+
artifact_paths:
83+
- junit-*.xml
84+
- "coverage/**/*"
8385
agents:
8486
queue: $AGENT_RUNNERS_WINDOWS_QUEUE
8587
plugins:
8688
- test-collector#v1.2.0:
8789
files: "junit-*.xml"
8890
format: "junit"
89-
- artifacts#v1.9.0:
90-
upload: "cover.{html,out}"
91+
92+
- name: ":coverage: Test coverage report Linux ARM64"
93+
key: test-coverage-linux-arm64
94+
command: ".buildkite/steps/test-coverage-report.sh"
95+
artifact_paths:
96+
- "cover.html"
97+
- "cover.out"
98+
depends_on:
99+
- test-linux-arm64
100+
plugins:
101+
- docker-compose#v4.14.0:
102+
config: .buildkite/docker-compose.yml
103+
cli-version: 2
104+
run: agent
105+
- artifacts#v1.9.4:
106+
download: "coverage/**"
107+
step: test-linux-arm64
108+
109+
- name: ":coverage: Test coverage report Linux AMD64"
110+
key: test-coverage-linux-amd64
111+
command: ".buildkite/steps/test-coverage-report.sh"
112+
artifact_paths:
113+
- "cover.html"
114+
- "cover.out"
115+
depends_on:
116+
- test-linux-amd64
117+
plugins:
118+
- docker-compose#v4.14.0:
119+
config: .buildkite/docker-compose.yml
120+
cli-version: 2
121+
run: agent
122+
- artifacts#v1.9.4:
123+
download: "coverage/**"
124+
step: test-linux-amd64
125+
126+
- name: ":coverage: Test coverage report Linux ARM64 Race"
127+
key: test-coverage-linux-arm64-race
128+
command: ".buildkite/steps/test-coverage-report.sh"
129+
artifact_paths:
130+
- "cover.html"
131+
- "cover.out"
132+
depends_on:
133+
- test-race-linux-arm64
134+
plugins:
135+
- docker-compose#v4.14.0:
136+
config: .buildkite/docker-compose.yml
137+
cli-version: 2
138+
run: agent
139+
- artifacts#v1.9.4:
140+
download: "coverage/**"
141+
step: test-race-linux-arm64
91142

92143
- label: ":writing_hand: Annotate with Test Failures"
93144
depends_on:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo 'Producing coverage report'
5+
go tool covdata textfmt -i "coverage" -o cover.out
6+
go tool cover -html cover.out -o cover.html

.buildkite/steps/tests.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ go install gotest.tools/gotestsum@v1.8.0
88

99
go install github.com/buildkite/test-engine-client@v1.5.0-rc.3
1010

11-
echo '+++ Running tests'
1211
export BUILDKITE_TEST_ENGINE_SUITE_SLUG=buildkite-agent
1312
export BUILDKITE_TEST_ENGINE_TEST_RUNNER=gotest
1413
export BUILDKITE_TEST_ENGINE_RESULT_PATH="junit-${BUILDKITE_JOB_ID}.xml"
1514
export BUILDKITE_TEST_ENGINE_RETRY_COUNT=1
16-
export BUILDKITE_TEST_ENGINE_TEST_CMD="gotestsum --junitfile={{resultPath}} -- -count=1 -coverprofile=cover.out $@ {{packages}}"
15+
if [[ "$(go env GOOS)" == "windows" ]]; then
16+
# I can't get windows to work with the $COVERAGE_DIR, I tried cygpath but no luck.
17+
# need a Windows VM to debug.
18+
export BUILDKITE_TEST_ENGINE_TEST_CMD="gotestsum --junitfile={{resultPath}} -- -count=1 $* {{packages}}"
19+
else
20+
mkdir -p coverage
21+
COVERAGE_DIR="$PWD/coverage"
22+
export BUILDKITE_TEST_ENGINE_TEST_CMD="gotestsum --junitfile={{resultPath}} -- -count=1 -cover $* {{packages}} -test.gocoverdir=${COVERAGE_DIR}"
23+
fi
1724

1825
test-engine-client
19-
20-
echo 'Producing coverage report'
21-
go tool cover -html cover.out -o cover.html

0 commit comments

Comments
 (0)