Provide your own script, before_script, and after_script

This commit is contained in:
Scott Wittenburg 2020-06-16 22:01:35 -06:00
parent 4ca7d46e15
commit ace52bd476
5 changed files with 35 additions and 112 deletions

View File

@ -449,7 +449,6 @@ def format_job_needs(phase_name, strip_compilers, dep_jobs,
def generate_gitlab_ci_yaml(env, print_summary, output_file,
custom_spack_repo=None, custom_spack_ref=None,
run_optimizer=False, use_dependencies=False):
# FIXME: What's the difference between one that opens with 'spack'
# and one that opens with 'env'? This will only handle the former.
@ -488,22 +487,6 @@ def generate_gitlab_ci_yaml(env, print_summary, output_file,
os.environ.get('SPACK_IS_PR_PIPELINE', '').lower() == 'true'
)
# Make sure we use a custom spack if necessary
before_script = None
after_script = None
if custom_spack_repo:
if not custom_spack_ref:
custom_spack_ref = 'develop'
before_script = [
('git clone "{0}"'.format(custom_spack_repo)),
'pushd ./spack && git checkout "{0}" && popd'.format(
custom_spack_ref),
'. "./spack/share/spack/setup-env.sh"',
]
after_script = [
'rm -rf "./spack"'
]
ci_mirrors = yaml_root['mirrors']
mirror_urls = [url for url in ci_mirrors.values()]
@ -604,19 +587,27 @@ def generate_gitlab_ci_yaml(env, print_summary, output_file,
except AttributeError:
image_name = build_image
job_script = [
'spack env activate --without-view .',
'spack ci rebuild',
]
if 'script' in runner_attribs:
job_script = [s for s in runner_attribs['script']]
before_script = None
if 'before_script' in runner_attribs:
before_script = [
s for s in runner_attribs['before_script']
]
after_script = None
if 'after_script' in runner_attribs:
after_script = [s for s in runner_attribs['after_script']]
osname = str(release_spec.architecture)
job_name = get_job_name(phase_name, strip_compilers,
release_spec, osname, build_group)
debug_flag = ''
if 'enable-debug-messages' in gitlab_ci:
debug_flag = '-d '
job_scripts = [
'spack env activate --without-view .',
'spack {0}ci rebuild'.format(debug_flag),
]
compiler_action = 'NONE'
if len(phases) > 1:
compiler_action = 'FIND_ANY'
@ -717,7 +708,7 @@ def generate_gitlab_ci_yaml(env, print_summary, output_file,
job_object = {
'stage': stage_name,
'variables': variables,
'script': job_scripts,
'script': job_script,
'tags': tags,
'artifacts': {
'paths': artifact_paths,

View File

@ -45,15 +45,6 @@ def setup_parser(subparser):
'--copy-to', default=None,
help="Absolute path of additional location where generated jobs " +
"yaml file should be copied. Default is not to copy.")
generate.add_argument(
'--spack-repo', default=None,
help="Provide a url for this argument if a custom spack repo " +
"should be cloned as a step in each generated job.")
generate.add_argument(
'--spack-ref', default=None,
help="Provide a git branch or tag if a custom spack branch " +
"should be checked out as a step in each generated job. " +
"This argument is ignored if no --spack-repo is provided.")
generate.add_argument(
'--optimize', action='store_true', default=False,
help="(Experimental) run the generated document through a series of "
@ -82,8 +73,6 @@ def ci_generate(args):
output_file = args.output_file
copy_yaml_to = args.copy_to
spack_repo = args.spack_repo
spack_ref = args.spack_ref
run_optimizer = args.optimize
use_dependencies = args.dependencies
@ -97,8 +86,7 @@ def ci_generate(args):
# Generate the jobs
spack_ci.generate_gitlab_ci_yaml(
env, True, output_file, spack_repo, spack_ref,
run_optimizer=run_optimizer,
env, True, output_file, run_optimizer=run_optimizer,
use_dependencies=use_dependencies)
if copy_yaml_to:

View File

@ -91,6 +91,21 @@
},
},
},
'before_script': {
'type': 'array',
'default': [],
'items': {'type': 'string'}
},
'script': {
'type': 'array',
'default': [],
'items': {'type': 'string'}
},
'after_script': {
'type': 'array',
'default': [],
'items': {'type': 'string'}
},
},
},
},
@ -100,10 +115,6 @@
'type': 'boolean',
'default': False,
},
'enable-debug-messages': {
'type': 'boolean',
'default': False,
},
'final-stage-rebuild-index': {
'type': 'object',
'additionalProperties': False,

View File

@ -351,7 +351,6 @@ def test_ci_generate_with_cdash_token(tmpdir, mutable_mock_env_path,
some-mirror: https://my.fake.mirror
gitlab-ci:
enable-artifacts-buildcache: True
enable-debug-messages: True
mappings:
- match:
- archive-files
@ -533,72 +532,6 @@ def test_ci_generate_with_external_pkg(tmpdir, mutable_mock_env_path,
assert not any('externaltool' in key for key in yaml_contents)
def test_ci_generate_debug_with_custom_spack(tmpdir, mutable_mock_env_path,
env_deactivate, install_mockery,
mock_packages):
"""Make sure we generate cloning of spack in job script if needed"""
filename = str(tmpdir.join('spack.yaml'))
with open(filename, 'w') as f:
f.write("""\
spack:
specs:
- archive-files
mirrors:
some-mirror: https://my.fake.mirror
gitlab-ci:
enable-artifacts-buildcache: True
enable-debug-messages: True
mappings:
- match:
- archive-files
runner-attributes:
tags:
- donotcare
image: donotcare
""")
with tmpdir.as_cwd():
env_cmd('create', 'test', './spack.yaml')
outfile = str(tmpdir.join('.gitlab-ci.yml'))
with ev.read('test'):
spack_repo = 'https://github.com/usera/spack.git'
spack_ref = 'custom-branch'
expected_clone_str = 'git clone "{0}"'.format(spack_repo)
ci_cmd('generate', '--output-file', outfile, '--spack-repo',
spack_repo, '--spack-ref', spack_ref)
with open(outfile) as f:
contents = f.read()
yaml_contents = syaml.load(contents)
for ci_key in yaml_contents.keys():
if '(specs)' in ci_key:
next_job = yaml_contents[ci_key]
print(next_job)
assert('before_script' in next_job)
before_script = next_job['before_script']
for step in before_script:
if expected_clone_str in step:
break
else:
msg = 'job "{0}" did not clone spack repo'.format(
ci_key)
print(msg)
assert(False)
assert('script' in next_job)
script = next_job['script']
for step in script:
if 'spack -d ci rebuild' in step:
break
else:
msg = 'job {0} missing rebuild command'.format(
ci_key)
print(msg)
assert(False)
def test_ci_rebuild_basic(tmpdir, mutable_mock_env_path, env_deactivate,
install_mockery, mock_packages,
mock_gnupghome):

View File

@ -465,7 +465,7 @@ _spack_ci() {
}
_spack_ci_generate() {
SPACK_COMPREPLY="-h --help --output-file --copy-to --spack-repo --spack-ref --optimize --dependencies"
SPACK_COMPREPLY="-h --help --output-file --copy-to --optimize --dependencies"
}
_spack_ci_rebuild() {