-
Notifications
You must be signed in to change notification settings - Fork 117
[feat] Add new action for generating dynamic Gitlab pipelines #1641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vkarak
merged 16 commits into
reframe-hpc:master
from
victorusu:ci-generate-pipeline-new
Feb 8, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
481f56d
Initial implementation of ci-tags
victorusu 364ec1e
Merge branch 'master' of https://github.com/eth-cscs/reframe
victorusu 1f8aeea
Merge branch 'master' of https://github.com/eth-cscs/reframe
victorusu 2c8677f
Add ci-generate-pipeline cli option
victorusu 0551ff8
Add PyYAML to requirements
victorusu b98c8ff
Merge branch 'master' into ci-generate-pipeline-new
06f3309
Fine tune implementation.
e0ba255
Remove unused import
fcf0023
Adapt YAML code generation to work properly with Gitlab
753b97a
Add unit test for CI generate
66e85a3
Remove unused import from unit tests
57f2318
Fine tune frontend output for the --ci-generate option
2831af0
Document the `--ci-generate` option
ee83d8f
Merge branch 'master' into ci-generate-pipeline-new
4cce474
Address PR comments.
8faebb4
Merge branch 'master' into ci-generate-pipeline-new
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich) | ||
| # ReFrame Project Developers. See the top-level LICENSE file for details. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| import sys | ||
| import yaml | ||
|
|
||
| import reframe.core.exceptions as errors | ||
| import reframe.core.runtime as runtime | ||
|
|
||
|
|
||
| def _emit_gitlab_pipeline(testcases): | ||
| config = runtime.runtime().site_config | ||
|
|
||
| # Collect the necessary ReFrame invariants | ||
| program = 'reframe' | ||
| prefix = 'rfm-stage/${CI_COMMIT_SHORT_SHA}' | ||
| checkpath = config.get('general/0/check_search_path') | ||
| recurse = config.get('general/0/check_search_recursive') | ||
|
|
||
| def rfm_command(testcase): | ||
| if config.filename != '<builtin>': | ||
| config_opt = f'-C {config.filename}' | ||
| else: | ||
| config_opt = '' | ||
|
|
||
| report_file = f'rfm-report-{testcase.level}.json' | ||
| if testcase.level: | ||
| restore_file = f'rfm-report-{testcase.level - 1}.json' | ||
| else: | ||
| restore_file = None | ||
|
|
||
| return ' '.join([ | ||
| program, | ||
| f'--prefix={prefix}', config_opt, | ||
| f'{" ".join("-c " + c for c in checkpath)}', | ||
| f'-R' if recurse else '', | ||
| f'--report-file={report_file}', | ||
| f'--restore-session={restore_file}' if restore_file else '', | ||
| '-n', testcase.check.name, '-r' | ||
| ]) | ||
|
|
||
| max_level = 0 # We need the maximum level to generate the stages section | ||
| json = { | ||
| 'cache': { | ||
| 'key': '${CI_COMMIT_REF_SLUG}', | ||
| 'paths': ['rfm-stage/${CI_COMMIT_SHORT_SHA}'] | ||
| }, | ||
| 'stages': [] | ||
| } | ||
| for tc in testcases: | ||
| json[f'{tc.check.name}'] = { | ||
| 'stage': f'rfm-stage-{tc.level}', | ||
| 'script': [rfm_command(tc)], | ||
| 'artifacts': { | ||
| 'paths': [f'rfm-report-{tc.level}.json'] | ||
| }, | ||
| 'needs': [t.check.name for t in tc.deps] | ||
| } | ||
| max_level = max(max_level, tc.level) | ||
|
|
||
| json['stages'] = [f'rfm-stage-{m}' for m in range(max_level+1)] | ||
| return json | ||
|
|
||
|
|
||
| def emit_pipeline(fp, testcases, backend='gitlab'): | ||
| if backend != 'gitlab': | ||
| raise errors.ReframeError(f'unknown CI backend {backend!r}') | ||
|
|
||
| yaml.dump(_emit_gitlab_pipeline(testcases), stream=fp, | ||
| indent=2, sort_keys=False, width=sys.maxsize) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| argcomplete==1.12.2 | ||
| coverage==5.3 | ||
| importlib_metadata==2.0.0 | ||
| jsonschema==3.2.0 | ||
| pytest==6.2.0 | ||
| pytest-forked==1.3.0 | ||
| pytest-parallel==0.1.0 | ||
| coverage==5.3 | ||
| PyYAML==5.3.1 | ||
| requests==2.25.1 | ||
| setuptools==50.3.0 | ||
| wcwidth==0.2.5 | ||
| argcomplete==1.12.2 | ||
| #+pygelf%pygelf==0.3.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright 2016-2021 Swiss National Supercomputing Centre (CSCS/ETH Zurich) | ||
| # ReFrame Project Developers. See the top-level LICENSE file for details. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
|
|
||
| import io | ||
| import requests | ||
|
|
||
| import reframe.frontend.ci as ci | ||
| import reframe.frontend.dependencies as dependencies | ||
| import reframe.frontend.executors as executors | ||
| from reframe.frontend.loader import RegressionCheckLoader | ||
|
|
||
|
|
||
| def test_ci_gitlab_pipeline(): | ||
| loader = RegressionCheckLoader([ | ||
| 'unittests/resources/checks_unlisted/deps_complex.py' | ||
| ]) | ||
| cases = dependencies.toposort( | ||
| dependencies.build_deps( | ||
| executors.generate_testcases(loader.load_all()) | ||
| )[0] | ||
| ) | ||
| with io.StringIO() as fp: | ||
| ci.emit_pipeline(fp, cases) | ||
| yaml = fp.getvalue() | ||
|
|
||
| response = requests.post('https://gitlab.com/api/v4/ci/lint', | ||
| data={'content': {yaml}}) | ||
| assert response.ok | ||
| assert response.json()['status'] == 'valid' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.