diff --git a/craft_application/services/fetch.py b/craft_application/services/fetch.py index 6e4d492a..50f575aa 100644 --- a/craft_application/services/fetch.py +++ b/craft_application/services/fetch.py @@ -20,12 +20,13 @@ import pathlib import subprocess import typing +from functools import partial import craft_providers from craft_cli import emit from typing_extensions import override -from craft_application import fetch, models, services +from craft_application import fetch, models, services, util from craft_application.models.manifest import CraftManifest, ProjectManifest if typing.TYPE_CHECKING: @@ -173,3 +174,21 @@ def _create_craft_manifest( with manifest_path.open("w") as f: json.dump(data, f, ensure_ascii=False, indent=2) + + deps = craft_manifest.dependencies + rejections = [dep for dep in deps if dep.rejected] + + if rejections: + display = partial(emit.progress, permanent=True) + items: list[dict[str, typing.Any]] = [] + for rejection in rejections: + url = rejection.url[0] if len(rejection.url) == 1 else rejection.url + items.append({"url": url, "reasons": rejection.rejection_reasons}) + text = util.dump_yaml(items) + + display( + "The following artifacts were marked as rejected by the fetch-service:" + ) + for line in text.splitlines(): + display(line) + display("This build will fail on 'strict' fetch-service sessions.") diff --git a/tests/unit/services/test_fetch.py b/tests/unit/services/test_fetch.py index 72bd7430..c8883862 100644 --- a/tests/unit/services/test_fetch.py +++ b/tests/unit/services/test_fetch.py @@ -25,6 +25,7 @@ import contextlib import json import re +import textwrap from datetime import datetime from unittest import mock from unittest.mock import MagicMock, call @@ -108,7 +109,13 @@ def test_create_project_manifest_not_managed(fetch_service, tmp_path, monkeypatc def test_teardown_session_create_manifest( - fetch_service, tmp_path, mocker, manifest_data_dir, monkeypatch, fake_project + fetch_service, + tmp_path, + mocker, + manifest_data_dir, + monkeypatch, + fake_project, + emitter, ): monkeypatch.chdir(tmp_path) @@ -142,6 +149,27 @@ def temporarily_pull_file(*, source, missing_ok): assert obtained_file.read_text() + "\n" == expected_file.read_text() + expected_output = textwrap.dedent( + """\ + The following artifacts were marked as rejected by the fetch-service: + - url: https://github.com:443/canonical/sphinx-docs-starter-pack.git/git-upload-pack + reasons: + - fetch is allowed only on a single ref + - fetch is only allowed with depth 1 + - git repository does not contain a go.mod file + - url: https://proxy.golang.org:443/github.com/go-mmap/mmap/@v/v0.7.0.mod + reasons: + - the artefact format is unknown + - the request was not recognized by any format inspector + This build will fail on 'strict' fetch-service sessions. + """ + ) + for line in expected_output.splitlines(): + emitter.assert_progress( + line, + permanent=True, + ) + @pytest.mark.parametrize("run_on_host", [True, False]) def test_warning_experimental(mocker, fetch_service, run_on_host, emitter):