From 92387f4c2af8e1857f06db1d344c038e87a7715d Mon Sep 17 00:00:00 2001 From: Johannes Lenzen Date: Tue, 4 Feb 2020 12:29:33 +0100 Subject: [PATCH] Changed the .gitlab-ci.yml structure Beginned with new building system .gitlab-ci.yml can now be generated by the script assemble-gitlab-ci.py. Therefore the .gitlab-ci.yml configuration file can be split into several smaller files --- .gitlab-ci.yml | 2 +- CI/gitlab-ci/assemble-gitlab-ci.py | 45 ++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 996966dc..d7414c1d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ # This is an auto generated file. Do not make # # changes to this file. They possible will be overriden. # # # -# To make persistent changes changes files in # +# To make persistent changes, changes files in # # ./CI/gitlab-ci/ ... # # and regenerate this file with the configuration tool # # python3 ./CI/gitlab-ci/assemble-gitlab-ci.py # diff --git a/CI/gitlab-ci/assemble-gitlab-ci.py b/CI/gitlab-ci/assemble-gitlab-ci.py index 79b7a2ea..02b2eade 100755 --- a/CI/gitlab-ci/assemble-gitlab-ci.py +++ b/CI/gitlab-ci/assemble-gitlab-ci.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 -import sys, os, re +import sys, os, re, yaml, hashlib -# Version 3 +# Version 3.2 # Script for automated gitlab-ci creation # Assembles the gitlab ci from master template file: @@ -32,7 +32,7 @@ autogenerated_notice = """###################################################### # This is an auto generated file. Do not make # # changes to this file. They possible will be overriden. # # # -# To make persistent changes changes files in # +# To make persistent changes, changes files in # # ./CI/gitlab-ci/ ... # # and regenerate this file with the configuration tool # # python3 ./CI/gitlab-ci/assemble-gitlab-ci.py # @@ -86,10 +86,10 @@ def assembleTarget(master, depth=maxFileRecursionDepth): if depth < 0: raise "Max depth reached. Possible circular import?" print_prefix = "" - for i in range(0, maxFileRecursionDepth-depth): - print_prefix = " | \t" + print_prefix + for _ in range(0, maxFileRecursionDepth-depth): + print_prefix = print_prefix + " | \t" print_prefix_inverse = "" - for i in range(0, depth): + for _ in range(0, depth): print_prefix_inverse = print_prefix_inverse + "\t" master_content = readFile(master) @@ -139,13 +139,34 @@ def main(): os.chdir(findCIAssemblyDirectory()) target_content = autogenerated_notice target_content += assembleTarget(master_file) - print("Writing config to file "+target_file) - target_file_handle = open(target_file, "w") - target_file_handle.write(target_content) - target_file_handle.write("\n") - target_file_handle.flush() - target_file_handle.close() + m = hashlib.sha256() + m.update(readFile(target_file).encode('utf-8')) + hash_original = m.hexdigest() + m = hashlib.sha256() + m.update(target_content.encode('utf-8')) + m.update("\n".encode('utf-8')) + hash_new = m.hexdigest() + + print("Old checksum: ", hash_original) + print("New checksum: ", hash_new) + + if (hash_original == hash_new): + print("No changes made: Skipping file write") + else: + print("File differs") + print("Writing config to file "+target_file) + target_file_handle = open(target_file, "w") + target_file_handle.write(target_content) + target_file_handle.write("\n") + target_file_handle.flush() + target_file_handle.close() + + try: + yaml.load(target_content, Loader=yaml.SafeLoader) + print("Yaml syntax check: OK") + except Exception as e: + print("Invalid yaml syntax:", e) print("Finished.")