How can I automatically deploy my app after a git push ( GitHub and node.js)?

Example in PHP:

Navigate to github into your github repository add click “Admin”

click tab ‘Service Hooks’ => ‘WebHook URLs’

and add

http://your-domain-name/git_test.php

then create git_test.php

<?php 
try
{
  $payload = json_decode($_REQUEST['payload']);
}
catch(Exception $e)
{
  exit(0);
}

//log the request
file_put_contents('logs/github.txt', print_r($payload, TRUE), FILE_APPEND);


if ($payload->ref === 'refs/heads/master')
{
  // path to your site deployment script
  exec('./build.sh');
}

In the build.sh you will need to put usual commands to retrieve your site from github

Leave a Comment