Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Drupal component setup command #6 #7

Merged
merged 12 commits into from
Jan 4, 2018
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/vendor/
/tests/sandbox
grumphp.yml
phpunit.xml
composer.lock
behat.yml
RoboFile.php
/tests/sandbox/*
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# OpenEuropa Task Runner

[![Build Status](https://travis-ci.org/ec-europa/oe-task-runner.svg?branch=master)](https://travis-ci.org/ec-europa/oe-task-runner)
[![Build Status](https://travis-ci.org/ec-europa/oe-task-runner.svg?branch=master)](https://travis-ci.org/ec-europa/oe-task-runner)

PHP task runner based on Robo.

After installation run `./vendor/bin/run` and check each command's help:

```bash
$ ./vendor/bin/run
OpenEuropa Task Runner

Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--simulate Run in simulated mode (show what would have happened).
--progress-delay=PROGRESS-DELAY Number of seconds before progress bar is displayed in long-running task collections. Default: 2s. [default: 2]
-D, --define=DEFINE Define a configuration item value. (multiple values allowed)
--working-dir=WORKING-DIR Working directory, defaults to current working directory. [default: "."]
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
help Displays help for a command
list Lists commands
changelog
changelog:generate [changelog:g|cg] Generate a changelog based on GitHub issues and pull requests.
drupal
drupal:component-scaffold [dcs] Scaffold Drupal component development.
drupal:site-install [drupal:si|dsi] Install target site.
setup
setup:behat [setup:b|sb] Setup Behat.
setup:phpunit [setup:p|sp] Setup PHPUnit.
setup:replace [setup:p|sp] Replace configuration tokens in a text file.

```
7 changes: 1 addition & 6 deletions bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,5 @@ if (file_exists(__DIR__.'/../vendor/autoload.php')) {
require_once __DIR__ . '/../../../autoload.php';
}

$runner = new TaskRunner([
getcwd().'/runner.yml.dist',
getcwd().'/runner.yml',
]);

$statusCode = $runner->run();
$statusCode = (new TaskRunner())->run();
exit($statusCode);
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"consolidation/robo": "^1.2"
"consolidation/robo": "^1.2",
"nuvoleweb/robo-config": "~0.2"
},
"require-dev": {
"ec-europa/oe-code-review": "*",
Expand All @@ -22,4 +23,4 @@
}
},
"bin": ["bin/run"]
}
}
Empty file added config/commands/base.yml
Empty file.
14 changes: 12 additions & 2 deletions config/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ runner:

drupal:
core: "8"
root: "build"
root: "./build"
base-url: "http://127.0.0.1:8888"
site:
name: "Site name"
Expand All @@ -21,6 +21,16 @@ drupal:
name: "drupal"
user: "root"
password: "root"
drush:
options:
exclude: "${drupal.root}"
settings:
conf:
file_scan_ignore_directories:
- "node_modules"
- "bower_components"
- "vendor"
- "${drupal.root}"

github:
token: ~
token: ~
47 changes: 38 additions & 9 deletions src/Commands/BaseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,51 @@
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.
*
* @package EC\OpenEuropa\TaskRunner\Commands
*/
class BaseCommands implements BuilderAwareInterface, IOAwareInterface, ContainerAwareInterface, ConfigAwareInterface
class BaseCommands implements BuilderAwareInterface, IOAwareInterface, ConfigAwareInterface
{
use ContainerAwareTrait;
use ConfigAwareTrait;
use LoadAllTasks;
use IO;

/**
* @param InputInterface $input
* @param AnnotationData $annotationData
* Path to YAML configuration file containing command defaults.
*
* @hook init
* Command classes should implement this method.
*
* @return null|string
*/
public function getConfigurationFile()
{
return __DIR__.'/../../config/commands/base.yml';
}

/**
* Command initialization.
*
* @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
*
* @hook pre-command-event *
*/
public function init(InputInterface $input, AnnotationData $annotationData)
public function initializeRuntimeConfiguration(ConsoleCommandEvent $event)
{
$this->setInput($input);
$workingDir = $event->getInput()->getOption('working-dir');

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

/**
Expand All @@ -47,12 +69,19 @@ public function init(InputInterface $input, AnnotationData $annotationData)
*/
protected function getBin($name)
{
$simulate = $this->input()->getOption('simulate');
$filename = $this->getConfig()->get('runner.bin-dir').'/'.$name;
if (!file_exists($filename) && !$simulate) {
if (!file_exists($filename) && !$this->isSimulating()) {
throw new TaskException($this, "Executable '{$filename}' not found.");
}

return $filename;
}

/**
* @return bool
*/
protected function isSimulating()
{
return (bool) $this->input()->getOption('simulate');
}
}
29 changes: 14 additions & 15 deletions src/Commands/ChangelogCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@

namespace EC\OpenEuropa\TaskRunner\Commands;

use EC\OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use EC\OpenEuropa\TaskRunner\Traits\ComposerAwareTrait;
use Symfony\Component\Console\Input\InputOption;

/**
* Class ChangelogCommands
*
* @package EC\OpenEuropa\TaskRunner\Commands
*/
class ChangelogCommands extends BaseCommands
class ChangelogCommands extends BaseCommands implements ComposerAwareInterface
{
use ComposerAwareTrait;

/**
* {@inheritdoc}
*/
public function getConfigurationFile()
{
return __DIR__.'/../../config/commands/changelog.yml';
}

/**
* Generate a changelog based on GitHub issues and pull requests.
*
Expand All @@ -33,7 +45,7 @@ public function generateChangelog(array $options = [
'tag' => InputOption::VALUE_OPTIONAL,
])
{
$projectName = $this->getFullProjectName();
$projectName = $this->getComposer()->getName();
$exec = "{$projectName} -t {$options['token']}";
if (!empty($options['tag'])) {
$exec .= " --future-release={$options['tag']}";
Expand All @@ -47,17 +59,4 @@ public function generateChangelog(array $options = [

return $task;
}

/**
* Get project name from composer.json.
*
* @return string
* Project name.
*/
protected function getFullProjectName()
{
$package = json_decode(file_get_contents('./composer.json'));

return $package->name;
}
}
Loading