From 823c1175631123699322c42aee4e15be2ca7119d Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 15 Oct 2025 18:00:51 +0200 Subject: [PATCH] Fix dry-run for notifications @ publish-codecov Apparently `codecovcli send-notifications` does not have a `--dry-run` CLI option. This patch stops adding it to the command and implements an external `dry-run` mode in the wrapper script or this case instead. This is a follow-up for #85968. Co-authored-by: Matt Clay --- .azure-pipelines/scripts/publish-codecov.py | 31 +++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/.azure-pipelines/scripts/publish-codecov.py b/.azure-pipelines/scripts/publish-codecov.py index 828b9fd5e19..1b5b2d12897 100755 --- a/.azure-pipelines/scripts/publish-codecov.py +++ b/.azure-pipelines/scripts/publish-codecov.py @@ -47,13 +47,25 @@ def parse_args() -> Args: return Args(**kwargs) -def run(*args: str | pathlib.Path) -> None: +def run( + *args: str | pathlib.Path, + dry_run: bool = False, +) -> None: + """ + Log and run given command. + + The command is not actually executed if ``dry_run`` is truthy. + """ cmd = [str(arg) for arg in args] - print(f'==> {shlex.join(cmd)}', flush=True) - subprocess.run(cmd, check=True) + dry_prefix = '[would run] ' if dry_run else '' + print(f'==> {dry_prefix}{shlex.join(cmd)}', flush=True) -def install_codecov(dest: pathlib.Path) -> pathlib.Path: + if not dry_run: + subprocess.run(cmd, check=True) + + +def install_codecov(dest: pathlib.Path, dry_run: bool = False) -> pathlib.Path: """Populate a transitively pinned venv with ``codecov-cli``.""" requirement_file = DEPS_DIR / 'codecov.in' constraint_file = requirement_file.with_suffix('.txt') @@ -72,6 +84,7 @@ def install_codecov(dest: pathlib.Path) -> pathlib.Path: f'--constraint={constraint_file!s}', f'--requirement={requirement_file!s}', '--disable-pip-version-check', + dry_run=dry_run, ) return codecov_bin @@ -131,10 +144,7 @@ def report_upload_completion( 'send-notifications', ] - if dry_run: - cmd.append('--dry-run') - - run(*cmd) + run(*cmd, dry_run=dry_run) def main() -> None: @@ -147,7 +157,10 @@ def main() -> None: # * https://docs.codecov.com/docs/notifications#preventing-notifications-until-youre-ready-to-send-notifications config_file.write_text('codecov:\n notify:\n manual_trigger: true') - codecov_bin = install_codecov(pathlib.Path(tmpdir)) + codecov_bin = install_codecov( + pathlib.Path(tmpdir), + dry_run=args.dry_run, + ) files = process_files(args.path) upload_files(codecov_bin, config_file, files, args.dry_run) # Ref: https://docs.codecov.com/docs/cli-options#send-notifications