Skip to content

Instantly share code, notes, and snippets.

@normanlolx
Forked from cowboy/github_post_recieve.php
Last active November 6, 2018 14:43
Show Gist options
  • Select an option

  • Save normanlolx/91411e5494f5e04e000a7cf28df95447 to your computer and use it in GitHub Desktop.

Select an option

Save normanlolx/91411e5494f5e04e000a7cf28df95447 to your computer and use it in GitHub Desktop.
PHP webhook to pull and Gulp build automatically after push
<?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');
?>
@normanlolx
Copy link
Copy Markdown
Author

normanlolx commented Jul 3, 2017

/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

@adibnoh
Copy link
Copy Markdown

adibnoh commented Nov 6, 2018

Thanks man! this works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment