]> littlesong.place Git - littlesongplace.git/commitdiff
Add post-receive hook
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 17 Aug 2025 16:29:57 +0000 (12:29 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 17 Aug 2025 16:57:06 +0000 (12:57 -0400)
.githooks/post-receive [new file with mode: 0755]

diff --git a/.githooks/post-receive b/.githooks/post-receive
new file mode 100755 (executable)
index 0000000..1e97da0
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# Convert README to HTML for gitweb summary page
+git cat-file blob HEAD:README.md | markdown > $GIT_DIR/README.html
+
+MASTER_UPDATED=false
+DEV_UPDATED=false
+while read OLDREV NEWREV REFNAME
+do
+    BRANCH=$(git rev-parse --symbolic --abbrev-ref $REFNAME)
+    if [ "master" = "$BRANCH" ]; then
+        MASTER_UPDATED=true
+    elif [ "dev" = "$BRANCH" ]; then
+        DEV_UPDATED=true
+    fi
+done
+
+function build_and_run {
+    BRANCH="$1"
+    OUTDIR="$2"
+    echo "Deploying $BRANCH"
+
+    echo "Preparing workspace..."
+    BUILDDIR=/tmp/lspbuild
+    rm -rf $BUILDDIR && mkdir $BUILDDIR
+    cd $BUILDDIR
+    git clone -b "$BRANCH" /pub/git/littlesongplace.git .
+    python3 -m venv .venv
+    . .venv/bin/activate
+    pip install --upgrade build
+
+    echo "Building..."
+    python -m build .
+
+    echo "Running..."
+    deactivate
+    . "${OUTDIR}/venv/bin/activate"
+    pip install --ignore-installed ./dist/*.whl
+    sudo systemctl restart littlesongplace.service
+
+    echo "Done!"
+}
+
+if [ "$MASTER_UPDATED" = true ]; then
+    build_and_run master /var/www/littlesongplace
+fi
+
+if [ "$DEV_UPDATED" = true ]; then
+    build_and_run dev /var/www/littlesongplace-test
+fi
+