From d54ce6c17fb7a35238d6b9f734d30a4289886773 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 30 Jul 2018 17:37:24 -0400
Subject: [PATCH] Properly forward exit 1 code from the paper root command

This is so the CI server can pick up when applying patches fails,
and mark the build as a failure.
---
 paper                     | 20 ++++++++++++++------
 scripts/applyPatches.sh   |  2 +-
 scripts/build.sh          |  2 +-
 scripts/paperclip.sh      |  2 +-
 scripts/rebuildPatches.sh |  2 +-
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/paper b/paper
index f80040c8f6..8c2f4ffdc5 100755
--- a/paper
+++ b/paper
@@ -27,27 +27,28 @@ gitcmd="git -c commit.gpgsign=false"
 
 source "$basedir/scripts/functions.sh"
 
+failed=0
 case "$1" in
     "rb" | "rbp" | "rebuild")
     (
         set -e
         cd "$basedir"
-        scripts/rebuildPatches.sh "$basedir"
-    )
+        scripts/rebuildPatches.sh "$basedir" || exit 1
+    ) || failed=1
     ;;
     "p" | "patch")
     (
         set -e
         cd "$basedir"
-        scripts/build.sh "$basedir"
-    )
+        scripts/build.sh "$basedir" || exit 1
+    ) || failed=1
     ;;
     "j" | "jar")
     (
         set -e
         cd "$basedir"
-        scripts/build.sh "$basedir" "--jar"
-    )
+        scripts/build.sh "$basedir" "--jar" || exit 1
+    ) || failed=1
     ;;
     "make")
     (
@@ -191,3 +192,10 @@ unset -f color
 unset -f colorend
 unset -f paperstash
 unset -f paperunstash
+if [ "$failed" == "1" ]; then
+	unset failed
+	false
+else
+	unset failed
+	true
+fi
\ No newline at end of file
diff --git a/scripts/applyPatches.sh b/scripts/applyPatches.sh
index 5e54339294..1422811260 100755
--- a/scripts/applyPatches.sh
+++ b/scripts/applyPatches.sh
@@ -95,4 +95,4 @@ cd "$basedir"
     echo "Failed to apply Paper Patches"
     exit 1
 ) || exit 1
-)
+) || exit 1
diff --git a/scripts/build.sh b/scripts/build.sh
index 62d4bca0e6..9b8fa286a7 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -12,4 +12,4 @@ gitcmd="git -c commit.gpgsign=false"
 if [ "$2" == "--jar" ]; then
     mvn clean install && ./scripts/paperclip.sh "$basedir"
 fi
-)
+) || exit 1
diff --git a/scripts/paperclip.sh b/scripts/paperclip.sh
index 693e6fc48d..2722ca3dda 100755
--- a/scripts/paperclip.sh
+++ b/scripts/paperclip.sh
@@ -19,4 +19,4 @@ echo ""
 echo ""
 echo "Build success!"
 echo "Copied final jar to $(cd "$basedir" && pwd -P)/paperclip.jar"
-)
+) || exit 1
diff --git a/scripts/rebuildPatches.sh b/scripts/rebuildPatches.sh
index e0f6af26f9..bd7dd20cd3 100755
--- a/scripts/rebuildPatches.sh
+++ b/scripts/rebuildPatches.sh
@@ -60,4 +60,4 @@ function savePatches {
 
 savePatches "$workdir/Spigot/Spigot-API" "Paper-API"
 savePatches "$workdir/Spigot/Spigot-Server" "Paper-Server"
-)
+) || exit 1