From 4fd7f8a8bf078eb95b6f1f87864de8a50a6524fe Mon Sep 17 00:00:00 2001
From: Dmitry Petrov <dmitry.petrov@rtsoft.de>
Date: Tue, 7 May 2024 16:08:00 +0200
Subject: [PATCH] report_image_diff: get rid of hardcode

Parse machines, pipeline names and distros from gitlab yaml file instead of
harcoding these values in the script.
---
 scripts/report_image_diff.py | 43 +++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/scripts/report_image_diff.py b/scripts/report_image_diff.py
index a26d449f..8e930fdc 100755
--- a/scripts/report_image_diff.py
+++ b/scripts/report_image_diff.py
@@ -1,10 +1,13 @@
 #!/usr/bin/env python3
 import argparse
+import base64
 import fnmatch
 import logging
+import sys
 from difflib import unified_diff
 
 from gitlab import Gitlab
+from ruamel.yaml import YAML
 
 import common
 from buildartifacts import BuildArtifacts
@@ -113,18 +116,36 @@ def main():
     )[0]
     build__mr = FullBuildPipeline(manifest_project, manifest_commit__mr.id)
 
-    machines = (
-        "seco-genio510",
-        "seco-genio700",
-        "seco-mx6",
-        "seco-mx6ull",
-        "seco-mx8mm",
-        "seco-mx8mp",
+    yml_file = manifest_project.files.get(
+        file_path=".gitlab-ci.yml", ref=args.target_branch
     )
-    pipelines_and_distros = {
-        "fngsystem-pipeline": "seconorth-fngsystem",
-        "yocto-pipeline": "seconorth-wayland",
-    }
+    yaml = YAML(typ="safe")
+    yml_dict = yaml.load(base64.b64decode(yml_file.content).decode("utf-8"))
+    try:
+        machines = yml_dict["generate-build-pipeline"]["variables"]["MACHINES"].split()
+    except KeyError:
+        sys.exit("Failed to extract MACHINES from .gitlab-ci.yml")
+
+    pipelines_and_distros = {}
+    for key in yml_dict.keys():
+        if not fnmatch.fnmatch(key, "*-pipeline"):
+            continue
+
+        if fnmatch.fnmatch(key, "generate-*") or fnmatch.fnmatch(key, "sdk-*"):
+            continue
+
+        try:
+            if yml_dict[key]["variables"]["MANUAL_BUILD"].lower() == "true":
+                continue
+        except KeyError:
+            pass
+
+        if fnmatch.fnmatch(key, "generate-*") or fnmatch.fnmatch(key, "sdk-*"):
+            continue
+        try:
+            pipelines_and_distros[key] = yml_dict[key]["variables"]["YOCTO_DISTRO"]
+        except KeyError:
+            sys.exit(f"Failed to extract YOCTO_DISTRO for '{key}' from .gitlab-ci.yml")
 
     summary = ""
 
-- 
GitLab