Skip to content

Commit

Permalink
Add codecov automation (#167)
Browse files Browse the repository at this point in the history
* Add codecov automation

* Rename codecov check

* Add make test-coverage
  • Loading branch information
djaglowski committed Jun 8, 2021
1 parent 6c757ec commit 8312a95
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/codecov.yaml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ artifacts/*
.vscode/*
gen/
.idea/*
coverage.out
coverage.out.bak
coverage.txt.bak
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -91,4 +104,4 @@ for-all:
done

.PHONY: ci-check
ci-check: vet lint check-license
ci-check: vet lint check-license
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 8312a95

Please sign in to comment.