summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Anderson <17242663+blue42u@users.noreply.github.com>2023-07-09 14:37:36 -0500
committerGitHub <noreply@github.com>2023-07-09 12:37:36 -0700
commitdb879a567928d3166365861d85dd1f3be4f0b36e (patch)
tree4bad82d72f18c921014891f34edde5455c5b8b92
parentd0804c44f1fbee4b3ae2d65e4c89895082292722 (diff)
downloadspack-db879a567928d3166365861d85dd1f3be4f0b36e.tar.gz
spack-db879a567928d3166365861d85dd1f3be4f0b36e.tar.bz2
spack-db879a567928d3166365861d85dd1f3be4f0b36e.tar.xz
spack-db879a567928d3166365861d85dd1f3be4f0b36e.zip
ci: Fix broken SPACK_CHECKOUT_VERSION (#38778)
-rw-r--r--lib/spack/spack/ci.py17
-rw-r--r--lib/spack/spack/test/cmd/ci.py13
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 generate_gitlab_ci_yaml(
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 @@ spack:
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 @@ spack:
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 test_push_mirror_contents_exceptions(monkeypatch, capsys):
@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 @@ spack:
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 @@ spack:
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"):