From: Chris Fulljames Date: Sun, 17 Aug 2025 16:29:57 +0000 (-0400) Subject: Add post-receive hook X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=29d81084963a0bf4250bf4b8edb040865db364d1;p=littlesongplace.git Add post-receive hook --- diff --git a/.githooks/post-receive b/.githooks/post-receive new file mode 100755 index 0000000..1e97da0 --- /dev/null +++ b/.githooks/post-receive @@ -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 +