Last active
April 15, 2017 11:38
-
-
Save actual-saurabh/cd12bda58414cd7a2da36aff263f18f5 to your computer and use it in GitHub Desktop.
Slim deployment with svn fallback for GitHub 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 ) { | |
$deploy_path = $repo[ 'path' ] . '/' . $repo_name; | |
if ( ! is_dir( $deploy_path ) ) { | |
mkdir( $deploy_path ); | |
} | |
if ( ! strstr( $repo[ 'git_url' ], 'github.com' ) ) { | |
exec( "git archive --remote={$repo[ 'git_url' ]} {$repo[ 'branch' ]} | (cd " . $deploy_path . " && tar -x)" ); | |
} else { | |
$ref_svn = ''; | |
// using the svn client, we map master branch to trunk | |
// and other branches to svn branches | |
if ( $branch === 'master' ) { | |
$ref_svn = 'trunk/'; | |
} else { | |
$ref_svn = "branches/$branch/"; | |
} | |
// get the svn url | |
$svn_url = str_replace( 'git@', 'https://', $repo[ 'git_url' ] ); | |
$svn_url = str_replace( '.git', '', $svn_url ); | |
// run svn export to directly deploy code | |
exec( "svn export $svn_url $ref_svn $path" ); | |
} | |
chdir( $original_dir ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment