Skip to content

Commit 26d3827

Browse files
author
Vasileios Karakasis
authored
Merge pull request #2514 from rsarm/ci-cli-options
[feat] Add `--mode` option to GitLab CI pipeline command
2 parents 0a6decc + 1adb384 commit 26d3827

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

docs/tutorial_tips_tricks.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,12 @@ The following is an example of ``.gitlab-ci.yml`` file that does exactly that:
385385
It defines two stages.
386386
The first one, called ``generate``, will call ReFrame to generate the pipeline specification for the desired tests.
387387
All the usual `test selection options <manpage.html#test-filtering>`__ can be used to select specific tests.
388-
ReFrame will process them as usual, but instead of running the selected tests, it will generate the correct steps
389-
for running each test individually as a Gitlab job. We then pass the generated CI pipeline file to second phase as
390-
an artifact and we are done! If ``image`` keyword is defined in ``.gitlab-ci.yml``, the emitted pipeline will use
391-
the same image as the one defined in the parent pipeline.
388+
ReFrame will process them as usual, but instead of running the selected tests, it will generate the correct steps for running each test individually as a Gitlab job in a child pipeline.
389+
The generated ReFrame command that will run each individual test reuses the :option:`-C`, :option:`-R`, :option:`-v` and :option:`--mode` options passed to the initial invocation of ReFrame that was used to generate the pipeline.
390+
Users can define CI-specific execution modes in their configuration in order to pass arbitrary options to the ReFrame invocation in the child pipeline.
391+
392+
Finally, we pass the generated CI pipeline file to second phase as an artifact and we are done!
393+
If ``image`` keyword is defined in ``.gitlab-ci.yml``, the emitted pipeline will use the same image as the one defined in the parent pipeline.
392394
Besides, each job in the generated pipeline will output a separate junit report which can be used to create GitLab badges.
393395

394396
The following figure shows one part of the automatically generated pipeline for the test graph depicted `above <#fig-deps-complex>`__.

reframe/frontend/ci.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import reframe.core.runtime as runtime
1212

1313

14-
def _emit_gitlab_pipeline(testcases):
14+
def _emit_gitlab_pipeline(testcases, child_pipeline_opts):
1515
config = runtime.runtime().site_config
1616

1717
# Collect the necessary ReFrame invariants
@@ -44,7 +44,8 @@ def rfm_command(testcase):
4444
f'--restore-session={restore_files}' if restore_files else '',
4545
f'--report-junit={testcase.check.unique_name}-report.xml',
4646
f'{"".join("-" + verbosity)}' if verbosity else '',
47-
'-n', f"'^{testcase.check.unique_name}$'", '-r'
47+
'-n', f"'^{testcase.check.unique_name}$'", '-r',
48+
*child_pipeline_opts
4849
])
4950

5051
max_level = 0 # We need the maximum level to generate the stages section
@@ -77,9 +78,10 @@ def rfm_command(testcase):
7778
return json
7879

7980

80-
def emit_pipeline(fp, testcases, backend='gitlab'):
81+
def emit_pipeline(fp, testcases, child_pipeline_opts=None, backend='gitlab'):
8182
if backend != 'gitlab':
8283
raise errors.ReframeError(f'unknown CI backend {backend!r}')
8384

84-
yaml.dump(_emit_gitlab_pipeline(testcases), stream=fp,
85+
child_pipeline_opts = child_pipeline_opts or []
86+
yaml.dump(_emit_gitlab_pipeline(testcases, child_pipeline_opts), stream=fp,
8587
indent=2, sort_keys=False, width=sys.maxsize)

reframe/frontend/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,11 @@ def _case_failed(t):
11101110
list_checks(testcases, printer)
11111111
printer.info('[Generate CI]')
11121112
with open(options.ci_generate, 'wt') as fp:
1113-
ci.emit_pipeline(fp, testcases)
1113+
child_pipeline_opts = []
1114+
if options.mode:
1115+
child_pipeline_opts.append(f'--mode={options.mode}')
1116+
1117+
ci.emit_pipeline(fp, testcases, child_pipeline_opts)
11141118

11151119
printer.info(
11161120
f' Gitlab pipeline generated successfully '

0 commit comments

Comments
 (0)