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

fix(cachi2): set gomod explicitly #2138

Merged
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
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
Loading