Enforce certain Git commands to succeed

This enforces all Git commands that are absolutely relevant for keeping
the benchmark running to succeed. If they don’t, an error is immediately
thrown. This doesn’t include fetching and pushing, because syncing the
data is still possible after downtimes, for example.
This commit is contained in:
Patrick Lühne 2017-11-20 23:31:34 +01:00
parent b98f6f44b4
commit 837422e4b0
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF

View File

@ -44,11 +44,13 @@ def fastDownwardVersion(config):
return version.strip() return version.strip()
def git(command, cwd): def git(command, cwd, enforce = False):
stdout, stderr, exitCode = executeCommand(["git"] + command, cwd = cwd) stdout, stderr, exitCode = executeCommand(["git"] + command, cwd = cwd)
if exitCode != 0: if exitCode != 0:
print(stderr, file = sys.stderr) print(stderr, file = sys.stderr)
if enforce:
raise RuntimeError("git error") raise RuntimeError("git error")
def initRepo(config): def initRepo(config):
@ -56,24 +58,24 @@ def initRepo(config):
# clone repo if not existing # clone repo if not existing
if not os.path.isdir(config["storage"]["local"]): if not os.path.isdir(config["storage"]["local"]):
git(["clone", config["storage"]["remote"], dataDir], None) git(["clone", config["storage"]["remote"], dataDir], None, enforce = True)
# default settings # default settings
git(["config", "--local", "user.name", config["storage"]["userName"]], dataDir) git(["config", "--local", "user.name", config["storage"]["userName"]], dataDir, enforce = True)
git(["config", "--local", "user.email", config["storage"]["userEMail"]], dataDir) git(["config", "--local", "user.email", config["storage"]["userEMail"]], dataDir, enforce = True)
if "userSigningKey" in config["storage"]: if "userSigningKey" in config["storage"]:
git(["config", "--local", "user.signingkey", config["storage"]["userSigningKey"]], dataDir) git(["config", "--local", "user.signingkey", config["storage"]["userSigningKey"]], dataDir, enforce = True)
git(["config", "--local", "commit.gpgsign", "true"], dataDir) git(["config", "--local", "commit.gpgsign", "true"], dataDir, enforce = True)
else: else:
git(["config", "--local", "commit.gpgsign", "false"], dataDir) git(["config", "--local", "commit.gpgsign", "false"], dataDir, enforce = True)
# fetch origin # fetch origin
git(["fetch"], cwd = dataDir) git(["fetch"], cwd = dataDir)
# pull all branches # pull all branches
for key, branch in config["storage"]["branches"].items(): for key, branch in config["storage"]["branches"].items():
git(["checkout", branch], cwd = dataDir) git(["checkout", branch], cwd = dataDir, enforce = True)
git(["pull"], cwd = dataDir) git(["pull"], cwd = dataDir)
def readBenchmarkConfig(config): def readBenchmarkConfig(config):
@ -82,7 +84,7 @@ def readBenchmarkConfig(config):
dataDir = config["storage"]["local"] dataDir = config["storage"]["local"]
# checkout config branch # checkout config branch
git(["checkout", config["storage"]["branches"]["config"]], cwd = dataDir) git(["checkout", config["storage"]["branches"]["config"]], cwd = dataDir, enforce = True)
# read instance list # read instance list
instancesFile = os.path.join(config["storage"]["local"], "instances.yml") instancesFile = os.path.join(config["storage"]["local"], "instances.yml")
@ -124,7 +126,7 @@ def nextJob(config):
dataDir = config["storage"]["local"] dataDir = config["storage"]["local"]
# checkout results branch # checkout results branch
git(["checkout", config["storage"]["branches"]["results"]], cwd = dataDir) git(["checkout", config["storage"]["branches"]["results"]], cwd = dataDir, enforce = True)
configurations = benchmarkConfig["configurations"]["configurations"] configurations = benchmarkConfig["configurations"]["configurations"]
instances = benchmarkConfig["instances"] instances = benchmarkConfig["instances"]
@ -145,7 +147,7 @@ def writeStatus(message, config):
dataDir = config["storage"]["local"] dataDir = config["storage"]["local"]
# checkout status branch # checkout status branch
git(["checkout", config["storage"]["branches"]["status"]], cwd = dataDir) git(["checkout", config["storage"]["branches"]["status"]], cwd = dataDir, enforce = True)
statusFilename = os.path.join(dataDir, "status.log") statusFilename = os.path.join(dataDir, "status.log")
@ -159,8 +161,8 @@ def writeStatus(message, config):
with open(statusFilename, "w") as statusFile: with open(statusFilename, "w") as statusFile:
print(time.strftime("%Y-%m-%d %H:%M:%S %z") + "\t" + message + "\n" + "".join(content), file = statusFile, end = "") print(time.strftime("%Y-%m-%d %H:%M:%S %z") + "\t" + message + "\n" + "".join(content), file = statusFile, end = "")
git(["add", "status.log"], dataDir) git(["add", "status.log"], dataDir, enforce = True)
git(["commit", "-m Update status: " + message], dataDir) git(["commit", "-m Update status: " + message], dataDir, enforce = True)
git(["push"], dataDir) git(["push"], dataDir)
def runJob(configuration, instance, config): def runJob(configuration, instance, config):
@ -173,7 +175,7 @@ def runJob(configuration, instance, config):
inputFiles = inputFilenames(instance, config) inputFiles = inputFilenames(instance, config)
# checkout results branch # checkout results branch
git(["checkout", config["storage"]["branches"]["results"]], cwd = dataDir) git(["checkout", config["storage"]["branches"]["results"]], cwd = dataDir, enforce = True)
command = \ command = \
[ [
@ -227,8 +229,8 @@ def runJob(configuration, instance, config):
print(yaml.dump(environment, default_flow_style = False), file = environmentFile) print(yaml.dump(environment, default_flow_style = False), file = environmentFile)
git(["add", outputFiles["outputFile"], outputFiles["errorFile"], outputFiles["environmentFile"]], dataDir) git(["add", outputFiles["outputFile"], outputFiles["errorFile"], outputFiles["environmentFile"]], dataDir, enforce = True)
git(["commit", "-m Add benchmark result " + jobName], dataDir) git(["commit", "-m Add benchmark result " + jobName], dataDir, enforce = True)
git(["push"], dataDir) git(["push"], dataDir)
if exitCode != 0: if exitCode != 0: