Skip to content

Instantly share code, notes, and snippets.

@bangpound
Last active April 26, 2017 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bangpound/7d96f3088b7565f3323baa6481ceb0e4 to your computer and use it in GitHub Desktop.
Save bangpound/7d96f3088b7565f3323baa6481ceb0e4 to your computer and use it in GitHub Desktop.

RoboFile for ActiveCampaign

  1. composer global require consolidation/robo or download robo.phar from http://robo.li/ and put it in your $PATH.
  2. Copy the RoboFile.php above so that it is a sibling of dev
  3. Modify the properties at the top like the $originPrefix and $allRepos.

Some things

  • robo git:update to add the upstream remote to all of your repositories.
  • robo git:fetch to get updates from upstream.
  • robo git:switch version-8.11 to check out version-8.11 from the versioned repositories.
  • robo git:rebase to rebase the current branch in each repository on the same one from upstream and to push that to origin.
  • robo git:status to show the currently checked out branch on all repositories.
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
/**
* @var string
*/
private $dirPrefix = 'dev';
/**
* @var string
*/
private $upstreamPrefix = 'git@github.com:activecampaign/';
/**
* @var string
*/
private $originPrefix = 'git@github.com:bangpound/';
/**
* @var array
*/
private $allRepos = ['Hosted-Scripts', 'cdn', 'ember-app', 'Hosted', 'library', 'provision'];
/**
* @var array
*/
private $versionedRepos = ['ember-app', 'Hosted'];
// add method for switching to node@0.12
// add method for running nombom
/**
* Pull all repositories.
*/
public function gitUp()
{
foreach ($this->allRepos as $repo) {
$this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->pull()->run();
}
}
/**
* Switch ember-app and Hosted repositories to specified branch.
*/
public function gitSwitch($branch = 'version-8.3')
{
foreach ($this->versionedRepos as $repo) {
$this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->checkout($branch)->run();
}
}
/**
* Clone all repositories and set ActiveCampaign as upstream remote.
*/
public function gitClone()
{
foreach ($this->allRepos as $repo) {
$this->taskGitStack()->cloneRepo($this->originPrefix . $repo . '.git', $this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->run();
$this->taskExec('git')->args(['remote', 'add', 'upstream', $this->upstreamPrefix . $repo . '.git'])->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->run();
}
}
/**
* Fetch from all repositories.
*/
public function gitFetch()
{
foreach ($this->allRepos as $repo) {
$this->io()->title($repo);
$this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->exec(['fetch', '--all'])->printOutput(false)->run();
}
}
/**
* Rebase checked out branches on upstream and push to origin.
*/
public function gitRebase()
{
foreach ($this->allRepos as $repo) {
$this->io()->title($repo);
$this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->exec(['fetch', '--all'])->printOutput(false)->run();
/** @var \Robo\Result $result */
$result = $this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->exec(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])->printOutput(false)->run();
$branch = $result->getOutputData();
$this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->exec(['rebase', '--autostash', 'upstream/'. $branch])->printOutput(false)->run();
$this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->push('origin')->printOutput(false)->run();
}
}
public function gitUpdate()
{
foreach ($this->allRepos as $repo) {
$this->taskGitStack()->exec($this->originPrefix . $repo . '.git', $this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->run();
$this->taskExec('git')->args(['remote', 'add', 'upstream', $this->upstreamPrefix . $repo . '.git'])->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->run();
}
}
/**
* Show status of all repositories.
*/
public function gitStatus()
{
$table = new \Symfony\Component\Console\Helper\Table($this->output);
$table->setHeaders(['Repo', 'Branch']);
foreach ($this->allRepos as $repo) {
$result = $this->taskGitStack()->dir($this->dirPrefix . DIRECTORY_SEPARATOR . $repo)->exec(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])->run();
$branch = trim($result->getOutputData());
$table->addRow([$repo, $branch]);
}
$table->render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment