pixelplanet/deployment/githook.sh

65 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2020-01-02 16:58:06 +00:00
#!/bin/bash
2023-12-13 02:53:16 +00:00
# This hook builds pixelplanet after a push to a development branch,
# and starts the dev-canvas
2020-01-02 16:58:06 +00:00
#
2022-06-24 19:38:56 +00:00
# To set up a server to use this, you have to go through the building steps manually first.
2020-01-02 16:58:06 +00:00
#
2023-12-13 02:53:16 +00:00
#folder for building the canvas (the git repository will get checkout there and the canvas will get built thtere)
BUILDDIR="/home/pixelpla/pixelplanet-build"
2020-01-02 16:58:06 +00:00
#folder for dev canvas
DEVFOLDER="/home/pixelpla/pixelplanet-dev"
2020-01-02 16:58:06 +00:00
should_reinstall () {
2022-06-19 16:06:01 +00:00
local TMPFILE="${BUILDDIR}/package.json.${1}.tmp"
local NODEDIR="${BUILDDIR}/node_modules"
local ORFILE="${BUILDDIR}/package.json"
[ -f "${TMPFILE}" ] && [ -d "${NODEDIR}" ] && diff -q "${TMPFILE}" "${ORFILE}" && {
echo "package.json stil the same, no need to rerun npm install."
return 1
}
cp "${ORFILE}" "${TMPFILE}"
echo "package.json changed, need to run npm install."
return 0
}
npm_reinstall () {
rm -rf node_modules
rm package-lock.json
npm install
}
2022-09-11 11:36:50 +00:00
copy () {
local TARGETDIR="${1}"
local REINSTALL="${2}"
2023-12-13 02:53:16 +00:00
cp -r "${BUILDDIR}"/dist/*.js "${TARGETDIR}/"
cp -r "${BUILDDIR}"/dist/workers "${TARGETDIR}/"
2022-09-11 11:36:50 +00:00
rm -rf "${TARGETDIR}/public/assets"
2023-12-13 02:53:16 +00:00
cp -r "${BUILDDIR}"/dist/public "${TARGETDIR}/"
cp -r "${BUILDDIR}"/dist/captchaFonts "${TARGETDIR}/"
cp -r "${BUILDDIR}"/dist/package.json "${TARGETDIR}/"
2022-09-11 11:36:50 +00:00
mkdir -p "${TARGETDIR}/log"
cd "${TARGETDIR}"
[ $REINSTALL -eq 0 ] && npm_reinstall
pm2 start ecosystem.yml
cd -
}
2020-01-02 16:58:06 +00:00
while read oldrev newrev refname
do
2022-06-19 16:06:01 +00:00
GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git fetch --all
cd "$BUILDDIR"
2020-01-02 16:58:06 +00:00
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
2023-12-13 02:53:16 +00:00
if [ "test" == "$branch" ] || [ "devel" == "$branch" ]; then
2020-01-02 16:58:06 +00:00
echo "---UPDATING REPO ON DEV SERVER---"
2022-01-03 12:59:40 +00:00
pm2 stop ppfun-server-dev
2020-01-02 16:58:06 +00:00
GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git reset --hard "origin/$branch"
echo "---BUILDING pixelplanet---"
2022-06-19 16:06:01 +00:00
should_reinstall dev
DO_REINSTALL=$?
[ $DO_REINSTALL -eq 0 ] && npm_reinstall
nice -n 19 npm run build:dev
2020-01-02 16:58:06 +00:00
echo "---RESTARTING CANVAS---"
2022-09-11 11:36:50 +00:00
copy "${DEVFOLDER}" "${DO_REINSTALL}"
2020-01-02 16:58:06 +00:00
fi
done