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 ...@@ -21,7 +21,7 @@ import shutil
import json import json
BRANCH_DIR_VERSION = "3" BRANCH_DIR_VERSION = "4"
class Branch: class Branch:
...@@ -82,7 +82,7 @@ class Branch: ...@@ -82,7 +82,7 @@ class Branch:
return False return False
# All the files must be be present # All the files must be be present
files = ["version", "commit", "config.json"] files = ["version", "commit", "built", "config.json"]
for file in files: for file in files:
file = root / file file = root / file
if not (file.exists() and file.is_file()): if not (file.exists() and file.is_file()):
...@@ -162,7 +162,7 @@ class Branch: ...@@ -162,7 +162,7 @@ class Branch:
def exec_command(self, raw_command, replaces=None, build=False): def exec_command(self, raw_command, replaces=None, build=False):
"""Exec a command in the context of the branch""" """Exec a command in the context of the branch"""
args, kwargs = self.command_popen_args(raw_command, replaces, build) 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): def command_popen_args(self, raw_command, replaces=None, build=False):
"""Get the Popen arguments for exec_command""" """Get the Popen arguments for exec_command"""
...@@ -261,11 +261,17 @@ class Branch: ...@@ -261,11 +261,17 @@ class Branch:
# Build the website # Build the website
for cmd in self.config["build"]: 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 # Execute the pre-install commands
for cmd in self.config["before_install"]: 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 # Install the builded artifacts
total = 0 total = 0
...@@ -284,7 +290,10 @@ class Branch: ...@@ -284,7 +290,10 @@ class Branch:
# Execute the post-install commands # Execute the post-install commands
if "after_install" in self.config: if "after_install" in self.config:
for cmd in self.config["after_install"]: 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 # Check if the branch was successifully built
popen_args = self.command_popen_args(self.config["run"]) popen_args = self.command_popen_args(self.config["run"])
...@@ -301,6 +310,9 @@ class Branch: ...@@ -301,6 +310,9 @@ class Branch:
self.manager.details["branches"][self.name] = self.mr self.manager.details["branches"][self.name] = self.mr
self.manager.save_details() self.manager.save_details()
# Create the built file
(branch / "built").touch()
self._deploying = False self._deploying = False
def destroy(self): 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