Pipelines: Set a pipeline type variable (#24505)

Spack pipelines need to take specific actions internally that depend
on whether the pipeline is being run on a PR to spack or a merge to
the develop branch.  Pipelines can also run in other repositories,
which represents other possible use cases than just the two mentioned
above.  This PR creates a "SPACK_PIPELINE_TYPE" gitlab variable which
is propagated to rebuild jobs, and is also used internally to determine
which pipeline-specific tasks to run.

One goal of the PR is fix an issue where rebuild jobs which failed on
develop pipelines did not properly report the broken full hash to the
"broken-specs-url".
This commit is contained in:
Scott Wittenburg 2021-06-24 16:15:19 -06:00 committed by GitHub
parent 010b431692
commit d7405ddd39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 15 deletions

View File

@ -549,9 +549,8 @@ def generate_gitlab_ci_yaml(env, print_summary, output_file,
generate_job_name = os.environ.get('CI_JOB_NAME', None)
parent_pipeline_id = os.environ.get('CI_PIPELINE_ID', None)
is_pr_pipeline = (
os.environ.get('SPACK_IS_PR_PIPELINE', '').lower() == 'true'
)
spack_pipeline_type = os.environ.get('SPACK_PIPELINE_TYPE', None)
is_pr_pipeline = spack_pipeline_type == 'spack_pull_request'
spack_pr_branch = os.environ.get('SPACK_PR_BRANCH', None)
pr_mirror_url = None
@ -1073,7 +1072,7 @@ def generate_gitlab_ci_yaml(env, print_summary, output_file,
'SPACK_JOB_LOG_DIR': rel_job_log_dir,
'SPACK_JOB_REPRO_DIR': rel_job_repro_dir,
'SPACK_LOCAL_MIRROR_DIR': rel_local_mirror_dir,
'SPACK_IS_PR_PIPELINE': str(is_pr_pipeline)
'SPACK_PIPELINE_TYPE': str(spack_pipeline_type)
}
if pr_mirror_url:

View File

@ -196,8 +196,7 @@ def ci_rebuild(args):
compiler_action = get_env_var('SPACK_COMPILER_ACTION')
cdash_build_name = get_env_var('SPACK_CDASH_BUILD_NAME')
related_builds = get_env_var('SPACK_RELATED_BUILDS_CDASH')
pr_env_var = get_env_var('SPACK_IS_PR_PIPELINE')
dev_env_var = get_env_var('SPACK_IS_DEVELOP_PIPELINE')
spack_pipeline_type = get_env_var('SPACK_PIPELINE_TYPE')
pr_mirror_url = get_env_var('SPACK_PR_MIRROR_URL')
remote_mirror_url = get_env_var('SPACK_REMOTE_MIRROR_URL')
@ -242,8 +241,11 @@ def ci_rebuild(args):
# Is this a pipeline run on a spack PR or a merge to develop? It might
# be neither, e.g. a pipeline run on some environment repository.
spack_is_pr_pipeline = True if pr_env_var == 'True' else False
spack_is_develop_pipeline = True if dev_env_var == 'True' else False
spack_is_pr_pipeline = spack_pipeline_type == 'spack_pull_request'
spack_is_develop_pipeline = spack_pipeline_type == 'spack_protected_branch'
tty.debug('Pipeline type - PR: {0}, develop: {1}'.format(
spack_is_pr_pipeline, spack_is_develop_pipeline))
# Figure out what is our temporary storage mirror: Is it artifacts
# buildcache? Or temporary-storage-url-prefix? In some cases we need to
@ -495,10 +497,13 @@ def ci_rebuild(args):
# list of known broken full hashes. This allows spack PR pipelines to
# avoid wasting compute cycles attempting to build those hashes.
if install_exit_code != 0 and spack_is_develop_pipeline:
tty.debug('Install failed on develop')
if 'broken-specs-url' in gitlab_ci:
broken_specs_url = gitlab_ci['broken-specs-url']
dev_fail_hash = job_spec.full_hash()
broken_spec_path = url_util.join(broken_specs_url, dev_fail_hash)
tty.msg('Reporting broken develop build as: {0}'.format(
broken_spec_path))
tmpdir = tempfile.mkdtemp()
empty_file_path = os.path.join(tmpdir, 'empty.txt')

View File

@ -612,14 +612,14 @@ def test_ci_generate_for_pr_pipeline(tmpdir, mutable_mock_env_path,
outputfile = str(tmpdir.join('.gitlab-ci.yml'))
with ev.read('test'):
os.environ['SPACK_IS_PR_PIPELINE'] = 'True'
os.environ['SPACK_PIPELINE_TYPE'] = 'spack_pull_request'
os.environ['SPACK_PR_BRANCH'] = 'fake-test-branch'
monkeypatch.setattr(
ci, 'SPACK_PR_MIRRORS_ROOT_URL', r"file:///fake/mirror")
try:
ci_cmd('generate', '--output-file', outputfile)
finally:
del os.environ['SPACK_IS_PR_PIPELINE']
del os.environ['SPACK_PIPELINE_TYPE']
del os.environ['SPACK_PR_BRANCH']
with open(outputfile) as f:
@ -630,8 +630,8 @@ def test_ci_generate_for_pr_pipeline(tmpdir, mutable_mock_env_path,
assert('variables' in yaml_contents)
pipeline_vars = yaml_contents['variables']
assert('SPACK_IS_PR_PIPELINE' in pipeline_vars)
assert(pipeline_vars['SPACK_IS_PR_PIPELINE'] == 'True')
assert('SPACK_PIPELINE_TYPE' in pipeline_vars)
assert(pipeline_vars['SPACK_PIPELINE_TYPE'] == 'spack_pull_request')
def test_ci_generate_with_external_pkg(tmpdir, mutable_mock_env_path,
@ -779,7 +779,7 @@ def fake_cdash_register(build_name, base_url, project, site, track):
set_env_var('SPACK_CDASH_BUILD_NAME', '(specs) archive-files')
set_env_var('SPACK_RELATED_BUILDS_CDASH', '')
set_env_var('SPACK_REMOTE_MIRROR_URL', mirror_url)
set_env_var('SPACK_IS_DEVELOP_PIPELINE', 'True')
set_env_var('SPACK_PIPELINE_TYPE', 'spack_protected_branch')
ci_cmd('rebuild', fail_on_error=False)

View File

@ -12,13 +12,13 @@ default:
- /^github\/pr[\d]+_.*$/
variables:
SPACK_PR_BRANCH: ${CI_COMMIT_REF_NAME}
SPACK_IS_PR_PIPELINE: "True"
SPACK_PIPELINE_TYPE: "spack_pull_request"
.develop:
only:
- /^github\/develop$/
variables:
SPACK_IS_PR_PIPELINE: "False"
SPACK_PIPELINE_TYPE: "spack_protected_branch"
.generate:
stage: generate