Commit 4786e2ec authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[ci] add script to create .yml file from test config

parent fe30315e
image: $$IMAGE
- build
- test
- if: $$CI_PIPELINE_SOURCE=="parent_pipeline"
build dumux:
stage: build
- build-cmake
expire_in: 3 hours
test dumux:
stage: test
- job: build dumux
artifacts: true
junit: junit/dumux-cmake.xml
#!/usr/bin/env python3
import os
import sys
import json
import string
from argparse import ArgumentParser
# require Python 3
if sys.version_info.major < 3:
sys.exit('Python 3 required')
parser = ArgumentParser(description='Generate dumux test pipeline .yml file')
parser.add_argument('-o', '--outfile', required=True,
help='Specify the file to write the pipeline definition')
parser.add_argument('-c', '--testconfig', required=False,
help='Specify a test configuration file containing the '
'tests that should be run within the test pipeline')
parser.add_argument('-t', '--template', required=False,
help='Specify the template .yml file to be used')
parser.add_argument('-i', '--indentation', required=False, default=4,
help='Specify the indentation for the script commands')
args = vars(parser.parse_args())
# substitute content from template and write to target
def substituteAndWrite(mapping):
template = args['template']
if not os.path.exists(template):
sys.exit("Template file '" + template + "' could not be found")
with open(args['outfile'], 'w') as ymlFile:
raw = string.Template(open(template).read())
with open(args['outfile'], 'w') as ymlFile:
def makeScriptString(commands):
commands = [' '*args['indentation'] + '- ' + comm for comm in commands]
return '\n'.join(commands)
# if no configuration is given, build and run all tests
if not args['testconfig']:
buildCommand = ['dunecontrol --opts=$DUNE_OPTS_FILE --current all',
'dunecontrol --opts=$DUNE_OPTS_FILE --current '
'make -k -j4 build_tests']
testCommand = ['cd build-cmake', 'dune-ctest -j4 --output-on-failure']
# otherwise, parse data from the given configuration file
with open(args['testconfig']) as configFile:
config = json.load(configFile)
testNames = config.keys()
targetNames = [tc['target'] for tc in config.values()]
# The MakeFile generated by cmake contains .NOTPARALLEL statement,
# as it only allows one call to `CMakeFiles/Makefile2` at a time.
# Parallelism is taken care of within that latter Makefile. Thus,
# we let the script create a small custom makeFile here on top of
# `Makefile2`, where we define a new target to be built in parallel
buildCommand = [
'rm TestMakefile', 'touch TestMakefile',
'echo "include CMakeFiles/Makefile2" >> TestMakefile',
'echo "" >> TestMakefile',
'echo "build_selected_tests: {}" >> TestMakefile'
.format(' '.join(targetNames)),
'make -j4 build_selected_tests']
testCommand = ['cd build-cmake',
'dune-ctest -j4 --output-on-failure -R {}'
.format(' '.join(testNames))]
substituteAndWrite({'build_script': makeScriptString(buildCommand),
'test_script': makeScriptString(testCommand)})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment