diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 464ce48047..90343dd650 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,22 +1,26 @@ -pytest: - image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.2.base +stages: + - generate + - trigger + - test + +generator: + stage: generate + image: python:3.7-alpine tags: - docker before_script: - - source ~/.bashrc - - git submodule init - - git submodule update - - conda activate hls4ml-testing - - pip install .[profiling] - script: + - pip install pyyaml + script: - cd test/pytest - - pytest -rA --cov-report xml --cov-report term --cov=hls4ml --junitxml=report.xml --randomly-seed=42 --randomly-dont-reorganize --randomly-dont-reset-seed + - python generate_ci_yaml.py artifacts: - when: always - reports: - junit: - - test/pytest/report.xml - cobertura: - - test/pytest/coverage.xml paths: - - test/pytest/hls4mlprj*.tar.gz + - test/pytest/pytests.yml + +pytests: + stage: trigger + trigger: + include: + - artifact: test/pytest/pytests.yml + job: generator + strategy: depend diff --git a/test/pytest/generate_ci_yaml.py b/test/pytest/generate_ci_yaml.py new file mode 100644 index 0000000000..5e50ea6468 --- /dev/null +++ b/test/pytest/generate_ci_yaml.py @@ -0,0 +1,49 @@ +import yaml +import glob + +base = """ +.pytest: + stage: test + image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.2.base + tags: + - docker + before_script: + - source ~/.bashrc + - if [ $EXAMPLEMODEL == 1 ]; then git submodule init; git submodule update; fi + - conda activate hls4ml-testing + - pip install .[profiling] + script: + - cd test/pytest + - pytest $PYTESTFILE -rA --cov-report xml --cov-report term --cov=hls4ml --junitxml=report.xml --randomly-seed=42 --randomly-dont-reorganize --randomly-dont-reset-seed + artifacts: + when: always + reports: + junit: + - test/pytest/report.xml + cobertura: + - test/pytest/coverage.xml + paths: + - test/pytest/hls4mlprj*.tar.gz +""" + +template = """ +pytest.{}: + extends: .pytest + variables: + PYTESTFILE: {} + EXAMPLEMODEL: {} +""" + +def uses_example_model(test_filename): + with open(test_filename, 'r') as f: + content = f.read() + return 'example-models/' in content + +yml = yaml.safe_load(base) +tests = glob.glob('test_*.py') +for test in tests: + name = test.replace('test_','').replace('.py','') + yml.update(yaml.safe_load(template.format(name, 'test_{}.py'.format(name), int(uses_example_model(test))))) + +yamlfile = open('pytests.yml', 'w') +yaml.safe_dump(yml, yamlfile)