Skip to content

Commit

Permalink
fix(cachi2): set gomod explicitly
Browse files Browse the repository at this point in the history
undefined pkg_managers means gomod, record this explictily in metadata,
so this information is not lost in workflow and proper metadata are
returned.

Signed-off-by: Martin Basti <mbasti@redhat.com>
  • Loading branch information
MartinBasti committed Dec 11, 2024
1 parent 4246270 commit 4ed60be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion atomic_reactor/plugins/cachi2_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
)
from atomic_reactor.plugin import Plugin
from atomic_reactor.util import map_to_user_params
from atomic_reactor.utils.cachi2 import remote_source_to_cachi2, clone_only, validate_paths
from atomic_reactor.utils.cachi2 import (
remote_source_to_cachi2, clone_only, validate_paths,
normalize_gomod_pkg_manager
)


class Cachi2InitPlugin(Plugin):
Expand Down Expand Up @@ -114,6 +117,9 @@ def process_remote_sources(self) -> List[Dict[str, Any]]:
remote_source["name"] if self.multiple_remote_sources_params
else CACHI2_SINGLE_REMOTE_SOURCE_NAME
)

normalize_gomod_pkg_manager(remote_source['remote_source'])

self.log.info("Initializing remote source %s", source_name)
source_path = self.remote_sources_root_path / source_name
source_path.mkdir()
Expand Down
20 changes: 16 additions & 4 deletions atomic_reactor/utils/cachi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ def is_path_ok(path_string):
raise ValueError(f"unexpected key '{key}' in '{pkg_mgr}' config")


def normalize_gomod_pkg_manager(remote_source: Dict[str, Any]):
"""Cachito compatibility, empty/undefined pkg_managers means gomod.
Replace it to explicitly use gomod
Function does in-place change.
"""
pkg_managers = remote_source.get("pkg_managers")
if pkg_managers is None:
# Cachito behavior, missing pkg_managers means to use gomod
pkg_managers = ["gomod"]
remote_source["pkg_managers"] = pkg_managers


def remote_source_to_cachi2(remote_source: Dict[str, Any]) -> Dict[str, Any]:
"""Converts remote source into cachi2 expected params.
Expand Down Expand Up @@ -84,10 +97,9 @@ def remote_source_to_cachi2(remote_source: Dict[str, Any]) -> Dict[str, Any]:
)
cachi2_packages = []

pkg_managers = remote_source.get("pkg_managers")
if pkg_managers is None:
# Cachito behavior, missing pkg_managers means to use gomod
pkg_managers = ["gomod"]
normalize_gomod_pkg_manager(remote_source)

pkg_managers = remote_source["pkg_managers"]

for pkg_manager in pkg_managers:
if pkg_manager in removed_pkg_managers:
Expand Down
2 changes: 2 additions & 0 deletions tests/plugins/test_cachi2_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def test_single_remote_source_initialization(workflow, mocked_cachi2_init):
"remote_source": {
"repo": REMOTE_SOURCE_REPO,
"ref": REMOTE_SOURCE_REF,
"pkg_managers": ["gomod"],
}
}]

Expand Down Expand Up @@ -254,6 +255,7 @@ def test_multi_remote_source_initialization(workflow, mocked_cachi2_init):
"remote_source": {
"repo": SECOND_REMOTE_SOURCE_REPO,
"ref": SECOND_REMOTE_SOURCE_REF,
"pkg_managers": ["gomod"],
}
}]

Expand Down

0 comments on commit 4ed60be

Please sign in to comment.