Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov authored Dec 2, 2024
2 parents f3d1f16 + 87d5916 commit 13edc25
Show file tree
Hide file tree
Showing 54 changed files with 844 additions and 128 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_for_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
- name: Publish package to PyPi
if: inputs.publish == true
uses: pypa/gh-action-pypi-publish@release/v1



with:
attestations: false
verbose: true
12 changes: 3 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install dependencies
- name: Check linting with ruff
run: |
python -m pip install --upgrade pip
pip install black==22.3.0 isort==5.10.1
- name: Check linting with black
run: |
black --check codecov_cli
- name: Check imports order with isort
run: |
isort --check --profile=black codecov_cli -p staticcodecov_languages
make lint
codecov-startup:
runs-on: ubuntu-latest
Expand Down
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ name ?= codecovcli
# Semantic versioning format https://semver.org/
tag_regex := ^v([0-9]{1,}\.){2}[0-9]{1,}([-_]\w+)?$

lint.install:
echo "Installing ruff..."
pip install -Iv ruff

# The preferred method (for now) w.r.t. fixable rules is to manually update the makefile
# with --fix and re-run 'make lint.' Since ruff is constantly adding rules this is a slight
# amount of "needed" friction imo.
lint.run:
ruff check --ignore F401 --exclude languages --exclude samples
ruff format --exclude languages --exclude samples

lint.check:
echo "Linting..."
ruff check --ignore F401 --exclude languages --exclude samples
echo "Formatting..."
ruff format --check --exclude languages --exclude samples

lint:
pip install black==22.3.0 isort==5.10.1
black codecov_cli
isort --profile=black codecov_cli -p staticcodecov_languages
black tests
isort --profile black tests
make lint.install
make lint.run

tag.release:
ifeq ($(shell echo ${version} | egrep "${tag_regex}"),)
Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/commands/get_report_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.git import GitService
from codecov_cli.helpers.options import global_options
from codecov_cli.services.report import send_reports_result_get_request
from codecov_cli.types import CommandContext


logger = logging.getLogger("codecovcli")


Expand Down
8 changes: 4 additions & 4 deletions codecov_cli/commands/labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ def _dry_run_list_output(
logger.warning(f"label-analysis didn't run correctly. Error: {fallback_reason}")

to_run_line = " ".join(
sorted(map(lambda l: f"'{l}'", runner_options))
+ sorted(map(lambda l: f"'{l}'", labels_to_run))
sorted(map(lambda option: f"'{option}'", runner_options))
+ sorted(map(lambda label: f"'{label}'", labels_to_run))
)
to_skip_line = " ".join(
sorted(map(lambda l: f"'{l}'", runner_options))
+ sorted(map(lambda l: f"'{l}'", labels_to_skip))
sorted(map(lambda option: f"'{option}'", runner_options))
+ sorted(map(lambda label: f"'{label}'", labels_to_skip))
)
# ⚠️ DON'T use logger
# logger goes to stderr, we want it in stdout
Expand Down
6 changes: 3 additions & 3 deletions codecov_cli/commands/process_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def process_test_results(
dir, exclude_folders, files, disable_search, report_type="test_results"
)

upload_collection_results: List[
UploadCollectionResultFile
] = file_finder.find_files()
upload_collection_results: List[UploadCollectionResultFile] = (
file_finder.find_files()
)
if len(upload_collection_results) == 0:
raise click.ClickException(
"No JUnit XML files were found. Make sure to specify them using the --file option."
Expand Down
175 changes: 175 additions & 0 deletions codecov_cli/commands/upload_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import logging
import pathlib
import typing

import click

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
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.options import global_options
from codecov_cli.services.upload_coverage import upload_coverage_logic
from codecov_cli.types import CommandContext

logger = logging.getLogger("codecovcli")


# These options are the combined options of commit, report and upload commands
@click.command()
@global_options
@global_upload_options
@click.option(
"--parent-sha",
help="SHA (with 40 chars) of what should be the parent of this commit",
)
@click.pass_context
def upload_coverage(
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,
):
args = get_cli_args(ctx)
logger.debug(
"Starting upload coverage",
extra=dict(
extra_log_attributes=args,
),
)

if not use_legacy_uploader and report_type == "coverage":
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)
ctx.invoke(
upload_coverage_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,
)
else:
ctx.invoke(
create_commit,
commit_sha=commit_sha,
parent_sha=parent_sha,
pull_request_number=pull_request_number,
branch=branch,
slug=slug,
token=token,
git_service=git_service,
fail_on_error=True,
)
if report_type == "coverage":
ctx.invoke(
create_report,
token=token,
code=report_code,
fail_on_error=True,
commit_sha=commit_sha,
slug=slug,
git_service=git_service,
)
ctx.invoke(
do_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,
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,
)
4 changes: 2 additions & 2 deletions codecov_cli/helpers/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def get_cli_args(ctx: click.Context):
filtered_args = {}
for k in args.keys():
try:
if type(args[k]) == PosixPath:
if isinstance(args[k], PosixPath):
filtered_args[k] = str(args[k])
else:
json.dumps(args[k])
filtered_args[k] = args[k]
except Exception as e:
except Exception:
continue

return filtered_args
15 changes: 10 additions & 5 deletions codecov_cli/helpers/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def backoff_time(curr_retry):
return 2 ** (curr_retry - 1)


class RetryException(Exception):
...
class RetryException(Exception): ...


def retry_request(func):
Expand All @@ -73,7 +72,7 @@ def wrapper(*args, **kwargs):
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
RetryException,
) as exp:
):
logger.warning(
"Request failed. Retrying",
extra=dict(extra_log_attributes=dict(retry=retry)),
Expand Down Expand Up @@ -102,15 +101,21 @@ def send_get_request(
return request_result(get(url=url, headers=headers, params=params))


def get_token_header_or_fail(token: str) -> dict:
def get_token_header_or_fail(token: Optional[str]) -> dict:
"""
Rejects requests with no Authorization token. Prevents tokenless uploads.
"""
if token is None:
raise click.ClickException(
"Codecov token not found. Please provide Codecov token with -t flag."
)
return {"Authorization": f"token {token}"}


def get_token_header(token: str) -> Optional[dict]:
def get_token_header(token: Optional[str]) -> Optional[dict]:
"""
Allows requests with no Authorization token.
"""
if token is None:
return None
return {"Authorization": f"token {token}"}
Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from codecov_cli.commands.send_notifications import send_notifications
from codecov_cli.commands.staticanalysis import static_analysis
from codecov_cli.commands.upload import do_upload
from codecov_cli.commands.upload_coverage import upload_coverage
from codecov_cli.commands.upload_process import upload_process
from codecov_cli.helpers.ci_adapters import get_ci_adapter, get_ci_providers_list
from codecov_cli.helpers.config import load_cli_config
Expand Down Expand Up @@ -74,6 +75,7 @@ def cli(
cli.add_command(label_analysis)
cli.add_command(static_analysis)
cli.add_command(empty_upload)
cli.add_command(upload_coverage)
cli.add_command(upload_process)
cli.add_command(send_notifications)
cli.add_command(process_test_results)
Expand Down
1 change: 0 additions & 1 deletion codecov_cli/plugins/pycoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(self, config: dict):
self.config = PycoverageConfig(config)

def run_preparation(self, collector) -> PreparationPluginReturn:

if shutil.which("coverage") is None:
logger.warning("coverage.py is not installed or can't be found.")
return
Expand Down
2 changes: 1 addition & 1 deletion codecov_cli/runners/dan_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def process_labelanalysis_result(self, result: LabelAnalysisRequestResult):
"DAN runner missing 'process_labelanalysis_result_command' configuration value"
)
command_list = []
if type(command) == list:
if isinstance(command, list):
command_list.extend(command)
else:
command_list.append(command)
Expand Down
1 change: 0 additions & 1 deletion codecov_cli/runners/pytest_standard_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def get_available_params(cls) -> List[str]:


class PytestStandardRunner(LabelAnalysisRunnerInterface):

dry_run_runner_options = ["--cov-context=test"]
params: PytestStandardRunnerConfigParams

Expand Down
Loading

0 comments on commit 13edc25

Please sign in to comment.