Skip to content

Commit

Permalink
Add distribution supported components list so only specific scripts c…
Browse files Browse the repository at this point in the history
…an take -d parameter (#1652)

* Add distribution supported components list so only specific scripts can take  parameter

Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>

* Remove extra spaces

Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
  • Loading branch information
peterzhuamazon authored Feb 19, 2022
1 parent 504427b commit 947bc5d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/build_workflow/builder_from_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def checkout(self, work_dir: str) -> None:
)

def build(self, build_recorder: BuildRecorder) -> None:

# List of components whose build scripts support `-d` parameter
# Bundled plugins do not need `-d` as they are java based zips
DISTRIBUTION_SUPPORTED_COMPONENTS = ["OpenSearch", "OpenSearch-Dashboards"]

build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)

build_command = " ".join(
Expand All @@ -39,7 +44,7 @@ def build(self, build_recorder: BuildRecorder) -> None:
f"-v {self.target.version}",
f"-p {self.target.platform}",
f"-a {self.target.architecture}",
f"-d {self.target.distribution}" if self.target.distribution else None,
f"-d {self.target.distribution}" if self.target.distribution and (self.component.name in DISTRIBUTION_SUPPORTED_COMPONENTS) else None,
f"-s {str(self.target.snapshot).lower()}",
f"-o {self.output_path}",
]
Expand Down
33 changes: 33 additions & 0 deletions tests/tests_build_workflow/test_builder_from_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ def setUp(self) -> None:
),
)

self.builder_distribution_support = BuilderFromSource(
InputComponentFromSource({"name": "common-utils", "repository": "url", "ref": "ref"}),
BuildTarget(
name="OpenSearch",
version="1.3.0",
platform="linux",
architecture="x64",
distribution="rpm",
snapshot=False,
),
)

def test_builder(self) -> None:
self.assertEqual(self.builder.component.name, "common-utils")

Expand Down Expand Up @@ -86,6 +98,27 @@ def test_build_distribution(self, mock_git_repo: Mock) -> None:
)
build_recorder.record_component.assert_called_with("OpenSearch", mock_git_repo.return_value)

@patch("build_workflow.builder_from_source.GitRepository")
def test_build_distribution_support(self, mock_git_repo: Mock) -> None:
mock_git_repo.return_value = MagicMock(working_directory="dir")
build_recorder = MagicMock()
self.builder_distribution_support.checkout("dir")
self.builder_distribution_support.build(build_recorder)
mock_git_repo.return_value.execute.assert_called_with(
" ".join(
[
"bash",
os.path.realpath(os.path.join(ScriptFinder.component_scripts_path, "common-utils", "build.sh")),
"-v 1.3.0",
"-p linux",
"-a x64",
"-s false",
"-o builds",
]
)
)
build_recorder.record_component.assert_called_with("common-utils", mock_git_repo.return_value)

@patch("build_workflow.builder_from_source.GitRepository")
def test_build_snapshot(self, mock_git_repo: Mock) -> None:
self.builder.target.snapshot = True
Expand Down

0 comments on commit 947bc5d

Please sign in to comment.