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