You are here

public function RoboFile::releasePublish in Panopoly 7

Release Stage 3: Publishes new releases on Drupal.org.

@option string $username The Drupal.org username. @option string $password The Drupal.org password. @option string $totp-secret The TOTP secret, if your Drupal.org account uses TFA. @option bool $skip-checkout-repos Skip checking out the release repos if they are already up-to-date. @option bool $no-stop Don't stop Mink after the release is done or errors out. @option string $wd-host The Webdriver (aka Selenium) end-point to connect to.

Parameters

string $old_version: The previous version.

string $new_version: The new version.

Return value

$this|\Robo\Collection\CollectionBuilder

Throws

\Exception

1 call to RoboFile::releasePublish()
RoboFile::release in ./RoboFile.php
Runs all 3 stages of the release process in order.

File

./RoboFile.php, line 930

Class

RoboFile
This is project's console commands configuration for Robo task runner.

Code

public function releasePublish($old_version, $new_version, $opts = [
  'username' => NULL,
  'password' => NULL,
  'totp-secret' => NULL,
  'skip-checkout-repos' => FALSE,
  'no-stop' => FALSE,
  'wd-host' => 'http://chromedriver:4444/wd/hub',
]) {
  if (empty($opts['username']) || empty($opts['password'])) {
    throw new \Exception("Must pass in --username and --pasword");
  }
  $branch = static::PANOPOLY_DEFAULT_BRANCH;
  list($drupal_major, ) = explode('-', $branch);

  /** @var \Robo\Collection\CollectionBuilder|$this $collection */
  $collection = $this
    ->collectionBuilder();

  // @todo Make this more configurable.
  $session = new \Behat\Mink\Session(new \Behat\Mink\Driver\Selenium2Driver('chrome', [
    'chrome' => [
      'switches' => [
        //'--headless',
        '--disable-gpu',
      ],
      // This hides the fact that Chrome is being driven by automation.
      'excludeSwitches' => [
        'enable-automation',
      ],
    ],
  ], $opts['wd-host']));
  if (!$opts['no-stop']) {
    $collection
      ->completionCode(function () use ($session) {
      $session
        ->stop();
    });
  }
  $panopoly_features = array_merge([
    'panopoly',
  ], $this
    ->getPanopolyFeatures());
  foreach ($panopoly_features as $index => $panopoly_feature) {
    $panopoly_feature_releases = $this
      ->runDrush("pm-releases {$panopoly_feature}-{$drupal_major}")
      ->getOutput();
    if (strpos($panopoly_feature_releases, $new_version) !== FALSE) {
      $this
        ->say("{$panopoly_feature} {$new_version} already released - skipping");
      unset($panopoly_features[$index]);
    }
  }
  if (empty($panopoly_features)) {
    $this
      ->say("Nothing to release!");
    return $collection;
  }
  if (!$opts['skip-checkout-repos']) {
    $collection
      ->addTask($this
      ->checkoutManyreposForRelease($branch));
  }
  $collection
    ->addCode(function () use ($session, $opts) {
    $session
      ->start();
    $session
      ->visit('https://drupal.org/user/login');
    $this
      ->submitForm($session
      ->getPage(), 'user-login', [
      'name' => $opts['username'],
      'pass' => $opts['password'],
    ], 'edit-submit');
    if (!empty($opts['totp-secret'])) {
      $this
        ->submitForm($session
        ->getPage(), 'tfa-form', [
        'code' => \OTPHP\TOTP::create($opts['totp-secret'])
          ->now(),
      ], 'edit-login');
    }
  });
  foreach ($panopoly_features as $panopoly_feature) {
    $collection
      ->addCode(function () use ($session, $panopoly_feature, $old_version, $new_version) {
      if ($panopoly_feature === 'panopoly') {
        $panopoly_feature_release_path = NULL;
      }
      else {
        $panopoly_feature_release_path = "release/{$panopoly_feature}";
      }
      $release_notes = $this
        ->runDrush("rn {$old_version} {$new_version} 2>/dev/null", $panopoly_feature_release_path)
        ->getOutput();
      $this
        ->createRelease($session, $panopoly_feature, $new_version, $release_notes);
    });
  }
  return $collection;
}