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

Upload-process uses upload-coverage endpoint #551

Merged
merged 22 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
289 changes: 289 additions & 0 deletions codecov_cli/commands/combined_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
import logging
import os
import pathlib
import typing

import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.git import GitService
from codecov_cli.helpers.options import global_options
from codecov_cli.services.combined_upload import combined_upload_logic
from codecov_cli.types import CommandContext

logger = logging.getLogger("codecovcli")


def _turn_env_vars_into_dict(ctx, params, value):
return dict((v, os.getenv(v, None)) for v in value)


@click.command()
@click.option(
"--parent-sha",
help="SHA (with 40 chars) of what should be the parent of this commit",
)
@click.option(
"-P",
"--pr",
"--pull-request-number",
"pull_request_number",
help="Specify the pull request number mannually. Used to override pre-existing CI environment variables",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.pull_request_number,
)
@click.option(
"-B",
"--branch",
help="Branch to which this commit belongs to",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.branch,
)
@click.option(
"--code",
"--report-code",
"report_code",
help="The code of the report. If unsure, leave default",
default="default",
)
@click.option(
"--network-root-folder",
help="Root folder from which to consider paths on the network section",
type=click.Path(path_type=pathlib.Path),
default=pathlib.Path.cwd,
show_default="Current working directory",
)
@click.option(
"-s",
"--dir",
"--coverage-files-search-root-folder",
"--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,
show_default="Current Working Directory",
)
@click.option(
"--exclude",
"--coverage-files-search-exclude-folder",
"--files-search-exclude-folder",
"files_search_exclude_folders",
help="Folders to exclude from search",
type=click.Path(path_type=pathlib.Path),
multiple=True,
default=[],
)
@click.option(
"-f",
"--file",
"--coverage-files-search-direct-file",
"--files-search-direct-file",
"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,
default=[],
)
@click.option(
"--disable-search",
help="Disable search for coverage files. This is helpful when specifying what files you want to upload with the --file option.",
is_flag=True,
default=False,
)
@click.option(
"--disable-file-fixes",
help="Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets)",
is_flag=True,
default=False,
)
@click.option(
"-b",
"--build",
"--build-code",
"build_code",
cls=CodecovOption,
help="Specify the build number manually",
fallback_field=FallbackFieldEnum.build_code,
)
@click.option(
"--build-url",
"build_url",
cls=CodecovOption,
help="The URL of the build where this is running",
fallback_field=FallbackFieldEnum.build_url,
)
@click.option(
"--job-code",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.job_code,
)
@click.option(
"-n",
"--name",
help="Custom defined name of the upload. Visible in Codecov UI",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.build_code,
)
@click.option(
"-e",
"--env",
"--env-var",
"env_vars",
multiple=True,
callback=_turn_env_vars_into_dict,
help="Specify environment variables to be included with this build.",
)
@click.option(
"-F",
"--flag",
"flags",
multiple=True,
default=[],
help="Flag the upload to group coverage metrics. Multiple flags allowed.",
)
@click.option(
"--plugin",
"plugin_names",
multiple=True,
default=["xcode", "gcov", "pycoverage"],
)
@click.option(
"-d",
"--dry-run",
"dry_run",
is_flag=True,
help="Don't upload files to Codecov",
)
@click.option(
"--legacy",
"--use-legacy-uploader",
"use_legacy_uploader",
is_flag=True,
help="Use the legacy upload endpoint",
)
@click.option(
"--handle-no-reports-found",
"handle_no_reports_found",
is_flag=True,
help="Raise no excpetions when no coverage reports found.",
)
@click.option(
"--report-type",
help="The type of the file to upload, coverage by default. Possible values are: testing, coverage.",
default="coverage",
type=click.Choice(["coverage", "test_results"]),
)
@click.option(
"--network-filter",
help="Specify a filter on the files listed in the network section of the Codecov report. This will only add files whose path begin with the specified filter. Useful for upload-specific path fixing",
)
@click.option(
"--network-prefix",
help="Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing",
)
@click.option(
"--gcov-args",
help="Extra arguments to pass to gcov",
)
@click.option(
"--gcov-ignore",
help="Paths to ignore during gcov gathering",
)
@click.option(
"--gcov-include",
help="Paths to include during gcov gathering",
)
@click.option(
"--gcov-executable",
help="gcov executable to run. Defaults to 'gcov'",
)
@click.option(
"--swift-project",
help="Specify the swift project",
)
@global_options
@click.pass_context
def combined_upload(
ctx: CommandContext,
branch: typing.Optional[str],
build_code: typing.Optional[str],
build_url: typing.Optional[str],
commit_sha: str,
disable_file_fixes: bool,
disable_search: bool,
dry_run: bool,
env_vars: typing.Dict[str, str],
fail_on_error: bool,
files_search_exclude_folders: typing.List[pathlib.Path],
files_search_explicitly_listed_files: typing.List[pathlib.Path],
files_search_root_folder: pathlib.Path,
flags: typing.List[str],
gcov_args: typing.Optional[str],
gcov_executable: typing.Optional[str],
gcov_ignore: typing.Optional[str],
gcov_include: typing.Optional[str],
git_service: typing.Optional[str],
handle_no_reports_found: bool,
job_code: typing.Optional[str],
name: typing.Optional[str],
network_filter: typing.Optional[str],
network_prefix: typing.Optional[str],
network_root_folder: pathlib.Path,
parent_sha: typing.Optional[str],
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
report_code: str,
report_type: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
token: typing.Optional[str],
use_legacy_uploader: bool,
):
versioning_system = ctx.obj["versioning_system"]
codecov_yaml = ctx.obj["codecov_yaml"] or {}
cli_config = codecov_yaml.get("cli", {})
ci_adapter = ctx.obj.get("ci_adapter")
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
combined_upload_logic(
cli_config,
versioning_system,
ci_adapter,
branch=branch,
build_code=build_code,
build_url=build_url,
commit_sha=commit_sha,
disable_file_fixes=disable_file_fixes,
disable_search=disable_search,
dry_run=dry_run,
enterprise_url=enterprise_url,
env_vars=env_vars,
fail_on_error=fail_on_error,
files_search_exclude_folders=files_search_exclude_folders,
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
files_search_root_folder=files_search_root_folder,
flags=flags,
gcov_args=gcov_args,
gcov_executable=gcov_executable,
gcov_ignore=gcov_ignore,
gcov_include=gcov_include,
git_service=git_service,
handle_no_reports_found=handle_no_reports_found,
job_code=job_code,
name=name,
network_filter=network_filter,
network_prefix=network_prefix,
network_root_folder=network_root_folder,
parent_sha=parent_sha,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
report_code=report_code,
slug=slug,
swift_project=swift_project,
token=token,
upload_file_type=report_type,
use_legacy_uploader=use_legacy_uploader,
args=args,
)
40 changes: 40 additions & 0 deletions codecov_cli/commands/upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import click

from codecov_cli.commands.combined_upload import combined_upload
from codecov_cli.commands.commit import create_commit
from codecov_cli.commands.report import create_report
from codecov_cli.commands.upload import do_upload, global_upload_options
Expand Down Expand Up @@ -67,6 +68,45 @@ def upload_process(
),
)

if not use_legacy_uploader and report_type == "coverage":
ctx.invoke(
combined_upload,
branch=branch,
build_code=build_code,
build_url=build_url,
commit_sha=commit_sha,
disable_file_fixes=disable_file_fixes,
disable_search=disable_search,
dry_run=dry_run,
env_vars=env_vars,
fail_on_error=fail_on_error,
files_search_exclude_folders=files_search_exclude_folders,
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
files_search_root_folder=files_search_root_folder,
flags=flags,
gcov_args=gcov_args,
gcov_executable=gcov_executable,
gcov_ignore=gcov_ignore,
gcov_include=gcov_include,
git_service=git_service,
handle_no_reports_found=handle_no_reports_found,
job_code=job_code,
name=name,
network_filter=network_filter,
network_prefix=network_prefix,
network_root_folder=network_root_folder,
parent_sha=parent_sha,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
report_code=report_code,
report_type=report_type,
slug=slug,
swift_project=swift_project,
token=token,
use_legacy_uploader=use_legacy_uploader,
)
return

ctx.invoke(
create_commit,
commit_sha=commit_sha,
Expand Down
Loading
Loading