Last active
August 22, 2020 18:04
-
-
Save daopk/1961e99eff9e66de41c194833534f6ea to your computer and use it in GitHub Desktop.
Git hooks post-receive with auto install node modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TRAGET="/path/to/your/website/folder" | |
GIT_DIR="/path/to/your/git/repo.git" | |
BRANCH="master" | |
while read oldrev newrev ref | |
do | |
# only checking out the master (or whatever branch you would like to deploy) | |
if [[ $ref = refs/heads/$BRANCH ]]; | |
then | |
echo "Ref $ref received. Deploying ${BRANCH} branch to production..." | |
git --work-tree=$TRAGET --git-dir=$GIT_DIR checkout $BRANCH -f | |
cd $TRAGET | |
# Install node_modules | |
git diff-tree -r --name-only --no-commit-id $oldrev $newrev | grep --quiet "package.json" && \ | |
echo "package.json changed" && \ | |
echo "Run: npm install" && \ | |
npm install | |
# npm run build | |
else | |
echo "Ref $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