From c191b7ee6fb228dd2462ef89de42155c7fa5f047 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 22 Nov 2024 13:26:35 +0100 Subject: [PATCH] Add composer install check --- post-receive | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/post-receive b/post-receive index eb09241..96e0d33 100755 --- a/post-receive +++ b/post-receive @@ -12,27 +12,42 @@ ACCOUNT="" # the account name your site is associated to PASSWORD="" # the account password your site is associated to SITE_ID="000000" # the reference ID of your site you can find in your *sites* section NPM_INSTALL_CHECK=false # a boolean to enable if your site is a _Node.js_ site, and if you want to automatically run `npm install` if your package.json changed since the last push (default to `false`) +COMPOSER_INSTALL_CHECK=false # enable automatic composer install if composer.json or composer.lock changed # Function checking if the "package.json" file has been changed since last push -# MIT © Sindre Sorhus - sindresorhus.com / Adapted by J.M. Cléry for Alwaysdata npm_install_check() { - # git hook to run a command after `git push` if a specified file was changed changed_files="$(git diff --name-only HEAD^ HEAD)" check_run() { if [ $(echo "$changed_files" | grep "$1") ]; then cd $TARGET - echo "'package.json' has been updated! Running 'npm install' automatically for you..." + echo "'$1' has been updated! Running '$2' automatically for you..." eval "$2" cd $GIT_DIR fi } # Run `npm install` ONLY if "package.json" has changed - # check_run package.json "npm install --silent --no-audit --no-progress > /dev/null" check_run package.json "npm install > /dev/null" } +# Function checking if "composer.json" or "composer.lock" has been changed since last push +composer_install_check() { + changed_files="$(git diff --name-only HEAD^ HEAD)" + + check_run() { + if [ $(echo "$changed_files" | grep -E "$1") ]; then + cd $TARGET + echo "'$1' has been updated! Running 'composer install' automatically for you..." + eval "$2" + cd $GIT_DIR + fi + } + + # Run `composer install` if "composer.json" or "composer.lock" has changed + check_run "composer.(json|lock)" "composer install --no-dev --optimize-autoloader" +} + ### # DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING ### @@ -49,11 +64,16 @@ while read oldrev newrev ref; do echo "Deploying '${BRANCH}' branch to production" git --work-tree=$TARGET --git-dir=$GIT_DIR checkout --force $BRANCH - # If it's a Node.js website and `npm install` needs to be trigerred + # If it's a Node.js website and `npm install` needs to be triggered if [ $NPM_INSTALL_CHECK = true ]; then npm_install_check fi + # If it's a Symfony project and `composer install` needs to be triggered + if [ $COMPOSER_INSTALL_CHECK = true ]; then + composer_install_check + fi + if [ "$RESTART" = true ]; then echo "Restarting your web server ..." @@ -63,7 +83,7 @@ while read oldrev newrev ref; do if [ "$status" = 204 ]; then echo "✅ Site successfully restarted!" else - echo "❌ An error occured when restarting your site, try to restart it manually" + echo "❌ An error occurred when restarting your site, try to restart it manually" exit 1 fi fi @@ -77,3 +97,4 @@ while read oldrev newrev ref; do exit 0 fi done +