From 17ddbf12e8aecee62e6757adefc60b8a694a0d39 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Thu, 30 May 2024 18:03:38 +0200 Subject: [PATCH] pkg_managers: gomod: Fix the Go toolchain selection conditions When commit d9d1620a enabled full Go 1.21 support the semantics it used for the Go toolchain selection conditions was very unfortunate as it revolved too much around the 'go_max_version' variable which at the time was set to be 1.21. The problem there is that once we try bumping the max version to say 1.22 the conditions stop making sense and as a bonus the existing tests start failing. The reasons for that are the following: - we're not actually planning on updating the container image with each Go version we're going to support unless absolutely necessary; that is thanks to the GOTOOLCHAIN=auto mechanism introduced by 1.21 that will download any new toolchain as needed automatically - without changing unit tests we suddenly can't pass the trivial condition on selecting the old fallback 1.20 if the existing unit test's base Go release is 1.21.X and the new max supported version is 1.22 Tweak the selection conditions so that they finally make sense semantically: - use go_max_version only to check incoming requests for incompatible new releases - otherwise always explicitly compare against 1.21 and only fall back to 1.20 if the base release is above 1.21 which would lead to dirtying the source repo due to compatibility issues on Golang's side Fixes: d9d1620ab789126b2232467f3e4802577719ab1c Signed-off-by: Erik Skultety --- cachito/workers/pkg_managers/gomod.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cachito/workers/pkg_managers/gomod.py b/cachito/workers/pkg_managers/gomod.py index ff41dff3e..447e3c052 100644 --- a/cachito/workers/pkg_managers/gomod.py +++ b/cachito/workers/pkg_managers/gomod.py @@ -1078,6 +1078,7 @@ def _select_go_toolchain(go_mod_file: Path) -> Go: go = Go() target_version = None go_max_version = pkgver.Version("1.21") + go_121_version = pkgver.Version("1.21") go_base_version = go.version go_mod_version_msg = "go.mod reported versions: '{}'[go], '{}'[toolchain]" @@ -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