From 9a7e6722ccb47562939fae4a457bfde4d5745065 Mon Sep 17 00:00:00 2001 From: Trevor Guidry Date: Fri, 1 Nov 2024 12:21:34 -0400 Subject: [PATCH] SERVER-95851 Fix 0% coverage reports and pull requests have separate coveralls builds (#28737) GitOrigin-RevId: e44387453918d42d722da105670efccf61efe51a --- etc/evergreen_yml_components/definitions.yml | 14 ++++++++++ .../functions/code_coverage_data_process.py | 28 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/etc/evergreen_yml_components/definitions.yml b/etc/evergreen_yml_components/definitions.yml index 54c8551bd74..27542d496f3 100644 --- a/etc/evergreen_yml_components/definitions.yml +++ b/etc/evergreen_yml_components/definitions.yml @@ -584,6 +584,14 @@ functions: exec_timeout_secs: ${exec_timeout_secs} timeout_secs: ${timeout_secs} + "set code coverage expansion": &set_code_coverage_expansion + command: expansions.update + display_name: "set code coverage expansion" + params: + updates: + - key: gather_code_coverage_results + value: "true" + ### Set expansion macros used in each task. "set task expansion macros": &set_task_expansion_macros command: expansions.update @@ -1160,6 +1168,8 @@ functions: - key: aws_secret_remote value: ${mongodatafiles_aws_secret} - *f_expansions_write + - *set_code_coverage_expansion + - *f_expansions_write - *set_up_remote_credentials - *f_expansions_write - *determine_resmoke_jobs @@ -1188,6 +1198,8 @@ functions: - *f_expansions_write - *update_task_timeout - *f_expansions_write + - *set_code_coverage_expansion + - *f_expansions_write - command: expansions.update params: env: @@ -1412,6 +1424,8 @@ functions: - *get_version_expansions - *apply_version_expansions - *f_expansions_write + - *set_code_coverage_expansion + - *f_expansions_write - *bazel_coverage_sh "ninja compile sh": &ninja_compile_sh diff --git a/evergreen/functions/code_coverage_data_process.py b/evergreen/functions/code_coverage_data_process.py index 1fa4a249ff4..9341331d971 100755 --- a/evergreen/functions/code_coverage_data_process.py +++ b/evergreen/functions/code_coverage_data_process.py @@ -7,6 +7,7 @@ import sys import tarfile from urllib.request import urlretrieve +import git import requests import retry @@ -72,6 +73,31 @@ def main(): ) return 0 + should_gather_code_coverage = expansions.get("gather_code_coverage_results", False) + if not should_gather_code_coverage: + print("Missing 'gather_code_coverage_results' expansion, skipping code coverage.") + return 0 + + if not os.path.exists(".git"): + print("No git repo found in working directory. Code coverage needs git repo to function.") + return 1 + + repo = git.Repo() + head_sha = repo.head.object.hexsha + evergreen_revision = expansions.get("revision") + # We need all code coverage runs from the same patch to have the same commit on HEAD + # When different runs have different git SHAs they are grouped in different builds in coveralls. + # + # Because of the weird cloning we do to have a git repo present during code coverage tasks + # and the inconsistent behaviors of the local git state during evergreen patches and + # commit-queue runs. We need to always ensure that the HEAD matches the evergreen revision + # for consistency in coveralls. + if head_sha != evergreen_revision: + print("test not equal") + print(f"head_sha: {head_sha}") + print(f"evergreen revision: {evergreen_revision}") + repo.git.reset("--mixed", evergreen_revision) + disallowed_arches = {"s390x", "s390", "ppc64le", "ppc64", "ppc", "ppcle"} arch = platform.uname().machine.lower() print(f"Detected arch: {arch}") @@ -123,6 +149,8 @@ def main(): ) args.append(bazel_coverage_report_location) retry_coveralls_report(args) + # no gcda files are generated from bazel coverage so we can exit early here + return 0 scons_build_dir = os.path.join(workdir, "src", "build", "debug") if os.path.exists(scons_build_dir):