You are here

protected function ComposerProjectTemplatesTest::getCoreStability in Drupal 9

Returns the stability of the current core version.

If the current core version is a tagged release (not a "-dev" version), this returns the stability of that version.

If the current core version is a "-dev" version, but not a "x.y.0-dev" version, this returns "stable", because it means that the corresponding "x.y.0" has already been released, and only stable changes are now permitted on the branch.

If the current core version is a "x.y.0-dev" version, then this returns the stability of the latest tag that matches "x.y.0-*". For example, if we've already released "x.y.0-alpha1" but have not yet released "x.y.0-beta1", then the current stability is "alpha". If there aren't any matching tags, this returns "dev", because it means that an "alpha1" has not yet been released.

Return value

string One of: "dev", "alpha", "beta", "RC", "stable".

1 call to ComposerProjectTemplatesTest::getCoreStability()
ComposerProjectTemplatesTest::testMinimumStabilityStrictness in core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
Make sure that static::MINIMUM_STABILITY is sufficiently strict.

File

core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php, line 403

Class

ComposerProjectTemplatesTest
Demonstrate that Composer project templates are buildable as patched.

Namespace

Drupal\BuildTests\Composer\Template

Code

protected function getCoreStability() {
  $version = \Drupal::VERSION;
  $stability = VersionParser::parseStability($version);
  if ($stability === 'dev') {

    // Strip off "-dev";
    $version_towards = substr($version, 0, -4);
    if (substr($version_towards, -2) !== '.0') {

      // If the current version is developing towards an x.y.z release where
      // z is not 0, it means that the x.y.0 has already been released, and
      // only stable changes are permitted on the branch.
      $stability = 'stable';
    }
    else {

      // If the current version is developing towards an x.y.0 release, there
      // might be tagged pre-releases. "git describe" identifies the latest
      // one.
      $root = $this
        ->getDrupalRoot();
      $process = $this
        ->executeCommand("git -C \"{$root}\" describe --abbrev=0 --match=\"{$version_towards}-*\"");

      // If there aren't any tagged pre-releases for this version yet, return
      // 'dev'. Ensure that any other error from "git describe" causes a test
      // failure.
      if (!$process
        ->isSuccessful()) {
        $this
          ->assertErrorOutputContains('No names found, cannot describe anything.');
        return 'dev';
      }

      // We expect a pre-release, because:
      // - A tag should not be of "dev" stability.
      // - After a "stable" release is made, \Drupal::VERSION is incremented,
      //   so there should not be a stable release on that new version.
      $stability = VersionParser::parseStability(trim($process
        ->getOutput()));
      $this
        ->assertContains($stability, [
        'alpha',
        'beta',
        'RC',
      ]);
    }
  }
  return $stability;
}