#!/bin/bash
set -e

TARGET="/home3/bosy2587/lexi"
GIT_DIR="/home3/bosy2587/bare/lexi.git"
BRANCH="main"

while read oldrev newrev ref; do
	if [ "$ref" = "refs/heads/$BRANCH" ]; then
		echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
		git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
		cd $TARGET
		pnpm install --frozen-lockfile
		pnpm --filter api build
		pnpm --filter web build
	else
		echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
	fi
done
