github.com/codeready-toolchain/api@v0.0.0-20240507023248-73662d6db2c5/make/test.mk (about) 1 ############################################################ 2 # 3 # (local) Tests 4 # 5 ############################################################ 6 7 .PHONY: test 8 ## runs the tests without coverage 9 test: 10 @echo "running the tests without coverage..." 11 $(Q)go test ${V_FLAG} -race $(shell go list ./...) -failfast 12 13 14 ############################################################ 15 # 16 # OpenShift CI Tests with Coverage 17 # 18 ############################################################ 19 20 # Output directory for coverage information 21 COV_DIR = $(OUT_DIR)/coverage 22 23 .PHONY: test-with-coverage 24 ## runs the tests with coverage 25 test-with-coverage: 26 @echo "running the tests with coverage..." 27 @-mkdir -p $(COV_DIR) 28 @-rm $(COV_DIR)/coverage.txt 29 $(Q)go test -vet off ${V_FLAG} $(shell go list ./...) -coverprofile=$(COV_DIR)/coverage.txt -covermode=atomic ./... 30 31 .PHONY: upload-codecov-report 32 # Uploads the test coverage reports to codecov.io. 33 # DO NOT USE LOCALLY: must only be called by OpenShift CI when processing new PR and when a PR is merged! 34 upload-codecov-report: 35 # Upload coverage to codecov.io. Since we don't run on a supported CI platform (Jenkins, Travis-ci, etc.), 36 # we need to provide the PR metadata explicitely using env vars used coming from https://github.com/openshift/test-infra/blob/master/prow/jobs.md#job-environment-variables 37 # 38 # Also: not using the `-F unittests` flag for now as it's temporarily disabled in the codecov UI 39 # (see https://docs.codecov.io/docs/flags#section-flags-in-the-codecov-ui) 40 env 41 ifneq ($(PR_COMMIT), null) 42 @echo "uploading test coverage report for pull-request #$(PULL_NUMBER)..." 43 bash <(curl -s https://codecov.io/bash) \ 44 -t $(CODECOV_TOKEN) \ 45 -f $(COV_DIR)/coverage.txt \ 46 -C $(PR_COMMIT) \ 47 -r $(REPO_OWNER)/$(REPO_NAME) \ 48 -P $(PULL_NUMBER) \ 49 -Z 50 else 51 @echo "uploading test coverage report after PR was merged..." 52 bash <(curl -s https://codecov.io/bash) \ 53 -t $(CODECOV_TOKEN) \ 54 -f $(COV_DIR)/coverage.txt \ 55 -C $(BASE_COMMIT) \ 56 -r $(REPO_OWNER)/$(REPO_NAME) \ 57 -Z 58 endif 59 60 CODECOV_TOKEN := "826c8011-d0bd-4223-b7e9-bc56dae66f3e" 61 REPO_OWNER := $(shell echo $$CLONEREFS_OPTIONS | jq '.refs[0].org') 62 REPO_NAME := $(shell echo $$CLONEREFS_OPTIONS | jq '.refs[0].repo') 63 BASE_COMMIT := $(shell echo $$CLONEREFS_OPTIONS | jq '.refs[0].base_sha') 64 PR_COMMIT := $(shell echo $$CLONEREFS_OPTIONS | jq '.refs[0].pulls[0].sha') 65 PULL_NUMBER := $(shell echo $$CLONEREFS_OPTIONS | jq '.refs[0].pulls[0].number')