-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
116 lines (104 loc) · 2.88 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
const COMPOSE_BIN = 'docker-compose';
const DRUPAL_ROOT = __DIR__ . '/web';
const DUMP_FILE = __DIR__ . '/dump.sql.gz';
const BEHAT_BIN = './vendor/bin/behat';
const SITENAME = 'super-scripts';
const TERMINUS_BIN = 'terminus';
/**
* Provision the database seed for Docker.
*/
public function dbSeed()
{
$this->_exec('gunzip dump.sql.gz');
$this->taskFilesystemStack()
->mkdir('mariadb-init')
->remove('mariadb-init/dump.sql')
->rename('dump.sql', 'mariadb-init/dump.sql')
->run();
}
/**
* Pull fresh backup from dev site.
*/
public function backupGet()
{
$this->terminusExec('backup:create', [self::SITENAME . '.dev'], ['element', 'db']);
$this->terminusExec('backup:get', [self::SITENAME . '.dev'], ['to', self::DUMP_FILE]);
}
/**
* Run Behat tests.
*/
public function test()
{
$this->taskExec(self::COMPOSE_BIN)
->args(['run', 'testphp', self::BEHAT_BIN])
->option('colors')
->option('format', 'progress')
->run();
}
/**
* Bring containers up, seed files as needed.
*/
public function up()
{
if (!file_exists('mariadb-init/dump.sql') ||
!file_exists('web/sites/default/settings.local.php')
) {
$this->setup();
}
$this->_exec(self::COMPOSE_BIN . ' up -d');
}
/**
* Seed database, shim in settings.local.php
*/
public function setup()
{
$this->terminusLogin();
$this->backupGet();
$this->dbSeed();
}
public function terminusLogin()
{
if (!getenv('TERMINUS_TOKEN')) {
putenv('TERMINUS_TOKEN=' . $this->ask(
'Please insert your Terminus Machine Token (https://dashboard.pantheon.io/machine-token/create)',
true
)
);
}
$token = getenv('TERMINUS_TOKEN');
$this->_exec(self::TERMINUS_BIN . " login --machine-token={$token}");
}
/**
* Build Drush tasks with common arguments.
* @return $this
*/
private function buildDrushTask()
{
return $this->taskDrushStack(self::DRUSH_BIN)
->drupalRootDirectory(self::DRUPAL_ROOT);
}
/**
* Build Terminus Command.
*
* @param string $command
* @param array $args
* @param array $opts
* @return \Robo\Result
*/
private function terminusExec($command = '', array $args = [], array $opt = [])
{
return $this->taskExec(self::TERMINUS_BIN)
->arg($command)
->args($args)
->option($opt[0], $opt[1])
->run();
}
}