-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Loading branch information
Showing
5 changed files
with
295 additions
and
295 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
/** | ||
* @package CodeIgniter Git Deploy | ||
* @author Bo-Yi Wu | ||
* @copyright Copyright (c) 2012, Bo-Yi Wu | ||
* @link https://github.com/appleboy/PHP-Git-Deploy | ||
* @since Version 1.0 | ||
*/ | ||
|
||
/** | ||
* Github config | ||
* | ||
* 1. git command absolute path | ||
* 2. project name, path and branch name | ||
* | ||
* Format: | ||
* array( | ||
* 'project_name' => array( | ||
* 'branch_name' => array('base_path' => 'folder_path') | ||
* ) | ||
* ); | ||
* | ||
* If your github project url path: | ||
* https://github.com/appleboy/CodeIgniter-Git-Deploy | ||
* | ||
* For example: Single project, multi branch | ||
* array( | ||
* 'codeigniter-git-deploy' => array( | ||
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'), | ||
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/') | ||
* ) | ||
* ); | ||
* | ||
* For example: Multi project, multi branch | ||
* array( | ||
* 'codeigniter-git-deploy' => array( | ||
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'), | ||
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/') | ||
* ), | ||
* 'codeigniter-my-model' => array( | ||
* 'master' => array('base_path' => '/path/CodeIgniter-MY-Model_1/'), | ||
* 'develop' => array('base_path' => '/path/CodeIgniter-MY-Model_2/') | ||
* ) | ||
* ); | ||
* | ||
*/ | ||
|
||
$config['git_path'] = '/usr/local/bin/git'; | ||
$config['github'] = array( | ||
'php-git-deploy' => array( | ||
'master' => array('base_path' => '/home/git/test/PHP-Git-Deploy/') | ||
) | ||
); | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
/** | ||
* @package CodeIgniter Git Deploy | ||
* @author Bo-Yi Wu | ||
* @copyright Copyright (c) 2012, Bo-Yi Wu | ||
* @link https://github.com/appleboy/PHP-Git-Deploy | ||
* @since Version 1.0 | ||
*/ | ||
|
||
/** | ||
* Github config | ||
* | ||
* 1. git command absolute path | ||
* 2. project name, path and branch name | ||
* | ||
* Format: | ||
* array( | ||
* 'project_name' => array( | ||
* 'branch_name' => array('base_path' => 'folder_path') | ||
* ) | ||
* ); | ||
* | ||
* If your github project url path: | ||
* https://github.com/appleboy/CodeIgniter-Git-Deploy | ||
* | ||
* For example: Single project, multi branch | ||
* array( | ||
* 'codeigniter-git-deploy' => array( | ||
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'), | ||
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/') | ||
* ) | ||
* ); | ||
* | ||
* For example: Multi project, multi branch | ||
* array( | ||
* 'codeigniter-git-deploy' => array( | ||
* 'master' => array('base_path' => '/path/CodeIgniter-Git-Deploy_1/'), | ||
* 'develop' => array('base_path' => '/path/CodeIgniter-Git-Deploy_2/') | ||
* ), | ||
* 'codeigniter-my-model' => array( | ||
* 'master' => array('base_path' => '/path/CodeIgniter-MY-Model_1/'), | ||
* 'develop' => array('base_path' => '/path/CodeIgniter-MY-Model_2/') | ||
* ) | ||
* ); | ||
* | ||
*/ | ||
|
||
$config['git_path'] = '/usr/local/bin/git'; | ||
$config['github'] = array( | ||
'php-git-deploy' => array( | ||
'master' => array('base_path' => '/home/git/test/PHP-Git-Deploy/') | ||
) | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
/** | ||
* Post-Receive Hooks API | ||
* | ||
* @author appleboy | ||
* @copyright 2012 appleboy | ||
* @link https://github.com/appleboy/PHP-Git-Deploy | ||
* @package CodeIgniter Git Deploy | ||
*/ | ||
class Deploy extends CI_Controller | ||
{ | ||
/** | ||
* Default __construct | ||
* | ||
* @author appleboy | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->config->load('github'); | ||
} | ||
|
||
/** | ||
* | ||
* Post-Receive Hooks | ||
* | ||
* @author appleboy | ||
*/ | ||
public function receive() | ||
{ | ||
// receive git payload | ||
$payload = $this->input->get_post('payload'); | ||
// load git command path config | ||
$git_config = $this->config->item('github'); | ||
$git_path = $this->config->item('git_path'); | ||
|
||
if ($payload and is_array($git_config)) { | ||
$payload = json_decode($payload); | ||
|
||
log_message('debug', 'Post-receive hook initial'); | ||
|
||
foreach ($git_config as $key => $val) { | ||
|
||
// check repository name exist in config | ||
$repository_name = strtolower($payload->repository->name); | ||
if ($repository_name != strtolower($key)) { | ||
continue; | ||
} | ||
|
||
foreach ($val as $k => $v) { | ||
// check if match payload ref branch | ||
$head = 'refs/heads/' . $k; | ||
if ($payload->ref != $head) { | ||
continue; | ||
} | ||
|
||
// git reset head and pull origin branch | ||
if (isset($v['base_path']) and !empty($v['base_path'])) { | ||
$base_path = realpath($v['base_path']) . '/'; | ||
|
||
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" reset --hard HEAD', | ||
$git_path, $base_path, $base_path); | ||
log_message('debug', '$shell value ' . $shell); | ||
$output = shell_exec(escapeshellcmd($shell)); | ||
|
||
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" clean -f', | ||
$git_path, $base_path, $base_path); | ||
log_message('debug', '$shell value ' . $shell); | ||
$output = shell_exec(escapeshellcmd($shell)); | ||
|
||
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" pull origin %s', | ||
$git_path, $base_path, $base_path, $k); | ||
log_message('debug', '$shell value ' . $shell); | ||
$output = shell_exec(escapeshellcmd($shell)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
/** | ||
* Post-Receive Hooks API | ||
* | ||
* @author appleboy | ||
* @copyright 2012 appleboy | ||
* @link https://github.com/appleboy/PHP-Git-Deploy | ||
* @package CodeIgniter Git Deploy | ||
*/ | ||
class Deploy extends CI_Controller | ||
{ | ||
/** | ||
* Default __construct | ||
* | ||
* @author appleboy | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->config->load('github'); | ||
} | ||
|
||
/** | ||
* | ||
* Post-Receive Hooks | ||
* | ||
* @author appleboy | ||
*/ | ||
public function receive() | ||
{ | ||
// receive git payload | ||
$payload = $this->input->get_post('payload'); | ||
// load git command path config | ||
$git_config = $this->config->item('github'); | ||
$git_path = $this->config->item('git_path'); | ||
|
||
if ($payload and is_array($git_config)) { | ||
$payload = json_decode($payload); | ||
|
||
log_message('debug', 'Post-receive hook initial'); | ||
|
||
foreach ($git_config as $key => $val) { | ||
|
||
// check repository name exist in config | ||
$repository_name = strtolower($payload->repository->name); | ||
if ($repository_name != strtolower($key)) { | ||
continue; | ||
} | ||
|
||
foreach ($val as $k => $v) { | ||
// check if match payload ref branch | ||
$head = 'refs/heads/' . $k; | ||
if ($payload->ref != $head) { | ||
continue; | ||
} | ||
|
||
// git reset head and pull origin branch | ||
if (isset($v['base_path']) and !empty($v['base_path'])) { | ||
$base_path = realpath($v['base_path']) . '/'; | ||
|
||
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" reset --hard HEAD', | ||
$git_path, $base_path, $base_path); | ||
log_message('debug', '$shell value ' . $shell); | ||
$output = shell_exec(escapeshellcmd($shell)); | ||
|
||
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" clean -f', | ||
$git_path, $base_path, $base_path); | ||
log_message('debug', '$shell value ' . $shell); | ||
$output = shell_exec(escapeshellcmd($shell)); | ||
|
||
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" pull origin %s', | ||
$git_path, $base_path, $base_path, $k); | ||
log_message('debug', '$shell value ' . $shell); | ||
$output = shell_exec(escapeshellcmd($shell)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.