forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_opensearch.py
67 lines (59 loc) · 2.04 KB
/
component_opensearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
import logging
import subprocess
from typing import Any
from git.git_repository import GitRepository
from manifests_workflow.component import Component
from system.properties_file import PropertiesFile
class ComponentOpenSearch(Component):
@classmethod
def checkout(
self,
name: str,
path: str,
opensearch_version: str,
branch: str = "main",
snapshot: bool = False,
working_directory: str = None,
) -> 'ComponentOpenSearch':
with GitRepository(
f"https://github.com/opensearch-project/{name}.git",
branch,
path,
working_directory,
) as repo:
return ComponentOpenSearch(
name,
repo,
opensearch_version,
snapshot,
)
def __init__(self, name: str, repo: GitRepository, opensearch_version: str, snapshot: bool = False) -> None:
super().__init__(name, repo, snapshot)
self.opensearch_version = opensearch_version
@property
def properties(self) -> PropertiesFile:
cmd = ComponentOpenSearch.gradle_cmd(
"properties",
{
"opensearch.version": self.opensearch_version,
"build.snapshot": str(self.snapshot).lower(),
},
)
return PropertiesFile(self.git_repo.output(cmd))
@property
def version(self) -> Any:
try:
return self.properties.get_value("version")
except subprocess.CalledProcessError as err:
logging.warn(f"Error getting version of {self.name}: {str(err)}, ignored")
return None
@classmethod
def gradle_cmd(self, target: str, props: dict = {}) -> str:
cmd = [f"./gradlew {target}"]
cmd.extend([f"-D{k}={v}" for k, v in props.items()])
return " ".join(cmd)