From 6001e38f79e1c0b414527c16c2b61cada93ca507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Fri, 14 Jun 2024 11:32:43 +0200 Subject: [PATCH] Versions: Add alternate tags --- github_app_geo_project/module/utils.py | 17 ++++++-- .../module/versions/__init__.py | 42 +++++++++++-------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/github_app_geo_project/module/utils.py b/github_app_geo_project/module/utils.py index f69f692e43c..7063878c206 100644 --- a/github_app_geo_project/module/utils.py +++ b/github_app_geo_project/module/utils.py @@ -662,12 +662,23 @@ def get_alternate_versions(security: c2cciutils.security.Security, branch: str) _LOGGER.warning("No Version column in the SECURITY.md") return [] + last = False + result = [] for row in security.data: if row[version_index] == branch: - return [v.strip() for v in row[alternate_index].split(",") if v.strip()] + result = [v.strip() for v in row[alternate_index].split(",") if v.strip()] + last = True + elif last: + last = False + break + + if last: + result.append("latest") - _LOGGER.warning("Branch %s not found in the SECURITY.md", branch) - return [] + if not result: + _LOGGER.warning("Branch %s not found in the SECURITY.md", branch) + + return result def manage_updated(status: dict[str, Any], key: str, days_old: int = 2) -> None: diff --git a/github_app_geo_project/module/versions/__init__.py b/github_app_geo_project/module/versions/__init__.py index 86b83b36b07..4d23804beba 100644 --- a/github_app_geo_project/module/versions/__init__.py +++ b/github_app_geo_project/module/versions/__init__.py @@ -239,13 +239,16 @@ async def process( raise VersionException("Failed to clone the repository") version_status = status.versions[version] - for alternate in context.module_event_data.alternate_versions or []: - status.versions[alternate] = version_status version_status.names_by_datasource.clear() version_status.dependencies_by_datasource.clear() transversal_status = context.transversal_status - _get_names(context, version_status.names_by_datasource, version) + _get_names( + context, + version_status.names_by_datasource, + version, + alternate_versions=context.module_event_data.alternate_versions, + ) message = module_utils.HtmlMessage( utils.format_json(json.loads(version_status.model_dump_json())["names_by_datasource"]) ) @@ -418,6 +421,7 @@ def _get_names( context: module.ProcessContext[configuration.VersionsConfiguration, _EventData, _TransversalStatus], names_by_datasource: dict[str, _TransversalStatusNameByDatasource], version: str, + alternate_versions: list[str] | None = None, ) -> None: for filename in subprocess.run( # nosec ["git", "ls-files", "pyproject.toml", "*/pyproject.toml"], @@ -455,26 +459,30 @@ def _get_names( docker_config = data.get("publish", {}).get("docker", {}) if docker_config: names = names_by_datasource.setdefault("docker", _TransversalStatusNameByDatasource()).names + all_versions = [version] + if alternate_versions: + all_versions.extend(alternate_versions) for conf in docker_config.get("images", []): for tag in conf.get("tags", ["{version}"]): for repository_conf in docker_config.get( "repository", c2cciutils.configuration.DOCKER_REPOSITORY_DEFAULT ).values(): - repository_server = repository_conf.get("server", False) - add_names = [] - if repository_server: - add_names.append( - f"{repository_server}/{conf.get('name')}:{tag.format(version=version)}" - ) + for ver in all_versions: + repository_server = repository_conf.get("server", False) + add_names = [] + if repository_server: + add_names.append( + f"{repository_server}/{conf.get('name')}:{tag.format(version=ver)}" + ) - else: - add_names = [ - f"{conf.get('name')}:{tag.format(version=version)}", - f"docker.io/{conf.get('name')}:{tag.format(version=version)}", - ] - for add_name in add_names: - if add_name not in names: - names.append(add_name) + else: + add_names = [ + f"{conf.get('name')}:{tag.format(version=ver)}", + f"docker.io/{conf.get('name')}:{tag.format(version=ver)}", + ] + for add_name in add_names: + if add_name not in names: + names.append(add_name) for filename in subprocess.run( # nosec ["git", "ls-files", "package.json", "*/package.json"],