Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary support for Go 1.22 #1004

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cachito/workers/pkg_managers/gomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,8 @@ def _get_gomod_version(go_mod_file: Path) -> Tuple[Optional[str], Optional[str]]
def _select_go_toolchain(go_mod_file: Path) -> Go:
go = Go()
target_version = None
go_max_version = pkgver.Version("1.21")
go_max_version = pkgver.Version("1.22")
go_121_version = pkgver.Version("1.21")
go_base_version = go.version
go_mod_version_msg = "go.mod reported versions: '{}'[go], '{}'[toolchain]"

Expand Down Expand Up @@ -1111,13 +1112,13 @@ def _select_go_toolchain(go_mod_file: Path) -> Go:
f"Required/recommended Go toolchain version '{target_version}' is not supported yet.",
)

if target_version >= go_max_version:
if target_version >= go_121_version:
# Project makes use of Go >=1.21:
# - always use the 'X.Y.0' toolchain to make sure GOTOOLCHAIN=auto fetches anything newer
# - container environments need to have it pre-installed
# - local environments will always install 1.21.0 SDK and then pull any newer toolchain
go = Go(release="go1.21.0")
elif go_base_version >= go_max_version:
elif go_base_version >= go_121_version:
# Starting with Go 1.21, Go doesn't try to be semantically backwards compatible in that
# the 'go X.Y' line now denotes the minimum required version of Go, not a "suggested"
# version. What it means in practice is that a Go toolchain >= 1.21 enforces the biggest
Expand Down
10 changes: 2 additions & 8 deletions cachito/workers/tasks/gomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
from pathlib import Path

from cachito.common.packages_data import PackagesData
from cachito.errors import (
FileAccessError,
GoModError,
InvalidRepoStructure,
InvalidRequestData,
UnsupportedFeature,
)
from cachito.errors import FileAccessError, GoModError, InvalidRequestData, UnsupportedFeature
from cachito.workers.config import get_worker_config
from cachito.workers.paths import RequestBundleDir
from cachito.workers.pkg_managers.general import update_request_env_vars
Expand Down Expand Up @@ -68,7 +62,7 @@ def _is_workspace(repo_root: Path, subpath: str):
def _fail_if_bundle_dir_has_workspaces(bundle_dir: RequestBundleDir, subpaths: list[str]):
for subpath in subpaths:
if _is_workspace(bundle_dir.source_root_dir, subpath):
raise InvalidRepoStructure("Go workspaces are not supported by Cachito.")
raise UnsupportedFeature("Go workspaces are not supported by Cachito.")


def _fail_if_parent_replacement_not_included(packages_json_data: PackagesData) -> None:
Expand Down
9 changes: 2 additions & 7 deletions tests/test_workers/test_tasks/test_gomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@

from cachito.common.packages_data import PackagesData
from cachito.common.paths import RequestBundleDir
from cachito.errors import (
FileAccessError,
InvalidRepoStructure,
InvalidRequestData,
UnsupportedFeature,
)
from cachito.errors import FileAccessError, InvalidRequestData, UnsupportedFeature
from cachito.workers import tasks
from cachito.workers.tasks import gomod

Expand Down Expand Up @@ -366,7 +361,7 @@ def test_fail_if_bundle_dir_has_workspaces(add_go_work_file, tmpdir):

if add_go_work_file:
Path(bundle_dir.source_root_dir / "go.work").touch()
with pytest.raises(InvalidRepoStructure):
with pytest.raises(UnsupportedFeature):
gomod._fail_if_bundle_dir_has_workspaces(bundle_dir, ["."])
else:
gomod._fail_if_bundle_dir_has_workspaces(bundle_dir, ["."])
Expand Down