From 29d81084963a0bf4250bf4b8edb040865db364d1 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Sun, 17 Aug 2025 12:29:57 -0400 Subject: [PATCH] Add post-receive hook --- .githooks/post-receive | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 .githooks/post-receive 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 + -- 2.39.5