|
13 | 13 | from typing import Dict, List, Type, Union
|
14 | 14 |
|
15 | 15 | import ruamel.yaml
|
| 16 | +from packaging.version import Version |
| 17 | +from packaging.version import parse as version_parse |
16 | 18 |
|
17 |
| -from manifests.component_manifest import ComponentFromSource |
18 |
| -from manifests.input_manifest import InputComponents, InputManifest |
| 19 | +from manifests.input_manifest import InputManifest |
19 | 20 | from manifests.manifests import Manifests
|
20 | 21 | from manifests_workflow.component_opensearch import ComponentOpenSearch
|
21 | 22 | from manifests_workflow.component_opensearch_dashboards_min import ComponentOpenSearchDashboardsMin
|
@@ -84,92 +85,75 @@ def update(
|
84 | 85 | component_klass: Type[ComponentOpenSearch],
|
85 | 86 | keep: bool = False,
|
86 | 87 | ) -> None:
|
87 |
| - known_versions = self.versions |
| 88 | + known_versions = sorted(self.versions, key=version_parse) |
| 89 | + branch_versions: Dict = {} |
88 | 90 | logging.info(f"Known versions: {known_versions}")
|
89 |
| - main_versions: Dict = {} |
90 | 91 | with TemporaryDirectory(keep=keep, chdir=True) as work_dir:
|
91 | 92 | logging.info(f"Checking out components into {work_dir.name}")
|
92 | 93 |
|
93 | 94 | # check out and build #main, 1.x, etc.
|
94 |
| - branches = min_klass.branches() |
| 95 | + branches = sorted(min_klass.branches()) |
95 | 96 |
|
96 | 97 | logging.info(f"Checking {self.name} {branches} branches")
|
97 | 98 | for branch in branches:
|
98 |
| - c = min_klass.checkout( |
| 99 | + min_component_klass = min_klass.checkout( |
99 | 100 | path=os.path.join(work_dir.name, self.name.replace(" ", ""), branch),
|
100 | 101 | branch=branch,
|
101 | 102 | )
|
102 | 103 |
|
103 |
| - version = c.version |
| 104 | + version = min_component_klass.version |
104 | 105 | logging.info(f"{self.name}#{branch} is version {version}")
|
105 |
| - if version not in main_versions.keys(): |
106 |
| - main_versions[version] = [c] |
107 |
| - |
108 |
| - if component_klass is not None: |
109 |
| - # components can increment their own version first without incrementing min |
110 |
| - manifest = self.latest |
111 |
| - logging.info(f"Examining components in the latest manifest of {manifest.build.name} ({manifest.build.version})") |
112 |
| - for component in manifest.components.values(): |
113 |
| - if component.name == self.name: |
114 |
| - continue |
115 |
| - |
116 |
| - if type(component) is ComponentFromSource: |
117 |
| - logging.info(f"Checking out {component.name}#main") |
118 |
| - component = component_klass.checkout( |
119 |
| - name=component.name, |
120 |
| - path=os.path.join(work_dir.name, component.name), |
121 |
| - opensearch_version=manifest.build.version, |
122 |
| - repo_url=component.repository, |
123 |
| - branch="main", |
124 |
| - ) |
125 |
| - |
126 |
| - component_version = component.version |
127 |
| - if component_version: |
128 |
| - release_version = ".".join(component_version.split(".")[:3]) |
129 |
| - if release_version not in main_versions.keys(): |
130 |
| - main_versions[release_version] = [] |
131 |
| - main_versions[release_version].append(component) |
132 |
| - logging.info(f"{component.name}#main is version {release_version} (from {component_version})") |
133 |
| - |
134 |
| - # summarize |
135 |
| - logging.info("Found versions on main:") |
136 |
| - for main_version in main_versions.keys(): |
137 |
| - for component in main_versions[main_version]: |
138 |
| - logging.info(f" {component.name}={main_version}") |
| 106 | + if version not in branch_versions: |
| 107 | + branch_versions[version] = branch |
139 | 108 |
|
140 | 109 | # generate new manifests
|
141 |
| - for release_version in sorted(main_versions.keys() - known_versions): |
142 |
| - self.write_manifest(release_version, main_versions[release_version]) |
143 |
| - self.add_to_cron(release_version) |
144 |
| - self.add_to_versionincrement_workflow(release_version) |
145 |
| - |
146 |
| - def create_manifest(self, version: str, components: List = []) -> InputManifest: |
147 |
| - templates_base_path = os.path.join(self.manifests_path(), "templates") |
148 |
| - template_version_folder = version.split(".")[0] + ".x" |
149 |
| - template_full_path = os.path.join(templates_base_path, self.prefix, template_version_folder, "manifest.yml") |
150 |
| - if not os.path.exists(template_full_path): |
151 |
| - template_full_path = os.path.join(templates_base_path, self.prefix, "default", "manifest.yml") |
| 110 | + new_versions = sorted(branch_versions.keys() - known_versions, key=version_parse) |
| 111 | + logging.info(f"New Versions: {new_versions}") |
| 112 | + for new_version_entry in new_versions: |
| 113 | + self.write_manifest(new_version_entry, branch_versions[new_version_entry], known_versions) |
| 114 | + self.add_to_cron(new_version_entry) |
| 115 | + self.add_to_versionincrement_workflow(new_version_entry) |
| 116 | + known_versions.append(new_version_entry) |
| 117 | + |
| 118 | + def create_manifest(self, version: str, branch: str, known_versions: List[str]) -> InputManifest: |
| 119 | + # If : No known_versions manifests exist or new version smaller than the min(known_versions), create new manifests from the templates |
| 120 | + # (1.0.0-3.0.0 based on template 1.x-3.x, 4.0.0+ from default.x, previous behavior) |
| 121 | + # Else: Create new manifests based on the latest version before the new version |
| 122 | + # (2.12.1 from 2.12.0, 2.13.0 from 2.12.1, 3.0.0 from 2.13.0, 4.0.0 from 3.0.0, etc.) |
| 123 | + if not known_versions or Version(version) < Version(min(known_versions, key=version_parse)): |
| 124 | + logging.info("No previous version exist before {version}, create with templates") |
| 125 | + templates_base_path = os.path.join(self.manifests_path(), "templates") |
| 126 | + template_version_folder = version.split(".")[0] + ".x" |
| 127 | + template_full_path = os.path.join(templates_base_path, self.prefix, template_version_folder, "manifest.yml") |
| 128 | + if not os.path.exists(template_full_path): |
| 129 | + template_full_path = os.path.join(templates_base_path, self.prefix, "default", "manifest.yml") |
| 130 | + else: |
| 131 | + previous_versions = [v for v in known_versions if Version(v) < Version(version)] |
| 132 | + base_version = max(previous_versions, key=version_parse) |
| 133 | + logging.info(f"Base Version: {base_version} is the highest version before {version}") |
| 134 | + template_full_path = os.path.join(self.manifests_path(), base_version, f"{self.prefix}-{base_version}.yml") |
| 135 | + if not os.path.exists(template_full_path): |
| 136 | + template_full_path = os.path.join(self.legacy_manifests_path(), base_version, f"{self.prefix}-{base_version}.yml") |
| 137 | + |
| 138 | + logging.info(f"Using {template_full_path} as the base manifest") |
152 | 139 |
|
153 | 140 | manifest = InputManifest.from_file(open(template_full_path))
|
154 | 141 |
|
155 | 142 | manifest.build.version = version
|
156 |
| - manifests_components = [] |
157 | 143 |
|
158 |
| - for component in components: |
159 |
| - logging.info(f" Adding {component.name}") |
160 |
| - manifests_components.append(component.to_dict()) |
| 144 | + for component in manifest.components.select(): |
| 145 | + component.ref = branch # type: ignore |
161 | 146 |
|
162 |
| - manifest.components = InputComponents(manifests_components) # type: ignore |
163 | 147 | return manifest
|
164 | 148 |
|
165 |
| - def write_manifest(self, version: str, components: List = []) -> None: |
| 149 | + def write_manifest(self, version: str, branch: str, known_versions: List[str]) -> None: |
166 | 150 | logging.info(f"Creating new version: {version}")
|
167 |
| - manifest = self.create_manifest(version, components) |
| 151 | + manifest = self.create_manifest(version, branch, known_versions) |
168 | 152 | manifest_dir = os.path.join(self.manifests_path(), version)
|
169 | 153 | os.makedirs(manifest_dir, exist_ok=True)
|
170 | 154 | manifest_path = os.path.join(manifest_dir, f"{self.prefix}-{version}.yml")
|
171 | 155 | manifest.to_file(manifest_path)
|
172 |
| - logging.info(f"Wrote {manifest_path}") |
| 156 | + logging.info(f"Wrote {manifest_path} as the new manifest") |
173 | 157 |
|
174 | 158 | def add_to_cron(self, version: str) -> None:
|
175 | 159 | logging.info(f"Adding new version to cron: {version}")
|
|
0 commit comments