forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_opensearch.py
66 lines (58 loc) · 1.87 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
# 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 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,
path,
opensearch_version,
branch="main",
snapshot=False,
working_directory=None,
):
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, repo, opensearch_version, snapshot=False):
super().__init__(name, repo, snapshot)
self.opensearch_version = opensearch_version
@property
def properties(self):
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):
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, props={}):
cmd = [f"./gradlew {target}"]
cmd.extend([f"-D{k}={v}" for k, v in props.items()])
return " ".join(cmd)