From 4d72b3f149a2bb80b5d371e661eb80324e2442bc Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 18 Aug 2023 13:00:31 -0400 Subject: acid: Improve git error handling Exit early from the cyche-source script on key git errors, where previously we would mindlessly continue on to execute a bunch of broken commands. Errors at this stage should be caught to prevent an attempt to build and deploy the code (even --force 'd builds). Signed-off-by: Malfurious --- acid/cyche-source | 20 +++++++++++--------- acid/cychedelic | 7 +++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/acid/cyche-source b/acid/cyche-source index dd290ac..e53ef6f 100755 --- a/acid/cyche-source +++ b/acid/cyche-source @@ -6,12 +6,14 @@ # doesn't exist. If updates are found, we attempt to checkout the newest # version according to (see from git-for-each-ref(1)). # -# The new (or current, if no update occurred) object hash is printed to stdout. -# This may be a commit hash. However, if matches an annotated tag, -# then the hash names the tag object. The caller should cache this hash value -# upon successful deployment. +# On a successful run, the new object hash is printed to stdout (or the previous +# hash, if no update occurred). This may be a commit hash. However, if +# matches an annotated tag, then the hash refers to the tag object. +# The caller should cache this hash value upon successful deployment. # -# If the file tree is updated, this file exits non-zero. +# If a new version of the file tree is checked out, this file exits with code 1, +# otherwise a stale success exits with 0. On any error, no hash is printed, and +# we exit with 2. gethash() { git for-each-ref \ @@ -24,7 +26,7 @@ gethash() { cd '/services' if ! [ -d "$1" ]; then - git clone "$2" "$1" >&2 + git clone "$2" "$1" >&2 || exit 2 touch "$1/.git/previous_hash" touch "$1/.git/previous_slug" fi @@ -32,14 +34,14 @@ fi cd "$1" git remote set-url origin "$2" >&2 # pick up url changes -git fetch --all --prune >&2 +git fetch --all --prune >&2 || exit 2 prev=$(cat '.git/previous_hash') next=$(gethash "$3") if [ -z "$next" ]; then - # no matching refs - next="$prev" + echo "No refs match $3" >&2 + exit 2 fi echo "$next" diff --git a/acid/cychedelic b/acid/cychedelic index 4e26b99..273a041 100755 --- a/acid/cychedelic +++ b/acid/cychedelic @@ -23,9 +23,12 @@ update() { for line in "${CYCHE_SERVICES[@]}"; do read -r -a arr <<< "$line" hash=$(cyche-source ${arr[@]:0:3}) + res=$? - if [ $? -ne 0 ] || [ "$1" == "$forceopt" ]; then - cyche-build "${arr[0]}" "${arr[3]}" "$hash" $selfopt + if [ $res -ne 2 ]; then + if [ $res -eq 1 ] || [ "$1" == "$forceopt" ]; then + cyche-build "${arr[0]}" "${arr[3]}" "$hash" $selfopt + fi fi forceopt="--force" -- cgit v1.2.3