Skip to content

Commit 969befc

Browse files
authored
fix(ci): do not fail on upload failure (#683)
This makes sure the CI does not break if upload cannot be done. Fixes MRGFY-5182
1 parent 025fef7 commit 969befc

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

mergify_cli/ci/cli.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ async def junit_upload( # noqa: PLR0913, PLR0917
5858
test_language: str | None,
5959
files: tuple[str, ...],
6060
) -> None:
61-
await upload.upload(
62-
api_url=api_url,
63-
token=token,
64-
repository=repository,
65-
test_framework=test_framework,
66-
test_language=test_language,
67-
files=files,
68-
)
61+
try:
62+
await upload.upload(
63+
api_url=api_url,
64+
token=token,
65+
repository=repository,
66+
test_framework=test_framework,
67+
test_language=test_language,
68+
files=files,
69+
)
70+
except Exception as e: # noqa: BLE001
71+
click.echo(
72+
click.style(f"Error uploading JUnit XML reports: {e}", fg="red"),
73+
err=True,
74+
)

mergify_cli/tests/ci/test_cli.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,41 @@ def test_cli(env: dict[str, str], monkeypatch: pytest.MonkeyPatch) -> None:
6565
"test_language": None,
6666
"files": (str(REPORT_XML),),
6767
}
68+
69+
70+
def test_upload_error(monkeypatch: pytest.MonkeyPatch) -> None:
71+
for key, value in {
72+
"GITHUB_EVENT_NAME": "push",
73+
"GITHUB_ACTIONS": "true",
74+
"MERGIFY_API_URL": "https://api.mergify.com",
75+
"MERGIFY_TOKEN": "abc",
76+
"GITHUB_REPOSITORY": "user/repo",
77+
"GITHUB_SHA": "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199",
78+
"GITHUB_WORKFLOW": "JOB",
79+
}.items():
80+
monkeypatch.setenv(key, value)
81+
82+
runner = testing.CliRunner()
83+
84+
with mock.patch.object(
85+
upload,
86+
"upload",
87+
mock.AsyncMock(),
88+
) as mocked_upload:
89+
mocked_upload.side_effect = Exception("Upload failed")
90+
result = runner.invoke(
91+
cli_junit_upload.junit_upload,
92+
[str(REPORT_XML)],
93+
)
94+
assert result.exit_code == 0, (result.stdout, result.stderr)
95+
assert result.stderr == "Error uploading JUnit XML reports: Upload failed\n"
96+
assert not result.stdout
97+
assert mocked_upload.call_count == 1
98+
assert mocked_upload.call_args.kwargs == {
99+
"api_url": "https://api.mergify.com",
100+
"token": "abc",
101+
"repository": "user/repo",
102+
"test_framework": None,
103+
"test_language": None,
104+
"files": (str(REPORT_XML),),
105+
}

0 commit comments

Comments
 (0)