From 11047d572d472eca27e13831ea7f27e9320af76f Mon Sep 17 00:00:00 2001
From: Hans Fangohr <hans.fangohr@mpsd.mpg.de>
Date: Fri, 26 May 2023 15:36:37 +0200
Subject: [PATCH] force `subprocess.run` to check return code is 0

In general, this should help to capture unintentional errors

Tests fail now, not clear why yet.
---
 mpsd-software-environment.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/mpsd-software-environment.py b/mpsd-software-environment.py
index ba01d62..08eea14 100755
--- a/mpsd-software-environment.py
+++ b/mpsd-software-environment.py
@@ -89,6 +89,7 @@ def setup_log_cmd(
                         subprocess.run(
                             ["git", "rev-parse", "--abbrev-ref", "HEAD"],
                             stdout=subprocess.PIPE,
+                            check=True,
                         )
                         .stdout.decode()
                         .strip()
@@ -97,6 +98,7 @@ def setup_log_cmd(
                         subprocess.run(
                             ["git", "rev-parse", "--short", "HEAD"],
                             stdout=subprocess.PIPE,
+                            check=True,
                         )
                         .stdout.decode()
                         .strip()
@@ -142,19 +144,20 @@ def create_dir_structure(mpsd_release: str, script_dir: Path) -> None:
                     "git",
                     "clone",
                     config_vars["spack_environments_repo"],
-                ]
+                ],
+                check=True,
             )
         with os_chdir("spack-environments"):
             # Git fetch and checkout the release branch and git pull
             # to be sure that the resulting repo is up to date
-            subprocess.run(["git", "fetch", "--all"])
+            subprocess.run(["git", "fetch", "--all"], check=True)
             checkout_result = subprocess.run(["git", "checkout", mpsd_release])
             if checkout_result.returncode != 0:
                 raise Exception(
                     "Release branch does not exist in spack-environment repo \n."
                     "Check for typos."
                 )
-            subprocess.run(["git", "pull"])
+            subprocess.run(["git", "pull"], check=True)
 
 
 def get_release_info(mpsd_release: str, script_dir: Path) -> Tuple[str, str, List[str]]:
@@ -186,13 +189,17 @@ def get_release_info(mpsd_release: str, script_dir: Path) -> Tuple[str, str, Lis
         with os_chdir("spack-environments"):
             # Get the branch and commit hash of the spack-environments repo
             spe_commit_hash = (
-                subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE)
+                subprocess.run(
+                    ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, check=True
+                )
                 .stdout.decode()
                 .strip()
             )
             spe_branch = (
                 subprocess.run(
-                    ["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE
+                    ["git", "rev-parse", "--abbrev-ref", "HEAD"],
+                    stdout=subprocess.PIPE,
+                    check=True,
                 )
                 .stdout.decode()
                 .strip()
@@ -331,6 +338,7 @@ def install_environment(
                 f"bash {spack_setup_script} {' '.join(install_flags)} {toolchain} 2>&1 "
                 f"| tee -a {install_log_file} ",
                 shell=True,
+                check=True,
             )
 
 
-- 
GitLab