summaryrefslogtreecommitdiffstats
path: root/acid
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-10-31 14:40:01 -0400
committerMalfurious <m@lfurio.us>2023-11-02 06:11:59 -0400
commita5bed544ab2d63492baa07af56176adb195565ab (patch)
treedecc081d6f337ffbbb533496d7a5ca48d83a7391 /acid
parent0da2ed7bd1cd7be76b6803a0c638036614a8f7b9 (diff)
downloadcychedelic-a5bed544ab2d63492baa07af56176adb195565ab.tar.gz
cychedelic-a5bed544ab2d63492baa07af56176adb195565ab.zip
acid: source: Return null hash on error
This seems like a more consistent behavior. Also, I would like to embed the git hash into the build log record somehow. Returning all zeroes in an error case allows the main script to simply pass along the result instead of worrying about an edge case. Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'acid')
-rwxr-xr-xacid/acid1
-rwxr-xr-xacid/acid-source17
2 files changed, 12 insertions, 6 deletions
diff --git a/acid/acid b/acid/acid
index 4f4da5a..d75e475 100755
--- a/acid/acid
+++ b/acid/acid
@@ -7,6 +7,7 @@
CYCHE_SERVICE_DIR="/data/services"
CYCHE_LOG_DIR="/data/logs"
CYCHE_STATUS_FILE="/data/status"
+NULL_HASH="0000000000000000000000000000000000000000"
source config.sh
now() {
diff --git a/acid/acid-source b/acid/acid-source
index 29b1516..351d3d0 100755
--- a/acid/acid-source
+++ b/acid/acid-source
@@ -12,8 +12,8 @@
# The caller should cache this hash value upon successful deployment.
#
# 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.
+# otherwise a stale success exits with 0. On any error, the null hash is
+# printed, and we exit with 2.
gethash() {
git for-each-ref \
@@ -23,16 +23,21 @@ gethash() {
"$1" # pattern
}
+fail() {
+ echo "$NULL_HASH"
+ exit 2
+}
+
cd "$CYCHE_SERVICE_DIR"
# For <name>, limit to a-z, 0-9, -, _
if ! echo "$1" | grep -Eq '^[-_a-z0-9]*$'; then
echo "Bad service name: $1" >&2
- exit 2
+ fail
fi
if ! [ -d "$1" ]; then
- git clone "$2" "$1" >&2 || exit 2
+ git clone "$2" "$1" >&2 || fail
touch "$1/.git/previous_hash"
touch "$1/.git/previous_slug"
fi
@@ -40,14 +45,14 @@ fi
cd "$1"
git remote set-url origin "$2" >&2 # pick up url changes
-git fetch --all --prune >&2 || exit 2
+git fetch --all --prune >&2 || fail
prev=$(cat '.git/previous_hash')
next=$(gethash "$3")
if [ -z "$next" ]; then
echo "No refs match $3" >&2
- exit 2
+ fail
fi
echo "$next"