From d7405ddd3908f328d052d1de7520620924825b7b Mon Sep 17 00:00:00 2001 From: Scott Wittenburg Date: Thu, 24 Jun 2021 16:15:19 -0600 Subject: [PATCH] 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". --- lib/spack/spack/ci.py | 7 +++---- lib/spack/spack/cmd/ci.py | 13 +++++++++---- lib/spack/spack/test/cmd/ci.py | 10 +++++----- share/spack/gitlab/cloud_pipelines/.gitlab-ci.yml | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/spack/spack/ci.py b/lib/spack/spack/ci.py index e966a5a970c..3e5e134e05e 100644 --- a/lib/spack/spack/ci.py +++ b/lib/spack/spack/ci.py @@ -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: diff --git a/lib/spack/spack/cmd/ci.py b/lib/spack/spack/cmd/ci.py index 1bc73ec4528..1f879245387 100644 --- a/lib/spack/spack/cmd/ci.py +++ b/lib/spack/spack/cmd/ci.py @@ -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') diff --git a/lib/spack/spack/test/cmd/ci.py b/lib/spack/spack/test/cmd/ci.py index cdc52477991..b267596a722 100644 --- a/lib/spack/spack/test/cmd/ci.py +++ b/lib/spack/spack/test/cmd/ci.py @@ -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) diff --git a/share/spack/gitlab/cloud_pipelines/.gitlab-ci.yml b/share/spack/gitlab/cloud_pipelines/.gitlab-ci.yml index 0247803a303..73d33c4b6da 100644 --- a/share/spack/gitlab/cloud_pipelines/.gitlab-ci.yml +++ b/share/spack/gitlab/cloud_pipelines/.gitlab-ci.yml @@ -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