From db879a567928d3166365861d85dd1f3be4f0b36e Mon Sep 17 00:00:00 2001 From: Jonathon Anderson <17242663+blue42u@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:37:36 -0500 Subject: [PATCH] ci: Fix broken SPACK_CHECKOUT_VERSION (#38778) --- lib/spack/spack/ci.py | 17 ++++------------- lib/spack/spack/test/cmd/ci.py | 13 +++++++++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/spack/spack/ci.py b/lib/spack/spack/ci.py index 926c042cec..cfe87e5214 100644 --- a/lib/spack/spack/ci.py +++ b/lib/spack/spack/ci.py @@ -1257,20 +1257,11 @@ def main_script_replacements(cmd): output_object["stages"] = stage_names - # Capture the version of spack used to generate the pipeline, transform it - # into a value that can be passed to "git checkout", and save it in a - # global yaml variable + # Capture the version of Spack used to generate the pipeline, that can be + # passed to `git checkout` for version consistency. If we aren't in a Git + # repository, presume we are a Spack release and use the Git tag instead. spack_version = spack.main.get_version() - version_to_clone = None - v_match = re.match(r"^\d+\.\d+\.\d+$", spack_version) - if v_match: - version_to_clone = "v{0}".format(v_match.group(0)) - else: - v_match = re.match(r"^[^-]+-[^-]+-([a-f\d]+)$", spack_version) - if v_match: - version_to_clone = v_match.group(1) - else: - version_to_clone = spack_version + version_to_clone = spack.main.get_spack_commit() or f"v{spack.spack_version}" output_object["variables"] = { "SPACK_ARTIFACTS_ROOT": rel_artifacts_root, diff --git a/lib/spack/spack/test/cmd/ci.py b/lib/spack/spack/test/cmd/ci.py index 6a82c29e32..818bf1850e 100644 --- a/lib/spack/spack/test/cmd/ci.py +++ b/lib/spack/spack/test/cmd/ci.py @@ -377,6 +377,7 @@ def test_ci_generate_with_custom_settings( with ev.read("test"): monkeypatch.setattr(spack.main, "get_version", lambda: "0.15.3") + monkeypatch.setattr(spack.main, "get_spack_commit", lambda: "big ol commit sha") ci_cmd("generate", "--output-file", outputfile) with open(outputfile) as f: @@ -387,7 +388,7 @@ def test_ci_generate_with_custom_settings( global_vars = yaml_contents["variables"] assert global_vars["SPACK_VERSION"] == "0.15.3" - assert global_vars["SPACK_CHECKOUT_VERSION"] == "v0.15.3" + assert global_vars["SPACK_CHECKOUT_VERSION"] == "big ol commit sha" for ci_key in yaml_contents.keys(): ci_obj = yaml_contents[ci_key] @@ -1196,6 +1197,7 @@ def failing_access(*args, **kwargs): @pytest.mark.parametrize("match_behavior", ["first", "merge"]) +@pytest.mark.parametrize("git_version", ["big ol commit sha", None]) def test_ci_generate_override_runner_attrs( tmpdir, mutable_mock_env_path, @@ -1204,6 +1206,7 @@ def test_ci_generate_override_runner_attrs( monkeypatch, ci_base_environment, match_behavior, + git_version, ): """Test that we get the behavior we want with respect to the provision of runner attributes like tags, variables, and scripts, both when we @@ -1281,7 +1284,9 @@ def test_ci_generate_override_runner_attrs( outputfile = str(tmpdir.join(".gitlab-ci.yml")) with ev.read("test"): - monkeypatch.setattr(spack.main, "get_version", lambda: "0.15.3-416-12ad69eb1") + monkeypatch.setattr(spack, "spack_version", "0.20.0.test0") + monkeypatch.setattr(spack.main, "get_version", lambda: "0.20.0.test0 (blah)") + monkeypatch.setattr(spack.main, "get_spack_commit", lambda: git_version) ci_cmd("generate", "--output-file", outputfile) with open(outputfile) as f: @@ -1291,9 +1296,9 @@ def test_ci_generate_override_runner_attrs( assert "variables" in yaml_contents global_vars = yaml_contents["variables"] assert "SPACK_VERSION" in global_vars - assert global_vars["SPACK_VERSION"] == "0.15.3-416-12ad69eb1" + assert global_vars["SPACK_VERSION"] == "0.20.0.test0 (blah)" assert "SPACK_CHECKOUT_VERSION" in global_vars - assert global_vars["SPACK_CHECKOUT_VERSION"] == "12ad69eb1" + assert global_vars["SPACK_CHECKOUT_VERSION"] == git_version or "v0.20.0.test0" for ci_key in yaml_contents.keys(): if ci_key.startswith("a"):