From ae764fbc3e56488b362fbb3ed37ed8465287db80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6ppner?= <jonas.hoeppner@garz-fricke.com> Date: Tue, 19 Mar 2024 10:41:22 +0000 Subject: [PATCH] CI: Confluence page: Fix not created mx6 section The function that merges the variables of the different jobs, i.e: `MACHINE="mx6"` `MACHINE="mx6ull"` used python `in` to check if a value already exists. But `"mx6" in "mx6ull"` is true, so mx6 was dropped. This rewrites it, storing the variables in a set (which is unique automatically) instead of space seperated strings. Space seperation is added before printing the variables to be used on on the shell. --- scripts/collect_release_information.py | 36 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/scripts/collect_release_information.py b/scripts/collect_release_information.py index aaff3ca2..6df0d05d 100755 --- a/scripts/collect_release_information.py +++ b/scripts/collect_release_information.py @@ -30,7 +30,7 @@ def get_job_env_variables( env_file: name of the GitLab dotenv file to read variables from Returns: - Dictionary of variables with 'name' and 'value' fields + Dictionary of variables with 'name' and an set of 'value' fields """ variables = {} @@ -52,7 +52,11 @@ def get_job_env_variables( for line in lines: name, value = line.partition("=")[::2] value = value.strip("'\" ") - variables[name] = value + if name not in variables.keys(): + variables[name] = set() + for elem in value.split(" "): + if len(elem) > 0: + variables[name].add(elem) return variables @@ -94,24 +98,26 @@ def get_pipeline_variable_value(variables: ProjectPipelineVariableManager, key: return variable.value -def merge_variables(first: dict[str, str], second: dict[str, str]) -> dict[str, str]: - """Merge two dictionaries of variables. If a variable exists in both dictionaries - and one value is not already contained in the other, concatenate its values with - a space in between. +def merge_variables( + first: dict[str, set[str]], second: dict[str, set[str]] +) -> dict[str, set[str]]: + """Merge two dictionaries of variables, each variable stored as set. + If a variable exists in both dictionaries the values are merged into one + without duplicates. Args: first: a dictionary containing variables - secondary: a dictionary containing variables + second: a dictionary containing variables Returns: A dictionary containing merged variables """ merged = first - for key in second: - if key not in first or first[key] in second[key]: - merged[key] = second[key] - elif second[key] not in first[key]: - merged[key] = f"{first[key]} {second[key]}" + for key, value in second.items(): + if key not in first: + merged[key] = value + else: + merged[key] |= value return merged @@ -169,6 +175,10 @@ def main(): ) # Get all parallel child pipelines with the same Confluence configuration + # For example the yocto build pipeline and the sdk pipeline should end up + # and the same confluence page, so both need to be found + # To find it, go up on level in the pipeline hierarchy and search child pipelines + # with the same confluence destination pipelines = [] parent_pipeline = get_parent_pipeline(project, pipeline) if parent_pipeline: @@ -241,7 +251,7 @@ def main(): # Print all variables in a shell compatible form for k, v in sorted(variables.items()): - print(f'{k}="{v}"') + print(f'{k}="{" ".join(v)}"') if __name__ == "__main__": -- GitLab