Skip to content

Commit

Permalink
SDK-5752: Feature dev-master switch for RG (#312)
Browse files Browse the repository at this point in the history
* SDK-5752: Feature dev-master switch for RG

* SDK-5752: Adjusted test cases

* SDK-5752: Adjusted test cases

* SDK-5752: Updated README
  • Loading branch information
vol4onok authored Jan 18, 2024
1 parent 093ac1e commit c947446
Show file tree
Hide file tree
Showing 25 changed files with 547 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export UPDATE_MINIMUM_DEPENDENCIES_ENABLED=true

## Enable update features to dev-master fixer
* Turn on internal specific behavior to update features to dev-master if it's blocker.
* Turn on internal specific behavior to update features to dev-master.
```bash
export UPDATE_FEATURES_TO_DEV_MASTER=true
```
Expand Down
23 changes: 23 additions & 0 deletions src/ReleaseApp/Domain/Entities/UpgradeInstructionModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class UpgradeInstructionModule
*/
protected const TYPE_KEY = 'type';

/**
* @var string
*/
protected const FEATURE_PACKAGES_KEY = 'feature_packages';

/**
* @var array<mixed>
*/
Expand Down Expand Up @@ -98,4 +103,22 @@ public function setType(string $type): void
{
$this->body[static::TYPE_KEY] = $type;
}

/**
* @return array<string, string>
*/
public function getFeaturePackages(): array
{
return $this->body[static::FEATURE_PACKAGES_KEY] ?? [];
}

/**
* @param string $type
*
* @return void
*/
public function setFeaturePackages(string $type): void
{
$this->body[static::FEATURE_PACKAGES_KEY] = $type;
}
}
17 changes: 16 additions & 1 deletion src/ReleaseApp/Infrastructure/Shared/Dto/ModuleDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ class ModuleDto
*/
protected string $versionType;

/**
* @var array<string, string>
*/
protected array $featurePackages;

/**
* @param string $name
* @param string $version
* @param string $versionType
* @param array<string, string> $featurePackages
*/
public function __construct(string $name, string $version, string $versionType)
public function __construct(string $name, string $version, string $versionType = ReleaseAppConstant::MODULE_TYPE_MINOR, array $featurePackages = [])
{
$this->name = $name;
$this->version = $version;
$this->versionType = $versionType;
$this->featurePackages = $featurePackages;
}

/**
Expand All @@ -57,6 +64,14 @@ public function getVersion(): string
return $this->version;
}

/**
* @return array<string, string>
*/
public function getFeaturePackages(): array
{
return $this->featurePackages;
}

/**
* @return string
*/
Expand Down
26 changes: 26 additions & 0 deletions src/ReleaseApp/Infrastructure/Shared/Dto/ReleaseGroupDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ class ReleaseGroupDto
*/
protected ModuleDtoCollection $backportModuleCollection;

/**
* @var \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection
*/
protected ModuleDtoCollection $featurePackages;

/**
* @param int $id
* @param string $name
* @param \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection $moduleCollection
* @param \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection $backportModuleCollection
* @param \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection $featurePackages
* @param \DateTimeInterface $released
* @param bool $containsProjectChanges
* @param string $link
Expand All @@ -103,6 +109,7 @@ public function __construct(
string $name,
ModuleDtoCollection $moduleCollection,
ModuleDtoCollection $backportModuleCollection,
ModuleDtoCollection $featurePackages,
DateTimeInterface $released,
bool $containsProjectChanges,
string $link,
Expand All @@ -118,6 +125,7 @@ public function __construct(
$this->link = $link;
$this->moduleCollection = $moduleCollection;
$this->backportModuleCollection = $backportModuleCollection;
$this->featurePackages = $featurePackages;
$this->containsProjectChanges = $containsProjectChanges;
$this->hasConflict = $hasConflict;
$this->rating = $rating;
Expand Down Expand Up @@ -152,6 +160,24 @@ public function setModuleCollection(ModuleDtoCollection $moduleCollection): void
$this->moduleCollection = $moduleCollection;
}

/**
* @return \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection
*/
public function getFeaturePackages(): ModuleDtoCollection
{
return $this->featurePackages;
}

/**
* @param \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection $featurePackages
*
* @return void
*/
public function setFeaturePackages(ModuleDtoCollection $featurePackages): void
{
$this->featurePackages = $featurePackages;
}

/**
* @return \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected function mapReleaseGroupDto(UpgradeInstructionsReleaseGroup $releaseGr
$releaseGroup->getName(),
$this->buildModuleTransferCollection($releaseGroup),
$this->buildBackportModuleTransferCollection($releaseGroup),
new ModuleDtoCollection(),
$releaseGroup->getReleased(),
$releaseGroup->hasProjectChanges(),
$this->getReleaseGroupLink($releaseGroup->getId()),
Expand Down Expand Up @@ -105,7 +106,7 @@ protected function buildModuleTransferCollection(UpgradeInstructionsReleaseGroup

$dataProviderModuleCollection = new ModuleDtoCollection();
foreach ($releaseGroupModuleCollection->toArray() as $module) {
$dataProviderModule = new ModuleDto($module->getName(), $module->getVersion(), $module->getType());
$dataProviderModule = new ModuleDto($module->getName(), $module->getVersion(), $module->getType(), $module->getFeaturePackages());
$dataProviderModuleCollection->add($dataProviderModule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public function isReportingEnabled(): bool;
*/
public function isPackageUpgradeOnly(): bool;

/**
* Specification:
* - Defines the specific release group id.
*
* @return int|null
*/
public function getReleaseGroupId(): ?int;

/**
* Specification:
* - Defines the report request auth token.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace Upgrade\Application\Strategy\ReleaseApp\Expander;

use ReleaseApp\Infrastructure\Shared\Dto\ModuleDto;
use ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Upgrade\Application\Adapter\PackageManagerAdapterInterface;
use Upgrade\Application\Provider\ConfigurationProviderInterface;
use Upgrade\Application\Strategy\ReleaseApp\Processor\Event\ReleaseGroupProcessorEvent;

class FeatureDevMasterPackageExpanderEventSubscriber implements EventSubscriberInterface
{
/**
* @var string
*/
protected const DEV_MASTER_PREFIX = 'dev-master';

/**
* @var \Upgrade\Application\Provider\ConfigurationProviderInterface
*/
protected ConfigurationProviderInterface $configurationProvider;

/**
* @var \Upgrade\Application\Adapter\PackageManagerAdapterInterface
*/
protected PackageManagerAdapterInterface $packageManager;

/**
* @var bool
*/
protected bool $isFeatureToDevMasterEnabled;

/**
* @param \Upgrade\Application\Provider\ConfigurationProviderInterface $configurationProvider
* @param \Upgrade\Application\Adapter\PackageManagerAdapterInterface $packageManager
* @param bool $isFeatureToDevMasterEnabled
*/
public function __construct(
ConfigurationProviderInterface $configurationProvider,
PackageManagerAdapterInterface $packageManager,
bool $isFeatureToDevMasterEnabled = false
) {
$this->configurationProvider = $configurationProvider;
$this->packageManager = $packageManager;
$this->isFeatureToDevMasterEnabled = $isFeatureToDevMasterEnabled;
}

/**
* @return array<string, string>
*/
public static function getSubscribedEvents(): array
{
return [
ReleaseGroupProcessorEvent::PRE_REQUIRE => 'onPreRequire',
];
}

/**
* @param \Upgrade\Application\Strategy\ReleaseApp\Processor\Event\ReleaseGroupProcessorEvent $event
*
* @return void
*/
public function onPreRequire(ReleaseGroupProcessorEvent $event): void
{
if (!$this->configurationProvider->getReleaseGroupId() || !$this->isFeatureToDevMasterEnabled) {
return;
}

$currentReleaseGroup = $event->getStepsExecutionDto()->getCurrentReleaseGroup();
if ($currentReleaseGroup === null) {
return;
}

$featurePackages = $this->getFeaturePackagesForUpdate($currentReleaseGroup);

foreach ($featurePackages as $featurePackage => $version) {
$currentReleaseGroup->getFeaturePackages()->add(new ModuleDto($featurePackage, $version));
}
}

/**
* @param \ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto $currentReleaseGroup
*
* @return array<string, string>
*/
protected function getFeaturePackagesForUpdate(ReleaseGroupDto $currentReleaseGroup): array
{
$featurePackages = $this->getFeaturePackages($currentReleaseGroup);
$composerJson = $this->packageManager->getComposerJsonFile();
$packages = array_merge($composerJson['require'], $composerJson['require-dev'] ?? []);
$featurePackagesForUpdate = [];
foreach ($featurePackages as $featurePackage => $version) {
if (!isset($packages[$featurePackage]) || strpos($packages[$featurePackage], static::DEV_MASTER_PREFIX) !== false) {
continue;
}
$featurePackagesForUpdate[$featurePackage] = $version;
}

return $featurePackagesForUpdate;
}

/**
* @param \ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto $currentReleaseGroup
*
* @return array<string, string>
*/
protected function getFeaturePackages(ReleaseGroupDto $currentReleaseGroup): array
{
$featurePackages = [];

foreach ($currentReleaseGroup->getModuleCollection()->toArray() as $moduleDto) {
foreach ($moduleDto->getFeaturePackages() as $package => $version) {
$featurePackages[$package] = $version;
}
}

return $featurePackages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,42 @@ public function __construct(ModuleFetcher $moduleFetcher, LoggerInterface $logge
*/
public function upgrade(ReleaseGroupDto $releaseGroup): PackageManagerResponseDto
{
$response = $this->moduleFetcher->require($releaseGroup->getModuleCollection());
$alternativeRequireModuleCollections = $this->getAlternativeRequireModuleCollections($releaseGroup);
$alternativeRequireModuleCollections[] = $releaseGroup->getModuleCollection();

foreach ($alternativeRequireModuleCollections as $alternativeRequireModuleCollection) {
$response = $this->moduleFetcher->require($alternativeRequireModuleCollection);
if ($response->isSuccessful()) {
break;
}
}

if (!$response->isSuccessful()) {
$response = $this->runWithFixer($releaseGroup, $response);
}

return $response;
}

/**
* @param \ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto $releaseGroup
*
* @return array<\ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection>
*/
protected function getAlternativeRequireModuleCollections(ReleaseGroupDto $releaseGroup): array
{
$moduleAlternativeCollection = [];
if ($releaseGroup->getFeaturePackages()->count()) {
$packageCollection = clone $releaseGroup->getModuleCollection();
foreach ($releaseGroup->getFeaturePackages()->toArray() as $package) {
$packageCollection->add($package);
}
$moduleAlternativeCollection[] = $packageCollection;
}

return $moduleAlternativeCollection;
}

/**
* @param \ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto $releaseGroup
* @param \Upgrade\Application\Dto\PackageManagerResponseDto $response
Expand Down
Loading

0 comments on commit c947446

Please sign in to comment.