Last active
September 2, 2022 13:36
-
-
Save artemsky/c8f3b8a15292a750656386c59e61db1f to your computer and use it in GitHub Desktop.
Post merge git hook to check Laravel 5+ typical resources were updated
This file contains 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 | |
# Looks for changes and automates running bundle and other tasks. | |
# Does not run if your local branch is behind the remote. | |
# https://gist.github.com/stefansundin/82051ad2c8565999b914 | |
# post-checkout hook - looks for changes, | |
# when you change branches, and if found, reinstalls the given packages every | |
# Exit early if this was only a file checkout, not a branch change ($3 == 1) | |
[[ $3 == 0 ]] && exit 0 | |
oldRef=$1 | |
newRef=$2 | |
# Exit early if the local branch is behind the remote | |
LOCAL=$(git rev-parse @) | |
REMOTE=$(git rev-parse @{u} 2> /dev/null) | |
BASE=$(git merge-base @ @{u} 2> /dev/null) | |
if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then | |
echo "You are behind origin, not running bundle/migrate post-checkout hook." | |
exit 1 | |
fi | |
function changed { | |
git diff --name-only $oldRef $newRef | grep "^$1" > /dev/null 2>&1 | |
} | |
if changed 'package.lock'; then | |
echo "[package.lock] changed: Installing npm dependencies..." | |
npm install | |
git add package.json package-lock.json | |
fi | |
if changed 'composer.lock'; then | |
echo "[composer.lock] changed: Installing composer dependencies..." | |
composer install | |
fi | |
if changed 'resources/assets'; then | |
echo "Front-end sources are changed: Building new dev bundle..." | |
npm run dev | |
fi | |
if changed 'database/migrations'; then | |
echo "Migrations are changed: Migrating..." | |
php artisan migrate | |
fi | |
if changed 'database/seeds'; then | |
echo "Seeds are changed: Seeding new data..." | |
php artisan db:seed | |
fi |
This file contains 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 | |
# Looks for changes and automates running bundle and other tasks. | |
# https://gist.github.com/stefansundin/82051ad2c8565999b914 | |
function changed { | |
git diff --name-only HEAD@{2} HEAD | grep "^$1" > /dev/null 2>&1 | |
} | |
if changed 'package.lock'; then | |
echo "[package.lock] changed: Installing npm dependencies..." | |
npm install | |
git add package.json package-lock.json | |
fi | |
if changed 'composer.lock'; then | |
echo "[composer.lock] changed: Installing composer dependencies..." | |
composer install | |
fi | |
if changed 'resources/assets'; then | |
echo "Front-end sources are changed: Building new dev bundle..." | |
npm run dev | |
fi | |
if changed 'database/migrations'; then | |
echo "Migrations are changed: Migrating..." | |
php artisan migrate | |
fi | |
if changed 'database/seeds'; then | |
echo "Seeds are changed: Seeding new data..." | |
php artisan db:seed | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment