-
-
Save normanlolx/91411e5494f5e04e000a7cf28df95447 to your computer and use it in GitHub Desktop.
PHP webhook to pull and Gulp build automatically after push
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
<?php | |
if ( isset($_POST['payload']) && $_POST['payload'] ) { | |
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser git pull'); | |
echo shell_exec('cd /var/www/mydrupal/sites/all/themes/mytheme/ && sudo -u myuser node ./node_modules/gulp/bin/gulp.js mygulptask'); | |
// Adding the drush will cause the delivery being displayed as unsuccessful. Means GitHub doesn't wait so long. The command will run nevertheless. | |
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser drush @sites cc all -y'); | |
} | |
// Should return www-data | |
echo shell_exec('whoami'); | |
// Should return myuser | |
echo shell_exec('sudo -u myuser whoami'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/etc/sudoers
:www-data ALL = (myuser) NOPASSWD: /usr/bin/git
www-data ALL = (myuser) NOPASSWD: /usr/bin/node
www-data ALL = (myuser) NOPASSWD: /usr/bin/drush
www-data ALL = (myuser) NOPASSWD: /usr/bin/whoami