Last active
April 15, 2017 11:38
-
-
Save actual-saurabh/03b462eb9e77854d3b31a2e36fa2e6a5 to your computer and use it in GitHub Desktop.
Regular deployment webhook script for deployment tutorial here: https://baapwp.me/2017/04/15/creating-simple-deployment-script-php/
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 | |
$repositories = array( | |
'custom-theme' => array( | |
'git_url' => '[email protected]/yapapaya/custom-theme.git', | |
'branch' => 'master', | |
'path' => '/var/www/dev.yoursite.com/htdocs/wp-content/themes/', | |
), | |
'custom-plugin' => array( | |
'git_url' => '[email protected]/yapapaya/custom-plugin.git', | |
'branch' => 'master', | |
'path' => '/var/www/dev.yoursite.com/htdocs/wp-content/plugins/' | |
), | |
); | |
if ( ! is_dir( '/var/www/dev.yoursite.com/htdocs/repositories/' ) ) { | |
mkdir( '/var/www/dev.yoursite.com/htdocs/repositories/' ); | |
} | |
$original_dir = getcwd(); | |
foreach ( $repositories as $repo_name => $repo ) { | |
$repo_path = "/var/www/dev.yoursite.com/htdocs/repositories/$repo_name"; | |
$deploy_path = $repo[ 'path' ] . '/' . $repo_name; | |
if ( ! is_dir( $repo_path ) ) { | |
mkdir( $repo_path ); | |
} | |
chdir( $repo_path ); | |
if ( ! is_dir( '.git' ) ) { | |
exec( 'git init' ); | |
exec( 'git remote add origin ' . $repo[ 'git_url' ] ); | |
} | |
exec( 'git pull origin ' . $repo[ 'branch' ] ); | |
if ( ! is_dir( $deploy_path ) ) { | |
mkdir( $deploy_path ); | |
} | |
exec( "git archive {$repo[ 'branch' ]} | (cd " . $deploy_path . " && tar -x)" ); | |
chdir( $original_dir ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment