blob: b009c6389a9505cdf9075915ec103ea0c75596bd (
plain) (
tree)
|
|
#!/bin/sh
# Simple webhook to build and deploy latest blog version.
# The webhook allows to pass an optional ref as url path.
#
# Examples:
# curl <host> ; Will deploy origin/main ref
# curl <host>/blub ; Will deploy origin/blub ref
while true; do
echo "Wait for webhook trigger ..."
# Wait until webhook is triggered and parse out optional branch info.
# The branch info can be passed via the url path, an example is:
# GET /blub HTTP/1.1
REF=$(echo -e "HTTP/1.0 204 No Content\r\nConnection: close\r\n\r" | nc -l -p 80 | awk '/GET/ { print $2; }' | tr -d '/')
# If we got a ref use it else default to main.
REF=origin/${REF:-main}
if [ ! -d blog ]; then
# Clone through podman network.
git clone http://cgito/blog
fi
git -C blog fetch --prune
echo "Checking out & deploying ref: $REF"
git -C blog checkout --quiet $REF || continue
zola --root blog build || continue
# webroot must be mounted at /www.
rm -rf /www/blog
mv blog/public /www/blog
echo "SUCCESS: Updated /www/blog"
done
|