Load environment in RoboFile always

[MAILPOET-1883]
This commit is contained in:
Jan Jakeš
2019-04-11 09:34:14 +02:00
committed by wxa
parent 787a43fe84
commit 52f3d52017
2 changed files with 6 additions and 26 deletions

View File

@@ -25,6 +25,7 @@ jobs:
./composer.phar validate --no-check-all --no-check-publish ./composer.phar validate --no-check-all --no-check-publish
./composer.phar validate --no-check-all --no-check-publish --working-dir=prefixer ./composer.phar validate --no-check-all --no-check-publish --working-dir=prefixer
./composer.phar install ./composer.phar install
touch .env
./do install ./do install
./do compile:all --env production ./do compile:all --env production
- save_cache: - save_cache:

View File

@@ -4,6 +4,11 @@ class RoboFile extends \Robo\Tasks {
use \Codeception\Task\SplitTestsByGroups; use \Codeception\Task\SplitTestsByGroups;
public function __construct() {
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
}
function install() { function install() {
return $this->taskExecStack() return $this->taskExecStack()
->stopOnFail() ->stopOnFail()
@@ -151,13 +156,10 @@ class RoboFile extends \Robo\Tasks {
function txinit() { function txinit() {
// Define WP_TRANSIFEX_API_TOKEN env. variable // Define WP_TRANSIFEX_API_TOKEN env. variable
$this->loadEnv();
return $this->_exec('./tasks/transifex_init.sh'); return $this->_exec('./tasks/transifex_init.sh');
} }
function testUnit(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) { function testUnit(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) {
$this->loadEnv();
$command = 'vendor/bin/codecept run unit'; $command = 'vendor/bin/codecept run unit';
if ($opts['file']) { if ($opts['file']) {
@@ -176,8 +178,6 @@ class RoboFile extends \Robo\Tasks {
} }
function testIntegration(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) { function testIntegration(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) {
$this->loadEnv();
$command = 'vendor/bin/codecept run integration'; $command = 'vendor/bin/codecept run integration';
if ($opts['multisite']) { if ($opts['multisite']) {
@@ -204,7 +204,6 @@ class RoboFile extends \Robo\Tasks {
} }
function testCoverage($opts=['file' => null, 'xml' => false]) { function testCoverage($opts=['file' => null, 'xml' => false]) {
$this->loadEnv();
$command = join(' ', array( $command = join(' ', array(
'vendor/bin/codecept run -s acceptance', 'vendor/bin/codecept run -s acceptance',
(($opts['file']) ? $opts['file'] : ''), (($opts['file']) ? $opts['file'] : ''),
@@ -277,19 +276,16 @@ class RoboFile extends \Robo\Tasks {
} }
function testFailedUnit() { function testFailedUnit() {
$this->loadEnv();
$this->_exec('vendor/bin/codecept build'); $this->_exec('vendor/bin/codecept build');
return $this->_exec('vendor/bin/codecept run unit -g failed'); return $this->_exec('vendor/bin/codecept run unit -g failed');
} }
function testFailedIntegration() { function testFailedIntegration() {
$this->loadEnv();
$this->_exec('vendor/bin/codecept build'); $this->_exec('vendor/bin/codecept build');
return $this->_exec('vendor/bin/codecept run integration -g failed'); return $this->_exec('vendor/bin/codecept run integration -g failed');
} }
function containerDump() { function containerDump() {
$this->loadEnv();
define('ABSPATH', getenv('WP_ROOT') . '/'); define('ABSPATH', getenv('WP_ROOT') . '/');
if (!file_exists(ABSPATH . 'wp-config.php')) { if (!file_exists(ABSPATH . 'wp-config.php')) {
$this->yell('WP_ROOT env variable does not contain valid path to wordpress root.', 40, 'red'); $this->yell('WP_ROOT env variable does not contain valid path to wordpress root.', 40, 'red');
@@ -368,7 +364,6 @@ class RoboFile extends \Robo\Tasks {
// PHPStan must be run out of main plugin directory to avoid its autoloading // PHPStan must be run out of main plugin directory to avoid its autoloading
// from vendor/autoload.php where some dev dependencies cause conflicts. // from vendor/autoload.php where some dev dependencies cause conflicts.
$dir = __DIR__; $dir = __DIR__;
$this->loadEnv();
return $this->collectionBuilder() return $this->collectionBuilder()
->taskExec('rm -rf ' . __DIR__ . '/vendor/goaop') ->taskExec('rm -rf ' . __DIR__ . '/vendor/goaop')
->taskExec('rm -rf ' . __DIR__ . '/vendor/nikic') ->taskExec('rm -rf ' . __DIR__ . '/vendor/nikic')
@@ -425,8 +420,6 @@ class RoboFile extends \Robo\Tasks {
} }
function svnPublish() { function svnPublish() {
$this->loadEnv();
$svn_dir = ".mp_svn"; $svn_dir = ".mp_svn";
$plugin_version = $this->getPluginVersion('mailpoet.php'); $plugin_version = $this->getPluginVersion('mailpoet.php');
$plugin_dist_name = 'mailpoet'; $plugin_dist_name = 'mailpoet';
@@ -550,11 +543,6 @@ class RoboFile extends \Robo\Tasks {
$this->say("IMPORTANT NOTES \n" . ($outputs[2] ?: 'none')); $this->say("IMPORTANT NOTES \n" . ($outputs[2] ?: 'none'));
} }
protected function loadEnv() {
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
}
protected function getPluginVersion($file) { protected function getPluginVersion($file) {
$data = file_get_contents($file); $data = file_get_contents($file);
preg_match('/^[ \t*]*Version:(.*)$/mi', $data, $m); preg_match('/^[ \t*]*Version:(.*)$/mi', $data, $m);
@@ -562,7 +550,6 @@ class RoboFile extends \Robo\Tasks {
} }
protected function getChangelogController() { protected function getChangelogController() {
$this->loadEnv();
return \MailPoetTasks\Release\ChangelogController::createWithJiraCredentials( return \MailPoetTasks\Release\ChangelogController::createWithJiraCredentials(
getenv('WP_JIRA_TOKEN'), getenv('WP_JIRA_TOKEN'),
getenv('WP_JIRA_USER'), getenv('WP_JIRA_USER'),
@@ -572,7 +559,6 @@ class RoboFile extends \Robo\Tasks {
} }
protected function getReleaseVersionController() { protected function getReleaseVersionController() {
$this->loadEnv();
return \MailPoetTasks\Release\ReleaseVersionController::createWithJiraCredentials( return \MailPoetTasks\Release\ReleaseVersionController::createWithJiraCredentials(
getenv('WP_JIRA_TOKEN'), getenv('WP_JIRA_TOKEN'),
getenv('WP_JIRA_USER'), getenv('WP_JIRA_USER'),
@@ -639,7 +625,6 @@ class RoboFile extends \Robo\Tasks {
} }
public function releaseDownloadZip() { public function releaseDownloadZip() {
$this->loadEnv();
$circleci_controller = $this->createCircleCiController(); $circleci_controller = $this->createCircleCiController();
$path = $circleci_controller->downloadLatestBuild(__DIR__ . '/mailpoet.zip'); $path = $circleci_controller->downloadLatestBuild(__DIR__ . '/mailpoet.zip');
$this->say('Release ZIP downloaded to: ' . $path); $this->say('Release ZIP downloaded to: ' . $path);
@@ -647,8 +632,6 @@ class RoboFile extends \Robo\Tasks {
} }
public function releasePublishGithub($version = null) { public function releasePublishGithub($version = null) {
$this->loadEnv();
$jira_controller = $this->createJiraController(); $jira_controller = $this->createJiraController();
$version = $jira_controller->getVersion($version); $version = $jira_controller->getVersion($version);
$changelog = $this->getChangelogController()->get($version['name']); $changelog = $this->getChangelogController()->get($version['name']);
@@ -661,7 +644,6 @@ class RoboFile extends \Robo\Tasks {
} }
public function releasePublishSlack($version = null) { public function releasePublishSlack($version = null) {
$this->loadEnv();
$jira_controller = $this->createJiraController(); $jira_controller = $this->createJiraController();
$version = $jira_controller->getVersion($version); $version = $jira_controller->getVersion($version);
$changelog = $this->getChangelogController()->get($version['name']); $changelog = $this->getChangelogController()->get($version['name']);
@@ -681,7 +663,6 @@ class RoboFile extends \Robo\Tasks {
} }
protected function createJiraController() { protected function createJiraController() {
$this->loadEnv();
return new \MailPoetTasks\Release\JiraController( return new \MailPoetTasks\Release\JiraController(
getenv('WP_JIRA_TOKEN'), getenv('WP_JIRA_TOKEN'),
getenv('WP_JIRA_USER'), getenv('WP_JIRA_USER'),
@@ -690,7 +671,6 @@ class RoboFile extends \Robo\Tasks {
} }
protected function createCircleCiController() { protected function createCircleCiController() {
$this->loadEnv();
return new \MailPoetTasks\Release\CircleCiController( return new \MailPoetTasks\Release\CircleCiController(
getenv('WP_CIRCLECI_USERNAME'), getenv('WP_CIRCLECI_USERNAME'),
getenv('WP_CIRCLECI_TOKEN'), getenv('WP_CIRCLECI_TOKEN'),
@@ -700,7 +680,6 @@ class RoboFile extends \Robo\Tasks {
} }
protected function createGitHubController() { protected function createGitHubController() {
$this->loadEnv();
return new \MailPoetTasks\Release\GitHubController( return new \MailPoetTasks\Release\GitHubController(
getenv('WP_GITHUB_USERNAME'), getenv('WP_GITHUB_USERNAME'),
getenv('WP_GITHUB_TOKEN'), getenv('WP_GITHUB_TOKEN'),