Skip to content

Instantly share code, notes, and snippets.

@actual-saurabh
Last active April 15, 2017 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save actual-saurabh/03b462eb9e77854d3b31a2e36fa2e6a5 to your computer and use it in GitHub Desktop.
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/
<?php
$repositories = array(
'custom-theme' => array(
'git_url' => 'git@github.com/yapapaya/custom-theme.git',
'branch' => 'master',
'path' => '/var/www/dev.yoursite.com/htdocs/wp-content/themes/',
),
'custom-plugin' => array(
'git_url' => 'git@github.com/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