From ee1889e9a65fd48f26d793680593220fc550ffe3 Mon Sep 17 00:00:00 2001 From: Amulyam24 Date: Fri, 17 Sep 2021 14:28:34 +0530 Subject: [PATCH] junit-report --- Makefile | 3 ++- go.mod | 1 + go.sum | 1 + scripts/ci-test.sh | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 58a9eadf3a..c447ca04a7 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ REGISTRY ?= $(STAGING_REGISTRY) RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null) PULL_BASE_REF ?= $(RELEASE_TAG) # PULL_BASE_REF will be provided by Prow RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF) +REPORT_NAME := $(JUNIT_REPORT_NAME) TAG ?= dev ARCH ?= amd64 @@ -50,7 +51,7 @@ all: manager # Run tests test: generate fmt vet manifests - go test ./... -coverprofile cover.out + go test ./... -v 2>&1 | go-junit-report > $(REPORT_NAME).xml # Build manager binary manager: generate fmt vet diff --git a/go.mod b/go.mod index f90c72ccd5..cd885d36fd 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/IBM/vpc-go-sdk v0.1.1 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/go-logr/logr v0.4.0 + github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/onsi/ginkgo v1.16.4 github.com/onsi/gomega v1.13.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 7e2d08d473..470d037aea 100644 --- a/go.sum +++ b/go.sum @@ -398,6 +398,7 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= diff --git a/scripts/ci-test.sh b/scripts/ci-test.sh index 8fde415a6f..ff750afd7b 100755 --- a/scripts/ci-test.sh +++ b/scripts/ci-test.sh @@ -22,6 +22,27 @@ REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. # shellcheck source=../hack/ensure-go.sh source "${REPO_ROOT}/hack/ensure-go.sh" +# Directory to store JUnit XML test report. +JUNIT_REPORT_DIR=${JUNIT_REPORT_DIR:-} + +# If JUNIT_REPORT_DIR is unset, and ARTIFACTS is set, then have them match. +if [[ -z "${JUNIT_REPORT_DIR:-}" && -n "${ARTIFACTS:-}" ]]; then + JUNIT_REPORT_DIR="${ARTIFACTS}" +fi + +# Generate prefix for JUnit file name. +junitFilenamePrefix() { + if [[ -z "${JUNIT_REPORT_DIR}" ]]; then + echo "" + return + fi + mkdir -p "${JUNIT_REPORT_DIR}" + DATE=$( date | awk '{print $4}' | base64 ) + echo "${JUNIT_REPORT_DIR}/junit_$DATE" +} + +export JUNIT_REPORT_NAME=$(junitFilenamePrefix) + cd "${REPO_ROOT}" && \ source ./scripts/fetch_ext_bins.sh && \ fetch_tools && \