Skip to content

Commit a389cf7

Browse files
authored
[chore][codecov] Add darwin-test (#6072)
* [chore][codecov] Add coverage to darwin-test * Add coverage upload step * Update Makefile
1 parent 4e98082 commit a389cf7

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

.github/workflows/darwin-test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@ jobs:
5151
make install-tools
5252
mkdir -p unit-test-results-${{ matrix.OS }}/junit
5353
trap "go-junit-report -set-exit-code < unit-test-results-${{ matrix.OS }}/go-unit-tests.out > unit-test-results-${{ matrix.OS }}/junit/results.xml" EXIT
54-
make for-all CMD="make test-without-race" | tee unit-test-results-${{ matrix.OS }}/go-unit-tests.out
54+
make gotest-cover-without-race | tee unit-test-results-${{ matrix.OS }}/go-unit-tests.out
5555
5656
- name: Uploading artifacts
5757
uses: actions/upload-artifact@v4
5858
with:
5959
name: unit-test-results-${{ matrix.OS }}
6060
path: ./unit-test-results-${{ matrix.OS }}
6161

62+
- name: Upload coverage report
63+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # 5.4.0
64+
env:
65+
fail_ci_if_error: true
66+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
67+
6268
- name: bundle.d
6369
run: |
6470
make bundle.d

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ gotest-with-cover:
139139
@$(MAKE) for-all-target TARGET="test-with-codecov"
140140
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt
141141

142+
.PHONY: gotest-cover-without-race
143+
gotest-cover-without-race:
144+
@$(MAKE) for-all-target TARGET="test-cover-without-race"
145+
$(GOCMD) tool covdata textfmt -i=./coverage -o ./coverage.txt
146+
142147
.PHONY: gendependabot
143148
gendependabot:
144149
.github/workflows/scripts/gendependabot.sh

Makefile.Common

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ endif
2323
# SRC_ROOT is the top of the source tree.
2424
SRC_ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
2525

26-
# COVER_PKGS is the list of packages to include in the coverage
27-
COVER_PKGS := $(shell go list ./... | tr "\n" ",")
2826

2927
# build tags required by any component should be defined as an independent variables and later added to GO_BUILD_TAGS below
3028
GO_BUILD_TAGS=""
@@ -43,6 +41,11 @@ IMPI=impi
4341
# BUILD_TYPE should be one of (dev, release).
4442
BUILD_TYPE?=release
4543

44+
# COVER_PKGS is the list of packages to include in the test coverage
45+
COVER_PKGS := $(shell go list ./... | tr "\n" ",")
46+
COVER_DIR?=$(PWD)/coverage
47+
COVER_OPTS?=-cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(COVER_DIR)"
48+
4649
ALL_PKG_DIRS := $(shell $(GOCMD) list -f '{{ .Dir }}' ./... | $(NORMALIZE_DIRS))
4750

4851
ALL_SRC := $(shell find $(ALL_PKG_DIRS) -name '*.go' \
@@ -86,9 +89,10 @@ test-with-codecov:
8689
# Currently, running CGO_ENABLED=0 go test -race is broken in gopsutil/v4
8790
# This target should be removed in favor of "test" once the following issue is resolved:
8891
# https://github.com/shirou/gopsutil/issues/1774
89-
.PHONY: test-without-race
90-
test-without-race:
91-
$(GOTEST) $(GOTEST_OPT_WITHOUT_RACE) $(ALL_PKG_DIRS)
92+
.PHONY: test-cover-without-race
93+
test-cover-without-race:
94+
mkdir -p $(COVER_DIR)
95+
$(GOTEST) $(GOTEST_OPT_WITHOUT_RACE) ./... $(COVER_OPTS)
9296

9397
.PHONY: addlicense
9498
addlicense:

internal/signalfx-agent/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ GOTEST_OPT_WITHOUT_RACE?= -v -timeout 180s --tags=$(GO_BUILD_TAGS)
1111

1212
# COVER_PKGS is the list of packages to include in the coverage
1313
COVER_PKGS := $(shell $(GOCMD) list ./... | tr "\n" ",")
14+
COVER_DIR?=$(PWD)/coverage
15+
COVER_OPTS?=-cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(COVER_DIR)"
1416

1517
.PHONY: clean
1618
clean:
@@ -60,9 +62,10 @@ test-race-detector:
6062
# Currently, running CGO_ENABLED=0 go test -race is broken in gopsutil/v4
6163
# This target should be removed in favor of "test" once the following issue is resolved:
6264
# https://github.com/shirou/gopsutil/issues/1774
63-
.PHONY: test-without-race
64-
test-without-race:
65-
$(GOTEST) $(GOTEST_OPT_WITHOUT_RACE) ./...
65+
.PHONY: test-cover-without-race
66+
test-cover-without-race:
67+
mkdir -p $(COVER_DIR)
68+
$(GOTEST) $(GOTEST_OPT_WITHOUT_RACE) ./... $(COVER_OPTS)
6669

6770
.PHONY: check
6871
check: lint vet test

0 commit comments

Comments
 (0)