diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 000000000..f594aba0a --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,13 @@ +coverage: + require_ci_to_pass: no + wait_for_ci: no + status: + project: + default: + informational: true + patch: + default: + informational: true + +# When modifying this file, please validate using: +# make codecov-validate diff --git a/Makefile b/Makefile index 10da54301..1138764f2 100644 --- a/Makefile +++ b/Makefile @@ -367,6 +367,7 @@ test-unit: export UNIT_TEST_FAILFAST ?= true test-unit: export UNIT_TEST_RERUN_FAILS ?= true test-unit: export UNIT_TEST_USE_DEVELOPMENT_LOGGER ?= true test-unit: export UNIT_TEST_REPORT_CODECLIMATE ?= false +test-unit: export UNIT_TEST_REPORT_CODECOV ?= false test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list ./... | \ grep -v /vendor | \ grep -v /t/e2e | \ @@ -499,3 +500,6 @@ run-integration-tests: run-anvil: SHELL := /bin/sh run-anvil: docker-compose -f integration-tests/docker-compose.anvil.yml up --remove-orphans + +codecov-validate: + curl -X POST --data-binary @.codecov.yml https://codecov.io/validate diff --git a/_assets/ci/Jenkinsfile.tests b/_assets/ci/Jenkinsfile.tests index e9b9175e9..ed60f6cfd 100644 --- a/_assets/ci/Jenkinsfile.tests +++ b/_assets/ci/Jenkinsfile.tests @@ -35,6 +35,11 @@ pipeline { defaultValue: true, description: 'Should the job report test coverage to CodeClimate?' ) + booleanParam( + name: 'UNIT_TEST_REPORT_CODECOV', + defaultValue: true, + description: 'Should the job report test coverage to Codecov?' + ) booleanParam( name: 'UNIT_TEST_DRY_RUN', defaultValue: false, @@ -77,6 +82,7 @@ pipeline { UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}" UNIT_TEST_USE_DEVELOPMENT_LOGGER = "${params.UNIT_TEST_USE_DEVELOPMENT_LOGGER}" UNIT_TEST_REPORT_CODECLIMATE = "${params.UNIT_TEST_REPORT_CODECLIMATE}" + UNIT_TEST_REPORT_CODECOV = "${params.UNIT_TEST_REPORT_CODECOV}" UNIT_TEST_DRY_RUN = "${params.UNIT_TEST_DRY_RUN}" } @@ -166,11 +172,15 @@ pipeline { credentialsId: 'codeclimate-test-reporter-id', variable: 'CC_TEST_REPORTER_ID' ), + string( + credentialsId: 'codecov-repository-upload-token', + variable: 'CODECOV_TOKEN' + ), ]) { nix.shell('make test-unit V=1', pure: false) } sh "mv c.out test-coverage.out" - archiveArtifacts('test-coverage.out, coverage/codeclimate.json, test-coverage.html, coverage_merged.out') + archiveArtifacts('report_*.xml, test_*.log, test-coverage.out, coverage/codeclimate.json, test-coverage.html, coverage_merged.out') } } } } diff --git a/_assets/scripts/run_unit_tests.sh b/_assets/scripts/run_unit_tests.sh index fd0c13980..f66765aee 100755 --- a/_assets/scripts/run_unit_tests.sh +++ b/_assets/scripts/run_unit_tests.sh @@ -161,6 +161,17 @@ if [[ $UNIT_TEST_REPORT_CODECLIMATE == 'true' ]]; then cc-test-reporter after-build --prefix=github.com/status-im/status-go fi +if [[ $UNIT_TEST_REPORT_CODECOV == 'true' ]]; then + echo -e "${GRN}Uploading coverage report to Codecov${RST}" + # https://docs.codeclimate.com/docs/jenkins#jenkins-ci-builds + codecov_report_files_args="" + for file in report_*.xml; do + codecov_report_files_args+="--file ${file} " + done + codecov do-upload --token "${CODECOV_TOKEN}" --report-type test_results ${codecov_report_files_args} + codecov --token "${CODECOV_TOKEN}" -f ${final_coverage_report} -F "unit" +fi + # Generate report with test stats shopt -s globstar nullglob # Enable recursive globbing if [[ "${UNIT_TEST_COUNT}" -gt 1 ]]; then diff --git a/nix/overlay.nix b/nix/overlay.nix index 77da1a5f4..d8f6b2d1a 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -52,6 +52,7 @@ in rec { # Custom packages go-modvendor = callPackage ./pkgs/go-modvendor { }; cc-test-reporter = callPackage ./pkgs/cc-test-reporter { }; + codecov-cli = callPackage ./pkgs/codecov-cli { }; gomobile = (prev.gomobile.overrideAttrs (old: { patches = [ diff --git a/nix/pkgs/codecov-cli/default.nix b/nix/pkgs/codecov-cli/default.nix new file mode 100644 index 000000000..12fbf83e0 --- /dev/null +++ b/nix/pkgs/codecov-cli/default.nix @@ -0,0 +1,42 @@ +{ lib, stdenv, fetchurl }: + +let + platform = lib.getAttr builtins.currentSystem { + aarch64-linux = "linux-arm64"; + x86_64-linux = "linux"; + aarch64-darwin = "macos"; # There's no arm64 build for macOS, amd64 works on both + x86_64-darwin = "macos"; + }; + +in stdenv.mkDerivation rec { + pname = "codecov"; + version = "0.7.4"; + + src = fetchurl { + url = "https://cli.codecov.io/v${version}/${platform}/codecov"; + hash = lib.getAttr builtins.currentSystem { + aarch64-darwin = "sha256-CB1D8/zYF23Jes9sd6rJiadDg7nwwee9xWSYqSByAlU="; + x86_64-linux = "sha256-65AgCcuAD977zikcE1eVP4Dik4L0PHqYzOO1fStNjOw="; + aarch64-linux = "sha256-hALtVSXY40uTIaAtwWr7EXh7zclhK63r7a341Tn+q/g="; + }; + }; + + dontUnpack = true; + stripDebug = false; + dontStrip = true; # This is to prevent `Could not load PyInstaller's embedded PKG archive from the executable` error + + installPhase = '' + runHook preInstall + install -D $src $out/bin/codecov + chmod +x $out/bin/codecov + runHook postInstall + ''; + + meta = with lib; { + description = "Codecov CLI tool to upload coverage reports"; + homepage = "https://docs.codecov.com/docs/the-codecov-cli"; + license = licenses.asl20; + mainProgram = "codecov"; + platforms = ["aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin"]; + }; +} diff --git a/nix/shell.nix b/nix/shell.nix index 369a7d3f3..9a793ae62 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -21,7 +21,7 @@ in pkgs.mkShell { buildInputs = with pkgs; [ git jq which - go golangci-lint go-junit-report gopls go-bindata gomobileMod + go golangci-lint go-junit-report gopls go-bindata gomobileMod codecov-cli mockgen protobuf3_20 protoc-gen-go gotestsum go-modvendor openjdk cc-test-reporter ] ++ lib.optionals (stdenv.isDarwin) [ xcodeWrapper ];