Skip to content

Commit c990a76

Browse files
Merge pull request #107 from Dee-6777/kite-onboard-codecov
Prepare the repo for codecov.io representation
2 parents 1a39c9c + 8694fab commit c990a76

File tree

3 files changed

+91
-18
lines changed

3 files changed

+91
-18
lines changed

.codecov.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: no
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: "20...100"
9+
10+
status:
11+
project: no
12+
patch: no
13+
changes: no
14+
15+
parsers:
16+
gcov:
17+
branch_detection:
18+
conditional: yes
19+
loop: yes
20+
method: no
21+
macro: no
22+
23+
comment:
24+
layout: "reach,diff,flags,tree"
25+
behavior: default
26+
require_changes: no
27+
28+
ignore:
29+
- "**/mocks"
30+
- "**/zz_generated*.go"
31+

Makefile

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unexport GOFLAGS
22

33
GOOS?=linux
4+
TESTOPTS ?=
45
GOARCH?=amd64
56
GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS=
67
GOPATH := $(shell go env GOPATH)
@@ -34,25 +35,11 @@ tools:
3435

3536
.PHONY: test
3637
test:
37-
go test ./... -covermode=atomic -coverpkg=./... -v
38+
go test ./... -v $(TESTOPTS)
3839

39-
test-cover:
40-
go test -covermode=atomic -coverpkg=./... -coverprofile=coverage.out ./...
41-
42-
.PHONY: coverage-html
43-
cover-html:
44-
go tool cover -html=coverage.out
45-
46-
.PHONY:coverage
47-
coverage:test-cover
48-
@{ \
49-
set -e ;\
50-
REQ_COV=15.5 ;\
51-
TEST_COV=$$(go tool cover -func coverage.out | grep -F total | awk '{print substr($$3, 1, length($$3)-1)}' ) ;\
52-
if (( $$(echo "$$REQ_COV > $$TEST_COV" |bc -l) )); then echo "Error: Code Coverage is less"; exit 1 ;\
53-
else echo "Code Coverage Test Passed"; exit 0; fi ;\
54-
}
55-
@rm -rf coverage.out
40+
.PHONY: coverage
41+
coverage:
42+
hack/codecov.sh
5643

5744
# Installed using instructions from: https://golangci-lint.run/usage/install/#linux-and-windows
5845
getlint:

hack/codecov.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
REPO_ROOT=$(git rev-parse --show-toplevel)
8+
CI_SERVER_URL=https://prow.svc.ci.openshift.org/view/gcs/origin-ci-test
9+
COVER_PROFILE=${COVER_PROFILE:-coverage.out}
10+
JOB_TYPE=${JOB_TYPE:-"local"}
11+
12+
# Default concurrency to four threads. By default it's the number of procs,
13+
# which seems to be 16 in the CI env. Some consumers' coverage jobs were
14+
# regularly getting OOM-killed; so do this rather than boost the pod resources
15+
# unreasonably.
16+
COV_THREAD_COUNT=${COV_THREAD_COUNT:-4}
17+
make -C "${REPO_ROOT}" test TESTOPTS="-coverprofile=${COVER_PROFILE}.tmp -covermode=atomic -coverpkg=./... -p ${COV_THREAD_COUNT}"
18+
19+
# Remove generated files from coverage profile
20+
grep -v "zz_generated" "${COVER_PROFILE}.tmp" > "${COVER_PROFILE}"
21+
rm -f "${COVER_PROFILE}.tmp"
22+
23+
# Configure the git refs and job link based on how the job was triggered via prow
24+
if [[ "${JOB_TYPE}" == "presubmit" ]]; then
25+
echo "detected PR code coverage job for #${PULL_NUMBER}"
26+
REF_FLAGS="-P ${PULL_NUMBER} -C ${PULL_PULL_SHA}"
27+
JOB_LINK="${CI_SERVER_URL}/pr-logs/pull/${REPO_OWNER}_${REPO_NAME}/${PULL_NUMBER}/${JOB_NAME}/${BUILD_ID}"
28+
elif [[ "${JOB_TYPE}" == "postsubmit" ]]; then
29+
echo "detected branch code coverage job for ${PULL_BASE_REF}"
30+
REF_FLAGS="-B ${PULL_BASE_REF} -C ${PULL_BASE_SHA}"
31+
JOB_LINK="${CI_SERVER_URL}/logs/${JOB_NAME}/${BUILD_ID}"
32+
elif [[ "${JOB_TYPE}" == "local" ]]; then
33+
echo "coverage report available at ${COVER_PROFILE}"
34+
exit 0
35+
else
36+
echo "${JOB_TYPE} jobs not supported" >&2
37+
exit 1
38+
fi
39+
40+
# Configure certain internal codecov variables with values from prow.
41+
export CI_BUILD_URL="${JOB_LINK}"
42+
export CI_BUILD_ID="${JOB_NAME}"
43+
export CI_JOB_ID="${BUILD_ID}"
44+
45+
if [[ "${JOB_TYPE}" != "local" ]]; then
46+
if [[ -z "${ARTIFACT_DIR:-}" ]] || [[ ! -d "${ARTIFACT_DIR}" ]] || [[ ! -w "${ARTIFACT_DIR}" ]]; then
47+
echo '${ARTIFACT_DIR} must be set for non-local jobs, and must point to a writable directory' >&2
48+
exit 1
49+
fi
50+
curl -sS https://codecov.io/bash -o "${ARTIFACT_DIR}/codecov.sh"
51+
bash <(cat "${ARTIFACT_DIR}/codecov.sh") -Z -K -f "${COVER_PROFILE}" -r "${REPO_OWNER}/${REPO_NAME}" ${REF_FLAGS}
52+
else
53+
bash <(curl -s https://codecov.io/bash) -Z -K -f "${COVER_PROFILE}" -r "${REPO_OWNER}/${REPO_NAME}" ${REF_FLAGS}
54+
fi
55+

0 commit comments

Comments
 (0)