diff options
author | Malfurious <m@lfurio.us> | 2023-08-18 13:00:31 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-08-18 13:45:53 -0400 |
commit | 4d72b3f149a2bb80b5d371e661eb80324e2442bc (patch) | |
tree | 06db695d8282439625a30120ccf1bb6252c5d488 | |
parent | d5c380f477f2913effd632cf58aff287062bf593 (diff) | |
download | cychedelic-4d72b3f149a2bb80b5d371e661eb80324e2442bc.tar.gz cychedelic-4d72b3f149a2bb80b5d371e661eb80324e2442bc.zip |
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 <m@lfurio.us>
-rwxr-xr-x | acid/cyche-source | 20 | ||||
-rwxr-xr-x | 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 @@ # <name> doesn't exist. If updates are found, we attempt to checkout the newest # version according to <ref-pattern> (see <pattern> 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 <ref-pattern> 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 +# <ref-pattern> 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" |