From 8c17b515174377842a5db061cc48045d186ecaf0 Mon Sep 17 00:00:00 2001 From: igor gaidaienko Date: Wed, 17 May 2023 16:21:01 +0300 Subject: [PATCH 1/3] Jenkinsfile,Makefile: add coverage flag --- Jenkinsfile | 14 ++++++++++++++ Makefile | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 273ad96a..f5b016b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,6 +86,7 @@ pipeline { STORJ_TEST_COCKROACH = 'cockroach://root@localhost:26257/postgres?sslmode=disable' STORJ_TEST_POSTGRES = 'postgres://postgres@localhost/postgres?sslmode=disable' STORJ_TEST_LOG_LEVEL = 'info' + COVERFLAGS = "${ env.BRANCH_NAME == 'main' ? '-coverprofile=.build/coverprofile ' : ''}" } steps { sh 'make test 2>&1 | tee .build/tests.json | xunit -out .build/tests.xml' @@ -95,6 +96,19 @@ pipeline { sh script: 'cat .build/tests.json | tparse -all -top -slow 100', returnStatus: true archiveArtifacts artifacts: '.build/tests.json' junit '.build/tests.xml' + + script { + if(fileExists(".build/coverprofile")){ + sh script: 'filter-cover-profile < .build/coverprofile > .build/clean.coverprofile', returnStatus: true + sh script: 'gocov convert .build/clean.coverprofile > .build/cover.json', returnStatus: true + sh script: 'gocov-xml < .build/cover.json > .build/cobertura.xml', returnStatus: true + cobertura coberturaReportFile: '.build/cobertura.xml', + lineCoverageTargets: '70, 60, 50', + autoUpdateHealth: false, + autoUpdateStability: false, + failUnhealthy: true + } + } } } } diff --git a/Makefile b/Makefile index 5d35fc96..029d4c05 100644 --- a/Makefile +++ b/Makefile @@ -162,7 +162,7 @@ SKIP_TESTSUITE ?= false .PHONY: test test: test-testsuite ## Test - go test -json=${JSON} -p 16 -parallel 4 -race -short=${SHORT} -timeout 10m -vet=off ./... + go test -json=${JSON} -cover -coverprofile=.build/coverprofile -p 16 -parallel 4 -race -short=${SHORT} -timeout 10m -vet=off ./... .PHONY: test-testsuite test-testsuite: ## Test testsuite @@ -174,7 +174,7 @@ endif .PHONY: test-testsuite-do test-testsuite-do: go vet ./... - go test -json=${JSON} -p 16 -parallel 4 -race -short=${SHORT} -timeout 10m -vet=off ./... + go test -json=${JSON} -cover -coverprofile=.build/coverprofile -p 16 -parallel 4 -race -short=${SHORT} -timeout 10m -vet=off ./... ##@ Local development/Public Jenkins/Verification From b566bb91b415deeb16215825dfd7c5b061a17ce4 Mon Sep 17 00:00:00 2001 From: igor gaidaienko Date: Thu, 18 May 2023 12:41:44 +0300 Subject: [PATCH 2/3] don`t fail the build --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f5b016b4..4507f810 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -106,7 +106,7 @@ pipeline { lineCoverageTargets: '70, 60, 50', autoUpdateHealth: false, autoUpdateStability: false, - failUnhealthy: true + failUnhealthy: false } } } From 8824cb2bf4b137147daa4034503ff1d6b0e5794c Mon Sep 17 00:00:00 2001 From: igor gaidaienko Date: Mon, 22 May 2023 13:11:21 +0300 Subject: [PATCH 3/3] add cobertura report for testsuite --- Jenkinsfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4507f810..96ec51b8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -134,6 +134,19 @@ pipeline { sh script: 'cat .build/testsuite.json | tparse -all -top -slow 100', returnStatus: true archiveArtifacts artifacts: '.build/testsuite.json' junit '.build/testsuite.xml' + + script { + if(fileExists(".build/coverprofile")){ + sh script: 'filter-cover-profile < .build/coverprofile > .build/clean.coverprofile', returnStatus: true + sh script: 'gocov convert .build/clean.coverprofile > .build/cover.json', returnStatus: true + sh script: 'gocov-xml < .build/cover.json > .build/cobertura.xml', returnStatus: true + cobertura coberturaReportFile: '.build/cobertura.xml', + lineCoverageTargets: '70, 60, 50', + autoUpdateHealth: false, + autoUpdateStability: false, + failUnhealthy: false + } + } } } }