feat_: Integrate Codecov (#5796)
* feat_: added `codecov-cli` nix derivation * feat_: added simple codecov configuration * feat_: add UNIT_TEST_REPORT_CODECOV ci flag * feat_: upload logs and reports to codecov
This commit is contained in:
parent
060918bcd4
commit
ea290d97ef
|
@ -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
|
4
Makefile
4
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
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
} }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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"];
|
||||
};
|
||||
}
|
|
@ -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 ];
|
||||
|
||||
|
|
Loading…
Reference in New Issue