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 manifest workflow failure #2889

Merged
merged 5 commits into from
Nov 14, 2022
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
19 changes: 17 additions & 2 deletions src/manifests/component_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ def __to_dict__(self) -> dict:

class Components(Dict[str, ComponentType], Generic[ComponentType]):
def __init__(self, data: Dict[Any, Any]) -> None:
create_component: Callable[[Any], Tuple[str, ComponentType]] = lambda component: (component["name"], self.__create__(component))
create_component: Callable[[Any], Tuple[str, ComponentType]] = lambda component: (
component["name"], self.__create__(component))
super().__init__(map(create_component, data))

@classmethod
def __create__(self, data: dict) -> ComponentType:
return Component(data) # type: ignore[return-value]
if "repository" in data:
return ComponentFromSource(data) # type: ignore[return-value]
else:
return Component(data) # type: ignore[return-value]

def __to_dict__(self) -> List[Dict[Any, Any]]:
as_dict: Callable[[ComponentType], dict] = lambda component: component.__to_dict__()
Expand Down Expand Up @@ -98,3 +102,14 @@ def __matches__(self, focus: List[str] = [], platform: str = None) -> bool:
logging.info(f"Skipping {self.name}")

return matches


class ComponentFromSource(Component):
repository: str

def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]

def __to_dict__(self) -> dict:
return {"name": self.name, "repository": self.repository}
3 changes: 2 additions & 1 deletion src/manifests_workflow/component_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ def checkout(
name: str,
path: str,
opensearch_version: str,
repo_url: str,
zelinh marked this conversation as resolved.
Show resolved Hide resolved
branch: str = "main",
snapshot: bool = False,
working_directory: str = None,
) -> 'ComponentOpenSearch':
with GitRepository(
f"https://github.com/opensearch-project/{name}.git",
repo_url,
branch,
path,
working_directory,
Expand Down
33 changes: 18 additions & 15 deletions src/manifests_workflow/input_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import ruamel.yaml

from manifests.component_manifest import ComponentFromSource
from manifests.input_manifest import InputComponents, InputManifest
from manifests.manifests import Manifests
from manifests_workflow.component_opensearch import ComponentOpenSearch
Expand Down Expand Up @@ -99,21 +100,23 @@ def update(
if component.name == self.name:
continue

logging.info(f"Checking out {component.name}#main")
component = component_klass.checkout(
name=component.name,
path=os.path.join(work_dir.name, component.name),
opensearch_version=manifest.build.version,
branch="main",
)

component_version = component.version
if component_version:
release_version = ".".join(component_version.split(".")[:3])
if release_version not in main_versions.keys():
main_versions[release_version] = []
main_versions[release_version].append(component)
logging.info(f"{component.name}#main is version {release_version} (from {component_version})")
if type(component) is ComponentFromSource:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm getting it correct, we assume all components here are type of ComponentFromSource that has repository in its data right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, return repo for only those components that have repository attribute

logging.info(f"Checking out {component.name}#main")
component = component_klass.checkout(
name=component.name,
path=os.path.join(work_dir.name, component.name),
opensearch_version=manifest.build.version,
repo_url=component.repository,
branch="main",
)

component_version = component.version
if component_version:
release_version = ".".join(component_version.split(".")[:3])
if release_version not in main_versions.keys():
main_versions[release_version] = []
main_versions[release_version].append(component)
logging.info(f"{component.name}#main is version {release_version} (from {component_version})")

# summarize
logging.info("Found versions on main:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestComponentOpenSearch(unittest.TestCase):
@patch("os.makedirs")
@patch.object(GitRepository, "__checkout__")
def test_checkout(self, *mocks: MagicMock) -> None:
component = ComponentOpenSearch.checkout("common-utils", "path", "1.1.0")
component = ComponentOpenSearch.checkout("common-utils", "path", "1.1.0", "git")
self.assertEqual(component.name, "common-utils")
self.assertFalse(component.snapshot)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import unittest
from unittest.mock import MagicMock, call, patch

from manifests.input_manifest import Component
from manifests.component_manifest import Component, ComponentFromSource
from manifests_workflow.input_manifests_opensearch import InputManifestsOpenSearch


Expand Down Expand Up @@ -49,7 +49,8 @@ def test_update(self, mock_input_manifest: MagicMock, mock_component_opensearch:
mock_component_opensearch.return_value = MagicMock(name="common-utils")
mock_component_opensearch.checkout.return_value = MagicMock(version="0.10.0")
mock_input_manifest_from_path.return_value.components = {
"common-utils": Component({"name": "common-utils", "repository": "git", "ref": "ref"})
"common-utils": ComponentFromSource({"name": "common-utils", "repository": "git", "ref": "ref"}),
"job-scheduler": Component({"name": "job-scheduler", "dist": "zip"})
}
manifests = InputManifestsOpenSearch()
manifests.update()
Expand Down