Skip to content

Commit

Permalink
Issue #25: NEPT-1105: Allow to define commands in runner.yml.dist
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco authored Jan 13, 2018
1 parent c49e4f8 commit 2de8d06
Show file tree
Hide file tree
Showing 24 changed files with 555 additions and 425 deletions.
9 changes: 5 additions & 4 deletions bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use Symfony\Component\Console\Input\ArgvInput;
use EC\OpenEuropa\TaskRunner\TaskRunner;

if (file_exists(__DIR__.'/../vendor/autoload.php')) {
require_once __DIR__.'/../vendor/autoload.php';
$classLoader = require __DIR__.'/../vendor/autoload.php';
} elseif (file_exists(__DIR__.'/../../../autoload.php')) {
require_once __DIR__ . '/../../../autoload.php';
$classLoader = require __DIR__ . '/../../../autoload.php';
}

$statusCode = (new TaskRunner())->run();
exit($statusCode);
$runner = new TaskRunner();
$runner->registerExternalCommands($classLoader);
exit($runner->run());
10 changes: 0 additions & 10 deletions config/commands/setup.yml

This file was deleted.

8 changes: 7 additions & 1 deletion config/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Global Task Runner settings.
runner:
bin-dir: "./vendor/bin"
bin_dir: "./vendor/bin"

# Drupal-related setting values.
# All default values below refers to Drupal 8.
Expand Down Expand Up @@ -75,3 +75,9 @@ github:

# GitHub OAuth token.
token: ~

commands:
setup:behat:
- { task: "process", source: "behat.yml.dist", destination: "behat.yml" }
setup:phpunit:
- { task: "process", source: "phpunit.xml.dist", destination: "phpunit.xml" }
18 changes: 2 additions & 16 deletions src/Commands/BaseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@

namespace EC\OpenEuropa\TaskRunner\Commands;

use Consolidation\AnnotatedCommand\AnnotatedCommand;
use Consolidation\AnnotatedCommand\AnnotationData;
use Robo\Common\ConfigAwareTrait;
use Robo\Common\IO;
use Robo\Contract\ConfigAwareInterface;
use Robo\Contract\IOAwareInterface;
use Robo\Contract\BuilderAwareInterface;
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;
use Robo\Exception\TaskException;
use Robo\LoadAllTasks;
use Robo\Result;
use Robo\Robo;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

/**
* Class BaseCommands.
Expand Down Expand Up @@ -52,13 +44,7 @@ public function getConfigurationFile()
*/
public function initializeRuntimeConfiguration(ConsoleCommandEvent $event)
{
$workingDir = $event->getInput()->getOption('working-dir');

Robo::loadConfiguration([
$workingDir.'/runner.yml.dist',
$workingDir.'/runner.yml',
$this->getConfigurationFile(),
], $this->getConfig());
Robo::loadConfiguration([$this->getConfigurationFile()], $this->getConfig());
}

/**
Expand All @@ -69,7 +55,7 @@ public function initializeRuntimeConfiguration(ConsoleCommandEvent $event)
*/
protected function getBin($name)
{
$filename = $this->getConfig()->get('runner.bin-dir').'/'.$name;
$filename = $this->getConfig()->get('runner.bin_dir').'/'.$name;
if (!file_exists($filename) && !$this->isSimulating()) {
throw new TaskException($this, "Executable '{$filename}' not found.");
}
Expand Down
47 changes: 14 additions & 33 deletions src/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
namespace EC\OpenEuropa\TaskRunner\Commands;

use EC\OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use EC\OpenEuropa\TaskRunner\Traits\ComposerAwareTrait;
use EC\OpenEuropa\TaskRunner\Traits\ConfigurationTokensTrait;
use EC\OpenEuropa\TaskRunner\Traits\PathUtilitiesTrait;
use EC\OpenEuropa\TaskRunner\Contract\FilesystemAwareInterface;
use Robo\Exception\TaskException;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Yaml\Yaml;
use EC\OpenEuropa\TaskRunner\Tasks as TaskRunnerTasks;
use EC\OpenEuropa\TaskRunner\Traits as TaskRunnerTraits;
use NuvoleWeb\Robo\Task as NuvoleWebTasks;

/**
* Class DrupalCommands.
*
* @package EC\OpenEuropa\TaskRunner\Commands
*/
class DrupalCommands extends BaseCommands implements ComposerAwareInterface
class DrupalCommands extends BaseCommands implements ComposerAwareInterface, FilesystemAwareInterface
{
use ComposerAwareTrait;
use ConfigurationTokensTrait;
use PathUtilitiesTrait;
use \NuvoleWeb\Robo\Task\Config\Php\loadTasks;
use TaskRunnerTraits\ComposerAwareTrait;
use TaskRunnerTraits\ConfigurationTokensTrait;
use TaskRunnerTraits\FilesystemAwareTrait;
use TaskRunnerTasks\CollectionFactory\loadTasks;
use NuvoleWebTasks\Config\Php\loadTasks;

/**
* {@inheritdoc}
Expand All @@ -32,16 +33,6 @@ public function getConfigurationFile()
return __DIR__.'/../../config/commands/drupal.yml';
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
*
* @hook init
*/
public function init(InputInterface $input)
{
$this->getComposer()->setWorkingDir($input->getOption('working-dir'));
}

/**
* Command initialization.
*
Expand Down Expand Up @@ -157,18 +148,9 @@ public function siteInstall(array $options = [
*/
public function sitePostInstall()
{
$commands = $this->getConfig()->get('drupal.post_install');
if (!empty($commands)) {
$taskStack = $this->taskExecStack();

foreach ($commands as $command) {
$taskStack->exec($command);
}

return $taskStack;
}
$tasks = $this->getConfig()->get('drupal.post_install');

return $this->taskExec('');
return $this->taskCollectionFactory($tasks);
}

/**
Expand Down Expand Up @@ -337,9 +319,8 @@ protected function setupSiteBuild($root, $symlinks = [])

foreach ($symlinks as $symlink) {
if (is_dir($symlink['from']) || $this->isSimulating()) {
$destination = $root.'/'.$symlink['to'];
$source = $this->walkPath($destination, $symlink['from']);
$collection->addTask($this->taskFilesystemStack()->symlink($source, $destination));
$source = $this->getFilesystem()->makePathRelative($symlink['from'], $symlink['to']);
$collection->addTask($this->taskFilesystemStack()->symlink($source, $root.'/'.$symlink['to']));
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/Commands/DynamicCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace EC\OpenEuropa\TaskRunner\Commands;

use EC\OpenEuropa\TaskRunner\Tasks\CollectionFactory\loadTasks;

/**
* Class DynamicCommands
*
* @package EC\OpenEuropa\TaskRunner\Commands
*/
class DynamicCommands extends BaseCommands
{
use loadTasks;

/**
* @return \EC\OpenEuropa\TaskRunner\Tasks\CollectionFactory\CollectionFactory
*/
public function runTasks()
{
$command = $this->input()->getArgument('command');
$tasks = $this->getConfig()->get("commands.{$command}");

return $this->taskCollectionFactory($tasks);
}
}
121 changes: 0 additions & 121 deletions src/Commands/SetupCommands.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Contract/ComposerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function getComposer();

/**
* @param \EC\OpenEuropa\TaskRunner\Services\Composer $composer
*
* @return $this
*/
public function setComposer(Composer $composer);
}
23 changes: 23 additions & 0 deletions src/Contract/FilesystemAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace EC\OpenEuropa\TaskRunner\Contract;

/**
* Interface FilesystemAwareTrait
*
* @package EC\OpenEuropa\TaskRunner\Contract
*/
interface FilesystemAwareInterface
{
/**
* @return \Symfony\Component\Filesystem\Filesystem
*/
public function getFilesystem();

/**
* @param \Symfony\Component\Filesystem\Filesystem $filesystem
*
* @return $this
*/
public function setFilesystem($filesystem);
}
Loading

0 comments on commit 2de8d06

Please sign in to comment.