Skip to content

Commit acff74b

Browse files
Merge pull request #411 from openshift/mtsre-1421-codecov
mtsre-1421 initial changes for codecov.io representation
2 parents e206b6a + 0e3318d commit acff74b

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

.codecov.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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"

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ENABLE_WEBHOOK?="false"
4646
ENABLE_MONITORING?="false"
4747
ENABLE_REMOTE_STORAGE_MOCK="true"
4848
WEBHOOK_PORT?=8080
49+
TESTOPTS?=-cover -race -v
4950

5051
# Container
5152
IMAGE_ORG?=quay.io/app-sre
@@ -154,7 +155,7 @@ lint:
154155
## Runs code-generators and unittests.
155156
test-unit: generate
156157
@echo "running unit tests..."
157-
./mage test:unit
158+
CGO_ENABLED=1 go test $(TESTOPTS) ./internal/... ./cmd/... ./pkg/...
158159
.PHONY: test-unit
159160

160161
## Runs the Integration testsuite against the current $KUBECONFIG cluster
@@ -304,3 +305,10 @@ push-image-%:
304305
# cleans the config/openshift folder for addon-operator-bundle openshift test folder
305306
clean-config-openshift:
306307
@rm -rf "config/openshift/*"
308+
309+
# ------------------
310+
##@ Codecov.io
311+
# ------------------
312+
.PHONY: coverage
313+
coverage:
314+
hack/codecov.sh

hack/codecov.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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-unit 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

0 commit comments

Comments
 (0)