diff --git a/.github/codecov.yaml b/.github/codecov.yaml new file mode 100644 index 00000000..5960f02b --- /dev/null +++ b/.github/codecov.yaml @@ -0,0 +1,20 @@ +codecov: + require_ci_to_pass: yes + +ignore: + - "internal/tools/*" + +coverage: + precision: 1 + round: down + range: "70...100" + status: + project: + default: + target: auto + threshold: 0.5% + +comment: + layout: "reach,diff,flags,tree" + behavior: default + require_changes: yes \ No newline at end of file diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 00000000..6f67ca2a --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,50 @@ +name: Run CodeCov +on: + push: + branches: + - main + pull_request: +env: + # Path to where test results will be saved. + TEST_RESULTS: /tmp/test-results + # Default minimum version of Go to support. + DEFAULT_GO_VERSION: 1.15 +jobs: + test-coverage: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2.1.3 + with: + go-version: ${{ env.DEFAULT_GO_VERSION }} + - name: Checkout Repo + uses: actions/checkout@v2 + - name: Setup Environment + run: | + echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV + echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + - name: Module cache + uses: actions/cache@v2.1.6 + env: + cache-name: go-mod-cache + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }} + - name: Run coverage tests + run: | + make test-coverage + mkdir $TEST_RESULTS + cp coverage.out $TEST_RESULTS + cp coverage.txt $TEST_RESULTS + cp coverage.html $TEST_RESULTS + - name: Upload coverage report + uses: codecov/codecov-action@v1 + with: + file: ./coverage.txt + fail_ci_if_error: true + verbose: true + - name: Store coverage test output + uses: actions/upload-artifact@v2 + with: + name: opentelemetry-log-collection-test-output + path: ${{ env.TEST_RESULTS }} diff --git a/.gitignore b/.gitignore index 7d5a9674..f971b5d4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ artifacts/* .vscode/* gen/ .idea/* +coverage.out +coverage.out.bak +coverage.txt.bak diff --git a/Makefile b/Makefile index be7c4156..5406bae9 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ GOARCH=$(shell go env GOARCH) GIT_SHA=$(shell git rev-parse --short HEAD) PROJECT_ROOT = $(shell pwd) -ARTIFACTS = ${PROJECT_ROOT}/artifacts ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort ) ALL_SRC := $(shell find . -name '*.go' -type f | sort) ADDLICENSE=addlicense +ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./internal/tools' | sort) TOOLS_MOD_DIR := ./internal/tools .PHONY: install-tools @@ -23,14 +23,27 @@ test: vet test-only test-only: $(MAKE) for-all CMD="go test -race -coverprofile coverage.txt -coverpkg ./... ./..." +.PHONY: test-coverage +test-coverage: clean + @set -e; \ + printf "" > coverage.txt; \ + for dir in $(ALL_COVERAGE_MOD_DIRS); do \ + (cd "$${dir}" && \ + go list ./... \ + | grep -v third_party \ + | xargs go test -coverpkg=./... -covermode=atomic -coverprofile=coverage.out && \ + go tool cover -html=coverage.out -o coverage.html); \ + [ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \ + done; \ + sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt + .PHONY: bench bench: go test -benchmem -run=^$$ -bench ^* ./... .PHONY: clean clean: - rm -fr ./artifacts - $(MAKE) for-all CMD="rm -f coverage.txt coverage.html" + $(MAKE) for-all CMD="rm -f coverage.txt.* coverage.html coverage.out" .PHONY: tidy tidy: @@ -91,4 +104,4 @@ for-all: done .PHONY: ci-check -ci-check: vet lint check-license \ No newline at end of file +ci-check: vet lint check-license diff --git a/README.md b/README.md index 1f1dd2cf..13c5014d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # opentelemetry-log-collection + +[![codecov.io](https://codecov.io/gh/open-telemetry/opentelemetry-log-collection/coverage.svg?branch=main)](https://app.codecov.io/gh/open-telemetry/opentelemetry-log-collection?branch=main) + ## Status This project was originally developed by [observIQ](https://observiq.com/) under the name [Stanza](https://github.com/observIQ/stanza). It has been contributed to the OpenTelemetry project in order to accelerate development of the collector's log collection capabilities.