diff --git a/scripts/collect_release_information.py b/scripts/collect_release_information.py index aaff3ca2d71b264532fab42b4d92a3fe6736dd4a..6df0d05d7ee80277256de3ecacab732e0804cb5e 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__":