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
This commit is contained in:
committed by
Jan Möbius
parent
a85ac6894b
commit
7ab45135cc
@@ -2,19 +2,29 @@
|
||||
|
||||
import sys, os, re
|
||||
|
||||
# Version 3
|
||||
|
||||
# Script for automated gitlab-ci creation
|
||||
# Assembles the gitlab ci from master template file:
|
||||
master_file = 'ci-master.yml'
|
||||
# Lines in the master file are copied to the resulting
|
||||
# assemblied gitlab ci file
|
||||
target_file = '../../.gitlab-ci.yml'
|
||||
# Lines containing the String {xxx} are interpreted
|
||||
# Lines that are {xxx} Strings are interpreted
|
||||
# as import statement. Therefore the file xxx is imported
|
||||
# into that line.
|
||||
# Lines that are {xxx,option1=...,option2=...} includes
|
||||
# the file xxx but replaces {{option1}} etc with specified
|
||||
# string.
|
||||
error_on_path_redirection = True
|
||||
# Notice that xxx can not contain path redirections
|
||||
# like .. and /
|
||||
|
||||
# Max import recursion
|
||||
maxFileRecursionDepth = 4
|
||||
# Max filename used for pretty print
|
||||
maxFilnameChars = 30
|
||||
|
||||
|
||||
# Prefix to prepend to master file
|
||||
autogenerated_notice = """#############################################################
|
||||
@@ -25,6 +35,7 @@ autogenerated_notice = """######################################################
|
||||
# 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 #
|
||||
# #
|
||||
#############################################################
|
||||
|
||||
@@ -52,13 +63,37 @@ def readFile(filename):
|
||||
file.close()
|
||||
return content
|
||||
|
||||
# Parse File Import String for variable replacements
|
||||
def fetchVariableReplacers(variablesGrep):
|
||||
if (variablesGrep == None):
|
||||
return {}
|
||||
|
||||
regex_option = r"([^\}\n\=,]+)\=([^\}\n\=,]+)"
|
||||
pattern = re.compile(regex_option, flags=re.MULTILINE)
|
||||
result = {}
|
||||
|
||||
for (key, value) in re.findall(pattern, variablesGrep):
|
||||
|
||||
if (key != None and value != None):
|
||||
key = key.strip()
|
||||
result[key] = value
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# Assembles the file in memory and returns file content as string
|
||||
def assembleTarget(master, depth=3):
|
||||
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
|
||||
print_prefix_inverse = ""
|
||||
for i in range(0, depth):
|
||||
print_prefix_inverse = print_prefix_inverse + "\t"
|
||||
|
||||
master_content = readFile(master)
|
||||
regex_import_stmt = r"^\ *\{([^\}\n]+)\}\ *$"
|
||||
regex_import_stmt = r"^\ *\{([^\},\n]+)(,[^=\n\}\,]+\=[^\}\n,]*)*\}\ *$"
|
||||
regex_import_comp = re.compile(regex_import_stmt)
|
||||
master_content_list = master_content.splitlines()
|
||||
|
||||
@@ -72,12 +107,21 @@ def assembleTarget(master, depth=3):
|
||||
importFile = match.groups()[0]
|
||||
if importFile:
|
||||
# Found import statement
|
||||
print("Importing file: "+importFile)
|
||||
print(print_prefix+"Importing file: "+importFile.ljust(maxFilnameChars), end="")
|
||||
|
||||
if not isValidImportFilename(importFile):
|
||||
raise "Invalid filename "+importFile+ ". Do not include path redirections"
|
||||
|
||||
variablesGrep = match.string
|
||||
variableReplacers = fetchVariableReplacers(variablesGrep)
|
||||
|
||||
print(print_prefix_inverse, variableReplacers)
|
||||
|
||||
import_content = assembleTarget(importFile, depth=depth-1)
|
||||
|
||||
for key, value in variableReplacers.items():
|
||||
import_content = import_content.replace(r"{{"+key+r"}}", value)
|
||||
|
||||
import_content_list = import_content.splitlines()
|
||||
master_content_list.pop(cur_index)
|
||||
for new_line in reversed(import_content_list):
|
||||
@@ -108,4 +152,4 @@ def main():
|
||||
|
||||
# Execute main function
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user