From 6024776b2cfe9a54a422921eba0f37e14f8c6dad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dennis=20Gl=C3=A4ser?= <dennis.glaeser@iws.uni-stuttgart.de>
Date: Wed, 14 Apr 2021 13:27:49 +0200
Subject: [PATCH] [ci][makeyml] use multiline command

For a large number of tests, the resulting .yml could not be interpreted
by the GitLab ci
---
 .gitlab-ci/makepipelineconfig.py | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci/makepipelineconfig.py b/.gitlab-ci/makepipelineconfig.py
index 0dc3537452..14e7221a6e 100644
--- a/.gitlab-ci/makepipelineconfig.py
+++ b/.gitlab-ci/makepipelineconfig.py
@@ -44,6 +44,17 @@ with open(args['outfile'], 'w') as ymlFile:
         commands = [commandIndentation + '- ' + comm for comm in commands]
         return '\n'.join(commands)
 
+    def makeMultiLineCommand(commandParts):
+
+        # add indentation to each part
+        result = [commandIndentation + '  ' + cp for cp in commandParts]
+
+        # add line break token at the end of each part
+        result = ' \\\n'.join(result)
+
+        # add multiline trigger token at the beginning
+        return '|\n' + result
+
     # if no configuration is given, build and run all tests
     if not args['testconfig']:
         buildCommand = [duneConfigCommand,
@@ -56,7 +67,7 @@ with open(args['outfile'], 'w') as ymlFile:
         with open(args['testconfig']) as configFile:
             config = json.load(configFile)
 
-            testNames = config.keys()
+            testNames = list(config.keys())
             targetNames = [tc['target'] for tc in config.values()]
 
             if not targetNames:
@@ -74,10 +85,9 @@ with open(args['outfile'], 'w') as ymlFile:
                     'rm -f TestMakefile && touch TestMakefile',
                     'echo "include CMakeFiles/Makefile2" >> TestMakefile',
                     'echo "" >> TestMakefile',
-                    '|\n'
-                    + commandIndentation
-                    + '  echo "build_selected_tests: {}" >> TestMakefile'
-                      .format(' '.join(targetNames)),
+                    makeMultiLineCommand(['echo "build_selected_tests:"']
+                                         + targetNames
+                                         + ['>> TestMakefile']),
                     'make -f TestMakefile -j4 build_selected_tests']
 
             if not testNames:
@@ -86,8 +96,10 @@ with open(args['outfile'], 'w') as ymlFile:
                                'dune-ctest -R NOOP']
             else:
                 testCommand = ['cd build-cmake',
-                               'dune-ctest -j4 --output-on-failure -R {}'
-                               .format(' '.join(testNames))]
+                               makeMultiLineCommand(['dune-ctest -j4 '
+                                                     '--output-on-failure '
+                                                     '-R']
+                                                    + testNames)]
 
     substituteAndWrite({'build_script': makeScriptString(buildCommand),
                         'test_script': makeScriptString(testCommand)})
-- 
GitLab