Skip to content

Instantly share code, notes, and snippets.

@ivangabriele
Last active August 22, 2021 14:16
Show Gist options
  • Save ivangabriele/1ca08023a99e65a6ffc5dc45a0ec7741 to your computer and use it in GitHub Desktop.
Save ivangabriele/1ca08023a99e65a6ffc5dc45a0ec7741 to your computer and use it in GitHub Desktop.
Github Post Receive Hook
#!/bin/bash
# Exit when any command fails:
set -e
TARGET="/home/.../deployments/matomo"
GIT_DIR="/home/.../repositories/matomo.git"
BRANCH="main"
while read oldrev newrev ref
do
# Only checking out the specified branch:
if [[ $ref = "refs/heads/${BRANCH}" ]]
then
echo "Git reference $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree="$TARGET" --git-dir="$GIT_DIR" checkout -f "$BRANCH"
cd $TARGET
sudo make start
else
echo "Git reference $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment