From 3ad65bbfc12fa83c0ae376da35eca2b97128a0af Mon Sep 17 00:00:00 2001 From: Jonathon Anderson <17242663+blue42u@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:31:39 -0500 Subject: Always set workflow:rules in spack ci pipelines (#38921) --- lib/spack/spack/ci.py | 22 +++++++++++----------- lib/spack/spack/test/cmd/ci.py | 11 +++++++++-- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/ci.py b/lib/spack/spack/ci.py index 3498e8d805..a530c645c4 100644 --- a/lib/spack/spack/ci.py +++ b/lib/spack/spack/ci.py @@ -1287,9 +1287,6 @@ def generate_gitlab_ci_yaml( if spack_stack_name: output_object["variables"]["SPACK_CI_STACK_NAME"] = spack_stack_name - # Ensure the child pipeline always runs - output_object["workflow"] = {"rules": [{"when": "always"}]} - if spack_buildcache_copy: # Write out the file describing specs that should be copied copy_specs_dir = os.path.join(pipeline_artifacts_dir, "specs_to_copy") @@ -1305,21 +1302,17 @@ def generate_gitlab_ci_yaml( with open(copy_specs_file, "w") as fd: fd.write(json.dumps(buildcache_copies)) - sorted_output = {} - for output_key, output_value in sorted(output_object.items()): - sorted_output[output_key] = output_value - # TODO(opadron): remove this or refactor if run_optimizer: import spack.ci_optimization as ci_opt - sorted_output = ci_opt.optimizer(sorted_output) + output_object = ci_opt.optimizer(output_object) # TODO(opadron): remove this or refactor if use_dependencies: import spack.ci_needs_workaround as cinw - sorted_output = cinw.needs_to_dependencies(sorted_output) + output_object = cinw.needs_to_dependencies(output_object) else: # No jobs were generated noop_job = spack_ci_ir["jobs"]["noop"]["attributes"] @@ -1330,10 +1323,17 @@ def generate_gitlab_ci_yaml( noop_job["script"] = [ 'echo "copy-only pipelines are not supported with deprecated ci configs"' ] - sorted_output = {"unsupported-copy": noop_job} + output_object = {"unsupported-copy": noop_job} else: tty.debug("No specs to rebuild, generating no-op job") - sorted_output = {"no-specs-to-rebuild": noop_job} + output_object = {"no-specs-to-rebuild": noop_job} + + # Ensure the child pipeline always runs + output_object["workflow"] = {"rules": [{"when": "always"}]} + + sorted_output = {} + for output_key, output_value in sorted(output_object.items()): + sorted_output[output_key] = output_value if known_broken_specs_encountered: tty.error("This pipeline generated hashes known to be broken on develop:") diff --git a/lib/spack/spack/test/cmd/ci.py b/lib/spack/spack/test/cmd/ci.py index 1ef493e422..09d942cf51 100644 --- a/lib/spack/spack/test/cmd/ci.py +++ b/lib/spack/spack/test/cmd/ci.py @@ -215,6 +215,10 @@ spack: with open(outputfile) as f: contents = f.read() yaml_contents = syaml.load(contents) + assert "workflow" in yaml_contents + assert "rules" in yaml_contents["workflow"] + assert yaml_contents["workflow"]["rules"] == [{"when": "always"}] + assert "stages" in yaml_contents assert len(yaml_contents["stages"]) == 5 assert yaml_contents["stages"][0] == "stage-0" @@ -1102,9 +1106,9 @@ spack: with open(outputfile_pruned) as f: contents = f.read() yaml_contents = syaml.load(contents) - assert "no-specs-to-rebuild" in yaml_contents # Make sure there are no other spec jobs or rebuild-index - assert len(yaml_contents.keys()) == 1 + assert set(yaml_contents.keys()) == {"no-specs-to-rebuild", "workflow"} + the_elt = yaml_contents["no-specs-to-rebuild"] assert "tags" in the_elt assert "nonbuildtag" in the_elt["tags"] @@ -1112,6 +1116,9 @@ spack: assert the_elt["image"] == "basicimage" assert the_elt["custom_attribute"] == "custom!" + assert "rules" in yaml_contents["workflow"] + assert yaml_contents["workflow"]["rules"] == [{"when": "always"}] + outputfile_not_pruned = str(tmpdir.join("unpruned_pipeline.yml")) ci_cmd("generate", "--no-prune-dag", "--output-file", outputfile_not_pruned) -- cgit v1.2.3-60-g2f50