Added SVN deployment tasks
This commit is contained in:
parent
0b7c9c07e2
commit
8a35182d81
241
RoboFile.php
241
RoboFile.php
@ -11,6 +11,7 @@
|
|||||||
* @version 1.4.2
|
* @version 1.4.2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Robo\Exception\TaskException;
|
||||||
use Robo\Tasks;
|
use Robo\Tasks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,6 +19,7 @@ use Robo\Tasks;
|
|||||||
*/
|
*/
|
||||||
class RoboFile extends Tasks {
|
class RoboFile extends Tasks {
|
||||||
const PROJECT_NAME = 'statify-blacklist';
|
const PROJECT_NAME = 'statify-blacklist';
|
||||||
|
const SVN_URL = 'https://plugins.svn.wordpress.org/statify-blacklist';
|
||||||
|
|
||||||
const OPT_TARGET = 'target';
|
const OPT_TARGET = 'target';
|
||||||
const OPT_SKIPTEST = 'skipTests';
|
const OPT_SKIPTEST = 'skipTests';
|
||||||
@ -67,14 +69,13 @@ class RoboFile extends Tasks {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function clean(
|
public function clean( $opts = [ self::OPT_TARGET => 'dist' ] ) {
|
||||||
$opts = [
|
|
||||||
self::OPT_TARGET => 'dist'
|
|
||||||
]
|
|
||||||
) {
|
|
||||||
$this->say( 'Cleaning target directory...' );
|
$this->say( 'Cleaning target directory...' );
|
||||||
if ( is_dir( $this->target_dir ) ) {
|
if ( is_dir( $this->target_dir . '/' . $this->final_name ) ) {
|
||||||
$this->taskCleanDir( [ $this->target_dir ] )->run();
|
$this->_deleteDir( [ $this->target_dir . '/' . $this->final_name ] );
|
||||||
|
}
|
||||||
|
if ( is_file( $this->target_dir . '/' . $this->final_name . '.zip' ) ) {
|
||||||
|
$this->_remove( $this->target_dir . '/' . $this->final_name . '.zip' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ class RoboFile extends Tasks {
|
|||||||
self::OPT_SKIPSTYLE => false,
|
self::OPT_SKIPSTYLE => false,
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
$this->clean($opts);
|
$this->clean( $opts );
|
||||||
if ( isset( $opts[ self::OPT_SKIPTEST ] ) && true === $opts[ self::OPT_SKIPTEST ] ) {
|
if ( isset( $opts[ self::OPT_SKIPTEST ] ) && true === $opts[ self::OPT_SKIPTEST ] ) {
|
||||||
$this->say( 'Tests skipped' );
|
$this->say( 'Tests skipped' );
|
||||||
} else {
|
} else {
|
||||||
@ -156,10 +157,232 @@ class RoboFile extends Tasks {
|
|||||||
self::OPT_SKIPSTYLE => false,
|
self::OPT_SKIPSTYLE => false,
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
$this->build($opts);
|
$this->build( $opts );
|
||||||
$this->say( 'Packaging...' );
|
$this->say( 'Packaging...' );
|
||||||
$this->taskPack( $this->target_dir . '/' . $this->final_name . '.zip' )
|
$this->taskPack( $this->target_dir . '/' . $this->final_name . '.zip' )
|
||||||
->addDir( '', $this->target_dir . '/' . $this->final_name )
|
->addDir( '', $this->target_dir . '/' . $this->final_name )
|
||||||
->run();
|
->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploy development version (trunk).
|
||||||
|
*
|
||||||
|
* @param array $opts Options.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws TaskException On errors.
|
||||||
|
*/
|
||||||
|
public function deployTrunk(
|
||||||
|
$opts = [
|
||||||
|
self::OPT_TARGET => 'dist',
|
||||||
|
self::OPT_SKIPTEST => false,
|
||||||
|
self::OPT_SKIPSTYLE => false,
|
||||||
|
]
|
||||||
|
) {
|
||||||
|
// First execute build job.
|
||||||
|
$this->build( $opts );
|
||||||
|
|
||||||
|
// Prepare VCS, either checkout or update local copy.
|
||||||
|
$this->prepareVCS();
|
||||||
|
|
||||||
|
$this->say( 'Preparing deployment directory...' );
|
||||||
|
$this->updateVCStrunk();
|
||||||
|
|
||||||
|
// Update remote repository.
|
||||||
|
$this->say( 'Deploying...' );
|
||||||
|
$this->commitVCS(
|
||||||
|
'--force trunk/*',
|
||||||
|
'Updated ' . self::PROJECT_NAME . ' trunk'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploy current version tag.
|
||||||
|
*
|
||||||
|
* @param array $opts Options.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws TaskException On errors.
|
||||||
|
*/
|
||||||
|
public function deployTag(
|
||||||
|
$opts = [
|
||||||
|
self::OPT_TARGET => 'dist',
|
||||||
|
self::OPT_SKIPTEST => false,
|
||||||
|
self::OPT_SKIPSTYLE => false,
|
||||||
|
]
|
||||||
|
) {
|
||||||
|
// First execute build job.
|
||||||
|
$this->build( $opts );
|
||||||
|
|
||||||
|
// Prepare VCS, either checkout or update local copy.
|
||||||
|
$this->prepareVCS();
|
||||||
|
|
||||||
|
$this->say( 'Preparing deployment directory...' );
|
||||||
|
$this->updateVCStag();
|
||||||
|
|
||||||
|
// Update remote repository.
|
||||||
|
$this->say( 'Deploying...' );
|
||||||
|
$this->commitVCS(
|
||||||
|
'tags/' . $this->version,
|
||||||
|
'Updated ' . self::PROJECT_NAME . ' v' . $this->version
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploy current version tag.
|
||||||
|
*
|
||||||
|
* @param array $opts Options.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws TaskException On errors.
|
||||||
|
*/
|
||||||
|
public function deployReadme(
|
||||||
|
$opts = [
|
||||||
|
self::OPT_TARGET => 'dist',
|
||||||
|
self::OPT_SKIPTEST => false,
|
||||||
|
self::OPT_SKIPSTYLE => false,
|
||||||
|
]
|
||||||
|
) {
|
||||||
|
// First execute build job.
|
||||||
|
$this->build( $opts );
|
||||||
|
|
||||||
|
// Prepare VCS, either checkout or update local copy.
|
||||||
|
$this->prepareVCS();
|
||||||
|
|
||||||
|
$this->updateVCSreadme();
|
||||||
|
|
||||||
|
// Update remote repository.
|
||||||
|
$this->say( 'Deploying...' );
|
||||||
|
$this->commitVCS(
|
||||||
|
'--force trunk/README.md',
|
||||||
|
'Updated ' . self::PROJECT_NAME . ' ReadMe'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploy current version tag and trunk.
|
||||||
|
*
|
||||||
|
* @param array $opts Options.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws TaskException On errors.
|
||||||
|
*/
|
||||||
|
public function deployAll(
|
||||||
|
$opts = [
|
||||||
|
self::OPT_TARGET => 'dist',
|
||||||
|
self::OPT_SKIPTEST => false,
|
||||||
|
self::OPT_SKIPSTYLE => false,
|
||||||
|
]
|
||||||
|
) {
|
||||||
|
// First execute build job.
|
||||||
|
$this->build( $opts );
|
||||||
|
|
||||||
|
// Prepare VCS, either checkout or update local copy.
|
||||||
|
$this->prepareVCS();
|
||||||
|
|
||||||
|
$this->say( 'Preparing deployment directory...' );
|
||||||
|
$this->updateVCStrunk();
|
||||||
|
$this->updateVCStag();
|
||||||
|
|
||||||
|
// Update remote repository.
|
||||||
|
$this->say( 'Deploying...' );
|
||||||
|
$this->commitVCS(
|
||||||
|
[
|
||||||
|
'--force trunk/*',
|
||||||
|
'--force tags/' . $this->version,
|
||||||
|
],
|
||||||
|
'Updated ' . self::PROJECT_NAME . ' v' . $this->version
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare VCS direcory.
|
||||||
|
*
|
||||||
|
* Checkout or update local copy of SVN repository.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws TaskException On errors.
|
||||||
|
*/
|
||||||
|
private function prepareVCS() {
|
||||||
|
if ( is_dir( $this->target_dir . '/svn' ) ) {
|
||||||
|
$this->taskSvnStack()
|
||||||
|
->stopOnFail()
|
||||||
|
->dir( $this->target_dir . '/svn/statify-blacklist' )
|
||||||
|
->update()
|
||||||
|
->run();
|
||||||
|
} else {
|
||||||
|
$this->_mkdir( $this->target_dir . '/svn' );
|
||||||
|
$this->taskSvnStack()
|
||||||
|
->dir( $this->target_dir . '/svn' )
|
||||||
|
->checkout( self::SVN_URL )
|
||||||
|
->run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit VCS changes
|
||||||
|
*
|
||||||
|
* @param string|array $to_add Files to add.
|
||||||
|
* @param string $msg Commit message.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws TaskException On errors.
|
||||||
|
*/
|
||||||
|
private function commitVCS( $to_add, $msg ) {
|
||||||
|
$task = $this->taskSvnStack()
|
||||||
|
->stopOnFail()
|
||||||
|
->dir( $this->target_dir . '/svn/statify-blacklist' );
|
||||||
|
|
||||||
|
if ( is_array( $to_add ) ) {
|
||||||
|
foreach ( $to_add as $ta ) {
|
||||||
|
$task = $task->add( $ta );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$task = $task->add( $to_add );
|
||||||
|
}
|
||||||
|
|
||||||
|
$task->commit( $msg )->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update SVN readme file.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function updateVCSreadme() {
|
||||||
|
$trunk_dir = $this->target_dir . '/svn/statify-blacklist/trunk';
|
||||||
|
$this->_copy( $this->target_dir . '/' . $this->final_name . 'README.md', $trunk_dir . 'README.md' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update SVN development version (trunk).
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function updateVCStrunk() {
|
||||||
|
// Clean trunk directory.
|
||||||
|
$trunk_dir = $this->target_dir . '/svn/statify-blacklist/trunk';
|
||||||
|
$this->taskCleanDir( $trunk_dir )->run();
|
||||||
|
|
||||||
|
// Copy built bundle to trunk.
|
||||||
|
$this->taskCopyDir( [ $this->target_dir . '/' . $this->final_name => $trunk_dir ] )->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update current SVN version tag.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function updateVCStag() {
|
||||||
|
// Clean tag directory if it exists.
|
||||||
|
$tag_dir = $this->target_dir . '/svn/statify-blacklist/tags/' . $this->version;
|
||||||
|
if ( is_dir( $tag_dir ) ) {
|
||||||
|
$this->taskCleanDir( $this->target_dir . '/svn/statify-blacklist/tags/' . $this->version )->run();
|
||||||
|
} else {
|
||||||
|
$this->_mkdir( $tag_dir );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy built bundle to trunk.
|
||||||
|
$this->taskCopyDir( [ $this->target_dir . '/' . $this->final_name => $tag_dir ] )->run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
"package": [
|
"package": [
|
||||||
"robo package"
|
"robo package"
|
||||||
],
|
],
|
||||||
|
"deploy": [
|
||||||
|
"robo deploy:all"
|
||||||
|
],
|
||||||
"test-all": [
|
"test-all": [
|
||||||
"@test",
|
"@test",
|
||||||
"@test-cs"
|
"@test-cs"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user