ci: Fix broken SPACK_CHECKOUT_VERSION (#38778)

This commit is contained in:
Jonathon Anderson 2023-07-09 14:37:36 -05:00 committed by GitHub
parent d0804c44f1
commit db879a5679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 17 deletions

View file

@ -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,

View file

@ -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"):