Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support test result ingestion in the CLI #324

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions codecov_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def _turn_env_vars_into_dict(ctx, params, value):


_global_upload_options = [
click.option(
"--type",
"--upload-file-type",
"upload_file_type",
help="The type of file to search for an upload. Uploads coverage files by default",
type=click.Choice(["coverage", "testing"]),
default="coverage",
),
click.option(
"--report-code",
help="The code of the report. If unsure, leave default",
Expand All @@ -34,7 +42,7 @@ def _turn_env_vars_into_dict(ctx, params, value):
"-s",
"--dir",
"--coverage-files-search-root-folder",
"coverage_files_search_root_folder",
"files_search_root_folder",
help="Folder where to search for coverage files",
type=click.Path(path_type=pathlib.Path),
default=pathlib.Path.cwd,
Expand All @@ -43,7 +51,7 @@ def _turn_env_vars_into_dict(ctx, params, value):
click.option(
"--exclude",
"--coverage-files-search-exclude-folder",
"coverage_files_search_exclude_folders",
"files_search_exclude_folders",
help="Folders to exclude from search",
type=click.Path(path_type=pathlib.Path),
multiple=True,
Expand All @@ -53,7 +61,7 @@ def _turn_env_vars_into_dict(ctx, params, value):
"-f",
"--file",
"--coverage-files-search-direct-file",
"coverage_files_search_explicitly_listed_files",
"files_search_explicitly_listed_files",
help="Explicit files to upload. These will be added to the coverage files found for upload. If you wish to only upload the specified files, please consider using --disable-search to disable uploading other files.",
type=click.Path(path_type=pathlib.Path),
multiple=True,
Expand Down Expand Up @@ -172,6 +180,7 @@ def global_upload_options(func):
def do_upload(
ctx: click.Context,
commit_sha: str,
upload_file_type: str,
report_code: str,
build_code: typing.Optional[str],
build_url: typing.Optional[str],
Expand All @@ -180,9 +189,9 @@ def do_upload(
flags: typing.List[str],
name: typing.Optional[str],
network_root_folder: pathlib.Path,
coverage_files_search_root_folder: pathlib.Path,
coverage_files_search_exclude_folders: typing.List[pathlib.Path],
coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path],
files_search_root_folder: pathlib.Path,
files_search_exclude_folders: typing.List[pathlib.Path],
files_search_explicitly_listed_files: typing.List[pathlib.Path],
disable_search: bool,
disable_file_fixes: bool,
token: typing.Optional[uuid.UUID],
Expand All @@ -205,6 +214,7 @@ def do_upload(
"Starting upload processing",
extra=dict(
extra_log_attributes=dict(
upload_file_type=upload_file_type,
commit_sha=commit_sha,
report_code=report_code,
build_code=build_code,
Expand All @@ -214,9 +224,9 @@ def do_upload(
flags=flags,
name=name,
network_root_folder=network_root_folder,
coverage_files_search_root_folder=coverage_files_search_root_folder,
coverage_files_search_exclude_folders=coverage_files_search_exclude_folders,
coverage_files_search_explicitly_listed_files=coverage_files_search_explicitly_listed_files,
files_search_root_folder=files_search_root_folder,
files_search_exclude_folders=files_search_exclude_folders,
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
plugin_names=plugin_names,
token=token,
branch=branch,
Expand All @@ -235,6 +245,7 @@ def do_upload(
versioning_system,
ci_adapter,
commit_sha=commit_sha,
upload_file_type=upload_file_type,
report_code=report_code,
build_code=build_code,
build_url=build_url,
Expand All @@ -243,13 +254,9 @@ def do_upload(
flags=flags,
name=name,
network_root_folder=network_root_folder,
coverage_files_search_root_folder=coverage_files_search_root_folder,
coverage_files_search_exclude_folders=list(
coverage_files_search_exclude_folders
),
coverage_files_search_explicitly_listed_files=list(
coverage_files_search_explicitly_listed_files
),
files_search_root_folder=files_search_root_folder,
files_search_exclude_folders=list(files_search_exclude_folders),
files_search_explicitly_listed_files=list(files_search_explicitly_listed_files),
plugin_names=plugin_names,
token=token,
branch=branch,
Expand Down
18 changes: 9 additions & 9 deletions codecov_cli/commands/upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def upload_process(
flags: typing.List[str],
name: typing.Optional[str],
network_root_folder: pathlib.Path,
coverage_files_search_root_folder: pathlib.Path,
coverage_files_search_exclude_folders: typing.List[pathlib.Path],
coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path],
files_search_root_folder: pathlib.Path,
files_search_exclude_folders: typing.List[pathlib.Path],
files_search_explicitly_listed_files: typing.List[pathlib.Path],
disable_search: bool,
disable_file_fixes: bool,
token: typing.Optional[uuid.UUID],
Expand Down Expand Up @@ -63,9 +63,9 @@ def upload_process(
flags=flags,
name=name,
network_root_folder=network_root_folder,
coverage_files_search_root_folder=coverage_files_search_root_folder,
coverage_files_search_exclude_folders=coverage_files_search_exclude_folders,
coverage_files_search_explicitly_listed_files=coverage_files_search_explicitly_listed_files,
files_search_root_folder=files_search_root_folder,
files_search_exclude_folders=files_search_exclude_folders,
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
plugin_names=plugin_names,
token=token,
branch=branch,
Expand Down Expand Up @@ -111,9 +111,9 @@ def upload_process(
flags=flags,
name=name,
network_root_folder=network_root_folder,
coverage_files_search_root_folder=coverage_files_search_root_folder,
coverage_files_search_exclude_folders=coverage_files_search_exclude_folders,
coverage_files_search_explicitly_listed_files=coverage_files_search_explicitly_listed_files,
files_search_root_folder=files_search_root_folder,
files_search_exclude_folders=files_search_exclude_folders,
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
disable_search=disable_search,
token=token,
plugin_names=plugin_names,
Expand Down
2 changes: 1 addition & 1 deletion codecov_cli/helpers/folder_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def search_files(
this_is_excluded = functools.partial(
_is_excluded, filename_exclude_regex, multipart_exclude_regex
)
for (dirpath, dirnames, filenames) in os.walk(folder_to_search):
for dirpath, dirnames, filenames in os.walk(folder_to_search):
dirs_to_remove = set(d for d in dirnames if d in folders_to_ignore)

if multipart_exclude_regex is not None:
Expand Down
125 changes: 105 additions & 20 deletions codecov_cli/services/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@
from codecov_cli.helpers.request import log_warnings_and_errors_if_any
from codecov_cli.helpers.versioning_systems import VersioningSystemInterface
from codecov_cli.plugins import select_preparation_plugins
from codecov_cli.services.upload.coverage_file_finder import select_coverage_file_finder
from codecov_cli.services.upload.finders.coverage_file_finder import (
select_coverage_file_finder,
)
from codecov_cli.services.upload.legacy_upload_sender import LegacyUploadSender
from codecov_cli.services.upload.network_finder import select_network_finder
from codecov_cli.services.upload.upload_collector import UploadCollector
from codecov_cli.services.upload.finders.network_finder import select_network_finder
from codecov_cli.services.upload.collectors.legacy_upload_collector import (
LegacyUploadCollector,
)
from codecov_cli.services.upload.finders.testing_result_file_finder import (
select_testing_result_file_finder,
)
from codecov_cli.services.upload.collectors.testing_result_upload_collector import (
TestingResultUploadCollector,
)
from codecov_cli.services.upload.collectors.coverage_upload_collector import (
CoverageUploadCollector,
)
from codecov_cli.services.upload.upload_sender import UploadSender
from codecov_cli.services.upload_completion import upload_completion_logic
from codecov_cli.types import RequestResult
Expand All @@ -26,6 +39,7 @@ def do_upload_logic(
versioning_system: VersioningSystemInterface,
ci_adapter: CIAdapterBase,
*,
upload_file_type: str,
commit_sha: str,
report_code: str,
build_code: typing.Optional[str],
Expand All @@ -35,9 +49,9 @@ def do_upload_logic(
flags: typing.List[str],
name: typing.Optional[str],
network_root_folder: Path,
coverage_files_search_root_folder: Path,
coverage_files_search_exclude_folders: typing.List[Path],
coverage_files_search_explicitly_listed_files: typing.List[Path],
files_search_root_folder: Path,
files_search_exclude_folders: typing.List[Path],
files_search_explicitly_listed_files: typing.List[Path],
plugin_names: typing.List[str],
token: uuid.UUID,
branch: typing.Optional[str],
Expand All @@ -52,23 +66,32 @@ def do_upload_logic(
handle_no_reports_found: bool = False,
disable_file_fixes: bool = False,
):
preparation_plugins = select_preparation_plugins(cli_config, plugin_names)
coverage_file_selector = select_coverage_file_finder(
coverage_files_search_root_folder,
coverage_files_search_exclude_folders,
coverage_files_search_explicitly_listed_files,
disable_search,
)
network_finder = select_network_finder(versioning_system)
collector = UploadCollector(
preparation_plugins, network_finder, coverage_file_selector, disable_file_fixes
)
try:
upload_data = collector.generate_upload_data()
if upload_file_type == "coverage":
upload_data = prepare_coverage_data(
cli_config,
plugin_names,
files_search_root_folder,
files_search_exclude_folders,
files_search_explicitly_listed_files,
disable_search,
versioning_system,
use_legacy_uploader,
disable_file_fixes,
env_vars,
)
else:
upload_data = prepare_testing_result_data(
files_search_root_folder,
files_search_exclude_folders,
files_search_explicitly_listed_files,
disable_search,
)
except click.ClickException as exp:
if handle_no_reports_found:
logger.info(
"No coverage reports found. Triggering notificaions without uploading."
"No reports found. Triggering notificaions without uploading.",
extra={"upload_type": upload_file_type},
)
upload_completion_logic(
commit_sha=commit_sha,
Expand All @@ -82,15 +105,17 @@ def do_upload_logic(
error=None,
warnings=None,
status_code=200,
text="No coverage reports found. Triggering notificaions without uploading.",
text=f"No {upload_file_type} reports found. Triggering notificaions without uploading.",
)
else:
raise exp

if use_legacy_uploader:
sender = LegacyUploadSender()
else:
sender = UploadSender()
logger.debug(f"Selected uploader to use: {type(sender)}")

ci_service = (
ci_adapter.get_fallback_value(FallbackFieldEnum.service)
if ci_adapter is not None
Expand All @@ -99,6 +124,7 @@ def do_upload_logic(

if not dry_run:
sending_result = sender.send_upload_data(
upload_file_type,
upload_data,
commit_sha,
token,
Expand Down Expand Up @@ -126,3 +152,62 @@ def do_upload_logic(
)
log_warnings_and_errors_if_any(sending_result, "Upload", fail_on_error)
return sending_result


def prepare_testing_result_data(
search_root_folder,
search_exclude_folders,
search_explicit,
disable_search,
):
testing_result_file_finder = select_testing_result_file_finder(
search_root_folder,
search_exclude_folders,
search_explicit,
disable_search,
)

collector = TestingResultUploadCollector(testing_result_file_finder)

return collector.generate_payload_data()


def prepare_coverage_data(
cli_config,
plugin_names,
search_root_folder,
search_exclude_folders,
search_explicit,
disable_search,
versioning_system,
use_legacy,
disable_file_fixes,
env_vars,
):
coverage_file_selector = select_coverage_file_finder(
search_root_folder,
search_exclude_folders,
search_explicit,
disable_search,
)
network_finder = select_network_finder(versioning_system)

if use_legacy:
Collector = LegacyUploadCollector
else:
Collector = CoverageUploadCollector

collector = Collector(
network_finder,
coverage_file_selector,
disable_file_fixes,
env_vars,
)

preparation_plugins = select_preparation_plugins(cli_config, plugin_names)

for prep in preparation_plugins:
logger.debug(f"Running preparation plugin: {type(prep)}")
prep.run_preparation(collector)

return collector.generate_upload_data()
Loading