Skip to content

Commit

Permalink
fix(remote-build): warn instead of error when using unsupported bases
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Schvezov <[email protected]>
  • Loading branch information
sergiusens committed Oct 6, 2023
1 parent d321033 commit 32eb779
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
26 changes: 25 additions & 1 deletion snapcraft/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def run(self, parsed_args: argparse.Namespace) -> None:
self._snapcraft_yaml = yaml_utils.get_snap_project().project_file
self._parsed_args = parsed_args
# pylint: enable=attribute-defined-outside-init
base = self._get_effective_base()
try:
base = self._get_effective_base()
except MaintenanceBase as base_err:
base = base_err.base
emit.progress(_get_esm_warning_for_base(base), permanent=True)

self._run_new_or_fallback_remote_build(base)

def _run_new_or_fallback_remote_build(self, base: str) -> None:
Expand Down Expand Up @@ -279,3 +284,22 @@ def _get_effective_base(self) -> str:
)

return base


def _get_esm_warning_for_base(base: str) -> str:
"""Return a warning appropriate for the base under ESM."""
channel: Optional[str] = None
match base:
case "core":
channel = "4.x"
version = "4"
case "core18":
channel = "7.x"
version = "7"
case _:
raise RuntimeError(f"Unmatched base {base!r}")

return (
f"WARNING: base {base!r} was last supported on Snapcraft {version} available "
f"on the {channel!r} channel."
)
1 change: 1 addition & 0 deletions snapcraft/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __init__(self, base: str) -> None:
resolution=resolution,
docs_url="https://snapcraft.io/docs/base-snaps",
)
self.base = base


class StoreCredentialsUnauthorizedError(SnapcraftError):
Expand Down
36 changes: 29 additions & 7 deletions tests/unit/commands/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_get_effective_base_with_build_base(


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
@pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES)
@pytest.mark.parametrize("base", CURRENT_BASES | LEGACY_BASES | ESM_BASES)
def test_get_effective_base_type(
base, snapcraft_yaml, mock_run_new_or_fallback_remote_build
):
Expand Down Expand Up @@ -255,15 +255,37 @@ def test_get_effective_base_none(capsys, snapcraft_yaml):


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
@pytest.mark.parametrize("base", ESM_BASES)
def test_get_effective_base_esm(base, capsys, snapcraft_yaml):
"""Raise an error if an ESM base is used."""
snapcraft_yaml(base=base)
def test_get_effective_base_core_esm_warning(
emitter, snapcraft_yaml, mock_run_new_or_fallback_remote_build
):
"""Warn if core, an ESM base, is used."""
snapcraft_yaml(base="core")

cli.run()

_, err = capsys.readouterr()
assert f"{base!r} is not supported on this version of Snapcraft." in err
mock_run_new_or_fallback_remote_build.assert_called_once_with("core")
emitter.assert_progress(
"WARNING: base 'core' was last supported on Snapcraft 4 available on the "
"'4.x' channel.",
permanent=True,
)


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
def test_get_effective_base_core18_esm_warning(
emitter, snapcraft_yaml, mock_run_new_or_fallback_remote_build
):
"""Warn if core18, an ESM base, is used."""
snapcraft_yaml(base="core18")

cli.run()

mock_run_new_or_fallback_remote_build.assert_called_once_with("core18")
emitter.assert_progress(
"WARNING: base 'core18' was last supported on Snapcraft 7 available on the "
"'7.x' channel.",
permanent=True,
)


#######################
Expand Down

0 comments on commit 32eb779

Please sign in to comment.