From e47e0cef2555542ca5ce55703f4d9761c86648e4 Mon Sep 17 00:00:00 2001 From: Julien Pinsonneau <91894519+jpinsonneau@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:35:05 +0200 Subject: [PATCH] codecov v4 (#650) --- .github/workflows/pull_request.yml | 4 ++-- .github/workflows/push_image.yml | 24 ++++++++++++++++++++++++ .gitignore | 2 +- Makefile | 13 +++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e14bebd3c..064370c87 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -31,8 +31,8 @@ jobs: run: go mod vendor - name: upload coverage to codecov.io if: ${{ matrix.go == '1.21' }} - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: - files: /tmp/coverage.out + files: ./cover.out flags: unittests fail_ci_if_error: true diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index 8e065edcd..bd04bb39f 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -40,3 +40,27 @@ jobs: if [[ "main" == "$WF_VERSION" ]]; then MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=latest make images fi + + codecov: + name: Codecov upload + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.21'] + steps: + - name: install make + run: sudo apt-get install make + - name: set up go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: checkout + uses: actions/checkout@v3 + - name: Test + run: make tests-unit coverage-report + - name: Report coverage + uses: codecov/codecov-action@v4 + with: + files: ./cover.out + flags: unittests + fail_ci_if_error: false diff --git a/.gitignore b/.gitignore index 48bfcafbc..16ce1e8da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /flowlogs-pipeline /confgenerator /bin/ - +cover.out diff --git a/Makefile b/Makefile index 3b77a3ee4..4d8285033 100644 --- a/Makefile +++ b/Makefile @@ -129,8 +129,7 @@ clean: ## Clean rm -f "${FLP_BIN_FILE}" go clean ./... -# note: to review coverage execute: go tool cover -html=/tmp/coverage.out -TEST_OPTS := -race -coverpkg=./... -covermode=atomic -coverprofile=/tmp/coverage.out +TEST_OPTS := -race -coverpkg=./... -covermode=atomic -coverprofile cover.out .PHONY: tests-unit tests-unit: validate_go ## Unit tests # tests may rely on non-thread safe libs such as go-ipfix => no -race flag @@ -138,6 +137,16 @@ tests-unit: validate_go ## Unit tests # enabling CGO is required for -race flag CGO_ENABLED=1 go test -p 1 $(TEST_OPTS) $$(go list ./... | grep -v /e2e | grep -v /testnorace) +.PHONY: coverage-report +coverage-report: ## Generate coverage report + @echo "### Generating coverage report" + go tool cover --func=./cover.out + +.PHONY: coverage-report-html +coverage-report-html: ## Generate HTML coverage report + @echo "### Generating HTML coverage report" + go tool cover --html=./cover.out + .PHONY: tests-fast tests-fast: TEST_OPTS= tests-fast: tests-unit ## Fast unit tests (no race tests / coverage)