Skip to content

Instantly share code, notes, and snippets.

@mikebell
Created January 6, 2016 20:49
Show Gist options
  • Save mikebell/de71ea97bee4332797e9 to your computer and use it in GitHub Desktop.
Save mikebell/de71ea97bee4332797e9 to your computer and use it in GitHub Desktop.
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
public $site = 'SITENAMEHERE';
// Define public methods as commands
function setup() {
$this->_mkdir($this->site);
$this->_mkdir($this->site . '/releases');
}
function composerBuild() {
$this->taskComposerInstall()->run();
}
function release() {
// Set time release started.
$time = time();
$this->composerBuild();
// Use rsync instead for better support and options.
$this->taskRsync()
->fromPath('.')
->toPath($this->site . '/releases/' . $time)
->recursive()
->excludeVcs()
->wholeFile()
->humanReadable()
->run();
$this->_symlink($this->site . '/releases/' . $time, $this->site . '/releases/current');
}
function rollback($version = 'last') {
// List all dirs in site directory.
$rollbackdirs = array_filter(glob($this->site . '/releases/*'), 'is_dir');
// Clean up the output to make working with it easier.
array_walk($rollbackdirs, array($this, 'arrayClean'));
// Remove 'current' directory from list. Current should always be last item.
array_pop($rollbackdirs);
if ($version == 'last') {
$version = end($rollbackdirs);
}
else {
// Check if version exists.
if ($key = array_search($version, $rollbackdirs)) {
$version = $rollbackdirs[$key];
}
else {
return print 'Version not found';
}
}
// Re-symlink
$this->_symlink($this->site . '/releases/' . $version, $this->site . '/releases/current');
}
function arrayClean(&$item, $key) {
$item = str_replace($this->site . '/releases/', '', $item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment