Commit b7467053 authored by Pietro Albini's avatar Pietro Albini

Fail the build if a command fails

parent 210ebf52
......@@ -21,7 +21,7 @@ import shutil
import json
BRANCH_DIR_VERSION = "3"
BRANCH_DIR_VERSION = "4"
class Branch:
......@@ -82,7 +82,7 @@ class Branch:
return False
# All the files must be be present
files = ["version", "commit", "config.json"]
files = ["version", "commit", "built", "config.json"]
for file in files:
file = root / file
if not (file.exists() and file.is_file()):
......@@ -162,7 +162,7 @@ class Branch:
def exec_command(self, raw_command, replaces=None, build=False):
"""Exec a command in the context of the branch"""
args, kwargs = self.command_popen_args(raw_command, replaces, build)
return subprocess.call(*args, **kwargs)
return subprocess.call(*args, **kwargs) == 0
def command_popen_args(self, raw_command, replaces=None, build=False):
"""Get the Popen arguments for exec_command"""
......@@ -261,11 +261,17 @@ class Branch:
# Build the website
for cmd in self.config["build"]:
self.exec_command(cmd, build=True)
if not self.exec_command(cmd, build=True):
log("[!] Failed to execute build command: %s" % " ".join(cmd))
log("[!] Aborting!")
return False
# Execute the pre-install commands
for cmd in self.config["before_install"]:
self.exec_command(cmd, build=True)
if not self.exec_command(cmd, build=True):
log("[!] Failed to execute before_install command: %s" % " ".join(cmd))
log("[!] Aborting!")
return False
# Install the builded artifacts
total = 0
......@@ -284,7 +290,10 @@ class Branch:
# Execute the post-install commands
if "after_install" in self.config:
for cmd in self.config["after_install"]:
self.exec_command(cmd, build=True)
if not self.exec_command(cmd, build=True):
log("[!] Failed to execute after_install command: %s" % " ".join(cmd))
log("[!] Aborting!")
return False
# Check if the branch was successifully built
popen_args = self.command_popen_args(self.config["run"])
......@@ -301,6 +310,9 @@ class Branch:
self.manager.details["branches"][self.name] = self.mr
self.manager.save_details()
# Create the built file
(branch / "built").touch()
self._deploying = False
def destroy(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment