仅在更改了特定文件后才在部署脚本中运行命令

时间:2018-06-29 18:45:27

标签: laravel laravel-5 laravel-forge

我刚刚通过我的Laravel Forge部署脚本开始运行npm installnpm run production来在生产站点上编译我的资产。但是,我注意到运行npm install会使我的部署速度降低了几分钟,而且我认为不需要在每次需要推送更新时都运行它。

这是我当前的部署脚本:

cd /home/forge/website.com
git pull origin master
npm install
npm run production # Run build process
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "" | sudo -S service php7.2-fpm reload
if [ -f artisan ]
then
    php artisan route:clear
    php artisan route:cache
    php artisan migrate --force
    php artisan cache:clear
    php artisan config:clear
    php artisan config:cache
    php artisan horizon:terminate
fi

是否可以在运行npm install之前检查package.json文件是否已更改?

这是我尝试过的方法,但是破坏了部署脚本,我很难弄清为什么它不起作用。

cd /home/forge/website.com
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
git pull origin master
check_run package.json "npm install"
npm run production # Run build process
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "" | sudo -S service php7.2-fpm reload
if [ -f artisan ]
then
    php artisan route:clear
    php artisan route:cache
    php artisan migrate --force
    php artisan cache:clear
    php artisan config:clear
    php artisan config:cache
    php artisan horizon:terminate
fi

0 个答案:

没有答案
相关问题