Skip to content

Commit

Permalink
Extracted manifests and components.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Sep 14, 2021
1 parent d88a549 commit cba6d14
Show file tree
Hide file tree
Showing 9 changed files with 2,834 additions and 96 deletions.
20 changes: 20 additions & 0 deletions bundle-workflow/src/manifests/input_manifests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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 glob
import os
import re

from manifests.input_manifest import InputManifest
from manifests.manifests import Manifests


class InputManifests(Manifests):
def __init__(self):
files = glob.glob(os.path.join(self.manifests_path, "opensearch-*.yml"))
# there's an opensearch-1.0.0-maven.yml that we want to skip
files = [f for f in files if re.search(r"/opensearch-([0-9.]*)\.yml$", f)]
super().__init__(InputManifest, files)
45 changes: 45 additions & 0 deletions bundle-workflow/src/manifests/manifests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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 os
import re

from sortedcontainers import SortedDict # type: ignore


class Manifests(SortedDict):
def __init__(self, klass, files):
super(Manifests, self).__init__()
self.klass = klass
self.__append__(files)

def __append__(self, files):
for filename in files:
basename = os.path.basename(filename)
match = re.search(r"-([0-9.]*).yml$", basename)
if not match:
raise ValueError(f"Invalid file: {basename}")

version = match.group(1)
manifest = self.klass.from_path(filename)
self.__setitem__(version, manifest)

@property
def manifests_path(self):
return os.path.realpath(
os.path.join(os.path.dirname(__file__), "../../../manifests")
)

@property
def versions(self):
return list(map(lambda manifest: manifest.build.version, self.values()))

@property
def latest(self):
if len(self) == 0:
raise RuntimeError("No manifests found")

return self.values()[-1]
17 changes: 17 additions & 0 deletions bundle-workflow/src/manifests_workflow/component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.


class Component:
def __init__(self, name, repo, snapshot=False):
self.name = name
self.git_repo = repo
self.snapshot = snapshot

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)
51 changes: 51 additions & 0 deletions bundle-workflow/src/manifests_workflow/component_opensearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.

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,
):
return ComponentOpenSearch(
name,
GitRepository(
f"https://github.com/opensearch-project/{name}.git",
branch,
path,
working_directory,
),
opensearch_version,
snapshot,
)

def __init__(self, name, repo, opensearch_version, snapshot=False):
super().__init__(name, repo, snapshot)
self.opensearch_version = opensearch_version

def get_properties(self):
cmd = self.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):
return self.get_properties().get_value("version")
56 changes: 56 additions & 0 deletions bundle-workflow/src/manifests_workflow/component_opensearch_min.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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 re
import subprocess

from git.git_repository import GitRepository
from manifests_workflow.component import Component
from system.properties_file import PropertiesFile


class ComponentOpenSearchMin(Component):
def __init__(self, repo, snapshot=False):
super().__init__("OpenSearch", repo, snapshot)

@classmethod
def get_root_branches(self):
branches = ["main"]
remote_branches = (
subprocess.check_output(
"git ls-remote https://github.com/opensearch-project/OpenSearch.git refs/heads/* | cut -f2 | cut -d/ -f3",
shell=True,
)
.decode()
.split("\n")
)
branches.extend(filter(lambda b: re.match(r"[\d]+.[\dx]*", b), remote_branches))
return branches

@classmethod
def checkout(self, path, branch="main", snapshot=False):
return ComponentOpenSearchMin(
GitRepository(
"https://github.com/opensearch-project/OpenSearch.git", branch, path
),
snapshot,
)

def publish_to_maven_local(self):
cmd = self.gradle_cmd(
"publishToMavenLocal", {"build.snapshot": str(self.snapshot).lower()}
)
self.git_repo.execute_silent(cmd)

def get_properties(self):
cmd = self.gradle_cmd(
"properties", {"build.snapshot": str(self.snapshot).lower()}
)
return PropertiesFile(self.git_repo.output(cmd))

@property
def version(self):
return self.get_properties().get_value("version")
Loading

0 comments on commit cba6d14

Please sign in to comment.