Skip to content

Commit 71eaf3a

Browse files
authored
Re-enable codecov for test coverage (#4125)
Codecov was disabled here due to security concerns: https://github.com/open-telemetry/opentelemetry-collector/pull/3014/files This new PR no longer downloads the codecov script from a remote location so is no longer susceptible to the same problem.
1 parent 87c8b6f commit 71eaf3a

File tree

8 files changed

+58
-15
lines changed

8 files changed

+58
-15
lines changed

.codecov.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ coverage:
1717

1818
ignore:
1919
- "service/internal/zpages/tmplgen/**/*"
20-
- "*/**/metadata/generated_metrics.go"
21-
- "internal/data/protogen/**/*"
22-
- "testbed/**/*"
20+
- "model/internal/data/protogen/**/*"
2321
- "*/**/third_party/**/*"

.github/workflows/build-and-test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ jobs:
124124
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
125125
- name: Run Unit Tests
126126
run: make gotest
127+
test-coverage:
128+
runs-on: ubuntu-latest
129+
needs: [setup-environment]
130+
steps:
131+
- name: Checkout Repo
132+
uses: actions/checkout@v2
133+
- name: Setup Go
134+
uses: actions/[email protected]
135+
with:
136+
go-version: 1.17
137+
- name: Setup Go Environment
138+
run: |
139+
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
140+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
141+
- name: Cache Go
142+
id: module-cache
143+
uses: actions/cache@v2
144+
env:
145+
cache-name: cache-go-modules
146+
with:
147+
path: |
148+
/home/runner/go/pkg/mod
149+
/home/runner/.cache/go-build
150+
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
151+
- name: Cache Tools
152+
id: tool-cache
153+
uses: actions/cache@v2
154+
env:
155+
cache-name: cache-tool-binaries
156+
with:
157+
path: /home/runner/go/bin
158+
key: tools-${{ runner.os }}-${{ hashFiles('./internal/tools/go.mod', './cmd/mdatagen/go.mod', './cmd/mdatagen/*.go') }}
159+
- name: Run Unit Tests With Coverage
160+
run: make gotest-with-cover
161+
- name: Upload coverage report
162+
uses: codecov/[email protected]
163+
with:
164+
file: ./coverage.txt
165+
fail_ci_if_error: true
166+
verbose: true
127167
cross-compile:
128168
runs-on: ubuntu-latest
129169
needs: [setup-environment]

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ dist/
1818
*.DS_Store
1919

2020
# Coverage
21+
coverage.out
2122
coverage.txt
22-
coverage_all.txt
23-
coverage_old.txt
2423
coverage.html
2524

2625
# Wix

Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ include ./Makefile.Common
22

33
# This is the code that we want to run lint, etc.
44
ALL_SRC := $(shell find . -name '*.go' \
5-
-not -path './cmd/schemagen/*' \
65
-not -path './internal/tools/*' \
7-
-not -path './examples/demo/app/*' \
86
-not -path './model/internal/data/protogen/*' \
97
-not -path './service/internal/zpages/tmplgen/*' \
108
-type f | sort)
@@ -31,8 +29,8 @@ CONTRIB_PATH=$(CURDIR)/../opentelemetry-collector-contrib
3129
COMP_REL_PATH=service/defaultcomponents/defaults.go
3230
MOD_NAME=go.opentelemetry.io/collector
3331

34-
GO_ACC=go-acc
3532
ADDLICENSE=addlicense
33+
GOCOVMERGE=gocovmerge
3634
MISSPELL=misspell -error
3735
MISSPELL_CORRECTION=misspell -w
3836

@@ -70,10 +68,8 @@ gobenchmark:
7068

7169
.PHONY: gotest-with-cover
7270
gotest-with-cover:
73-
@echo pre-compiling tests
74-
@time $(GOTEST) -i ./...
75-
$(GO_ACC) ./...
76-
go tool cover -html=coverage.txt -o coverage.html
71+
@$(MAKE) for-all CMD="make test-with-cover"
72+
$(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt
7773

7874
.PHONY: golint
7975
golint:
@@ -133,8 +129,9 @@ install-tools:
133129
cd $(TOOLS_MOD_DIR) && go install github.com/ory/go-acc
134130
cd $(TOOLS_MOD_DIR) && go install github.com/pavius/impi/cmd/impi
135131
cd $(TOOLS_MOD_DIR) && go install github.com/tcnksm/ghr
136-
cd $(TOOLS_MOD_DIR) && go install go.opentelemetry.io/build-tools/semconvgen
132+
cd $(TOOLS_MOD_DIR) && go install github.com/wadey/gocovmerge
137133
cd $(TOOLS_MOD_DIR) && go install go.opentelemetry.io/build-tools/checkdoc
134+
cd $(TOOLS_MOD_DIR) && go install go.opentelemetry.io/build-tools/semconvgen
138135
cd $(TOOLS_MOD_DIR) && go install golang.org/x/exp/cmd/apidiff
139136
cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/cmd/goimports
140137

Makefile.Common

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ ALL_PKGS := $(sort $(shell go list ./...))
55
# wide resources, e.g. ports.
66
GOTEST_OPT?= -v -p 1 -race -timeout 60s
77
GOTEST=go test
8+
GO_ACC=go-acc
89
LINT=golangci-lint
910
IMPI=impi
1011

1112
.PHONY: test
1213
test:
13-
@echo $(ALL_PKGS) | xargs -n 10 $(GOTEST) $(GOTEST_OPT)
14+
$(GOTEST) $(GOTEST_OPT) ./...
1415

1516
.PHONY: test-unstable
1617
test-unstable:
17-
@echo $(ALL_PKGS) | xargs -n 10 $(GOTEST) $(GOTEST_OPT) -tags enable_unstable
18+
$(GOTEST) $(GOTEST_OPT) -tags enable_unstable ./...
19+
20+
.PHONY: test-with-cover
21+
test-with-cover:
22+
$(GO_ACC) --output=coverage.out ./...
1823

1924
.PHONY: benchmark
2025
benchmark:

internal/tools/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/ory/go-acc v0.2.6
1111
github.com/pavius/impi v0.0.3
1212
github.com/tcnksm/ghr v0.14.0
13+
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad
1314
go.opentelemetry.io/build-tools/checkdoc v0.0.0-20210826185254-a20c5b1e2d7c
1415
go.opentelemetry.io/build-tools/semconvgen v0.0.0-20210813222030-0139980e9794
1516
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5

internal/tools/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl
737737
github.com/valyala/quicktemplate v1.6.3/go.mod h1:fwPzK2fHuYEODzJ9pkw0ipCPNHZ2tD5KW4lOuSdPKzY=
738738
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
739739
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE=
740+
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad h1:W0LEBv82YCGEtcmPA3uNZBI33/qF//HAAs3MawDjRa0=
741+
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad/go.mod h1:Hy8o65+MXnS6EwGElrSRjUzQDLXreJlzYLlWiHtt8hM=
740742
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
741743
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
742744
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=

internal/tools/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
_ "github.com/ory/go-acc"
3131
_ "github.com/pavius/impi/cmd/impi"
3232
_ "github.com/tcnksm/ghr"
33+
_ "github.com/wadey/gocovmerge"
3334
_ "go.opentelemetry.io/build-tools/checkdoc"
3435
_ "go.opentelemetry.io/build-tools/semconvgen"
3536
_ "golang.org/x/exp/cmd/apidiff"

0 commit comments

Comments
 (0)