Skip to content

Commit

Permalink
Merge pull request #235 from creative-commoners/pulls/master/cms5-beta1
Browse files Browse the repository at this point in the history
FIX Changes for CMS 5 release
  • Loading branch information
GuySartorelli authored Feb 27, 2023
2 parents f854727 + c7dfc67 commit 5682d6d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@
"php-http/message": "<1.13.0"
},
"prefer-stable": true,
"minimum-stability": "dev"
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
8 changes: 5 additions & 3 deletions src/Model/Modules/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public function saveCachedPlan(LibraryRelease $plan)
* @return LibraryRelease[]
* @throws Exception
*/
protected function unserialisePlan($serialisedPlan)
protected function unserialisePlan($serialisedPlan, ?LibraryRelease $parentRelease = null)
{
$releases = [];
foreach ($serialisedPlan as $name => $data) {
Expand All @@ -1032,6 +1032,9 @@ protected function unserialisePlan($serialisedPlan)
}
$version = new Version($data['Version']);
$libraryRelease = new LibraryRelease($library, $version);
if ($parentRelease) {
$libraryRelease->setParentRelease($parentRelease);
}

// Set the previous version if specified
if (!empty($data['PriorVersion'])) {
Expand All @@ -1041,14 +1044,13 @@ protected function unserialisePlan($serialisedPlan)

// Merge with unserialised children
if (!empty($data['Items'])) {
$libraryRelease->addItems($this->unserialisePlan($data['Items']));
$libraryRelease->addItems($this->unserialisePlan($data['Items'], $libraryRelease));
}

// Set branching
if (!empty($data['Branching'])) {
$libraryRelease->setBranching($data['Branching']);
}

$releases[$name] = $libraryRelease;
}
return $releases;
Expand Down
33 changes: 31 additions & 2 deletions src/Model/Release/LibraryRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,40 @@ class LibraryRelease
*/
private $childPriorVersions;

private ?LibraryRelease $parentRelease = null;

/**
* LibraryRelease constructor.
*
* @param Library $library
* @param Version $version
* @param Version|null $priorVersion
* @param LibraryRelease|null $parentRelease
*/
public function __construct(Library $library, Version $version, Version $priorVersion = null)
{
public function __construct(
Library $library,
Version $version,
Version $priorVersion = null,
LibraryRelease $parentRelease = null
) {
$this->setLibrary($library);
$this->setVersion($version);
if ($priorVersion) {
$this->setPriorVersion($priorVersion);
}
if ($parentRelease) {
$this->setParentRelease($parentRelease);
}
}

public function getParentRelease(): ?LibraryRelease
{
return $this->parentRelease;
}

public function setParentRelease(LibraryRelease $release)
{
$this->parentRelease = $release;
}

/**
Expand Down Expand Up @@ -354,4 +374,13 @@ public function isOnCorrectMinorReleaseBranch(): bool
}
return $matches[1] == $this->getLibrary()->getBranch();
}

public function getRootLibraryRelease(): LibraryRelease
{
$parentRelease = $this->getParentRelease();
if ($parentRelease) {
return $parentRelease->getRootLibraryRelease();
}
return $this;
}
}
3 changes: 0 additions & 3 deletions src/Steps/Release/CreateChangelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ protected function getChangelogLibrary(

// Check if this release has a historic tag.
$childReleaseName = $childNewReleaseLibrary->getName();
if (empty($pastComposer['require'][$childReleaseName])) {
continue;
}

// Use an explicitly specified previous version
$childHistoricVersion = $childNewRelease->getPriorVersion(false);
Expand Down
10 changes: 5 additions & 5 deletions src/Steps/Release/PlanRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected function generateUpgradeRelease(LibraryRelease $parentRelease, Library
. $candidateVersion->getValue() . " without a new release"
);
}
return new LibraryRelease($childModule, $candidateVersion, $priorRelease);
return new LibraryRelease($childModule, $candidateVersion, $priorRelease, $parentRelease);
}

// Get all stable tags that match the given composer constraint
Expand All @@ -222,7 +222,7 @@ protected function generateUpgradeRelease(LibraryRelease $parentRelease, Library
// Upgrade to highest version
$tags = Version::sort($candidates, 'descending');
$candidateVersion = reset($tags);
return new LibraryRelease($childModule, $candidateVersion, $priorRelease);
return new LibraryRelease($childModule, $candidateVersion, $priorRelease, $parentRelease);
}

/**
Expand Down Expand Up @@ -252,11 +252,11 @@ protected function proposeNewReleaseVersion(LibraryRelease $parentRelease, Libra

// If this is already tagged, just upgrade without a new release
if (array_key_exists($candidateVersion->getValue(), $tags)) {
return new LibraryRelease($childModule, $candidateVersion, $priorRelease);
return new LibraryRelease($childModule, $candidateVersion, $priorRelease, $parentRelease);
}

// Build release
return new LibraryRelease($childModule, $candidateVersion, $priorRelease);
return new LibraryRelease($childModule, $candidateVersion, $priorRelease, $parentRelease);
}

// Get stability to use for the new tag
Expand Down Expand Up @@ -287,7 +287,7 @@ protected function proposeNewReleaseVersion(LibraryRelease $parentRelease, Libra
}

// Report new tag
return new LibraryRelease($childModule, $version, $priorRelease);
return new LibraryRelease($childModule, $version, $priorRelease, $parentRelease);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Steps/Release/PublishRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ protected function releaseLibrary(OutputInterface $output, LibraryRelease $relea
// Step 2: Tag and push this tag
$this->publishTag($output, $releasePlanNode);

// Step 3: Create release in github
$this->createGitHubRelease($output, $releasePlanNode);

// Step 4: Rewrite composer.json to destabilise requirements
// Step 3: Rewrite composer.json to destabilise requirements
ConstraintStabiliser::destabiliseConstraints($output, $releasePlanNode, false);

// Step 5: Push development branch to origin
// Step 4: Push development branch to origin
$this->log($output, "Pushing branch <info>{$branch}</info>");
$library->pushTo('origin');

// Step 5: Create release in github
// These needs to be last to ensure the branch has been pushed to github
$this->createGitHubRelease($output, $releasePlanNode);
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/Utility/ConstraintStabiliser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public static function stabiliseConstraints(OutputInterface $output, LibraryRele
$parentLibrary = $releasePlanNode->getLibrary();
$originalData = $composerData = $parentLibrary->getComposerData();
$constraintType = $parentLibrary->getDependencyConstraint();
$parentName = $parentLibrary->getName();

// Rewrite all dependencies.
// Note: rewrite dependencies even if non-exclusive children, so do a global search
// through the entire tree of the plan to get the new tag
$items = $releasePlanNode->getAllItems();
foreach ($items as $item) {
foreach ($releasePlanNode->getRootLibraryRelease()->getAllItems() as $item) {
$childName = $item->getLibrary()->getName();

// Ensure this library is allowed to release this dependency (even if shared)
if (!isset($composerData['require'][$childName]) || !$parentLibrary->isChildLibrary($childName)) {
if (!isset($composerData['require'][$childName])) {
continue;
}

Expand Down Expand Up @@ -95,12 +95,11 @@ public static function destabiliseConstraints(
// Rewrite all dependencies.
// Note: only rewrite dependencies for anything that was included in the release.
// This mirrors functionality in PublishRelease::stabiliseConstraints()
$items = $releasePlanNode->getAllItems();
foreach ($items as $item) {
foreach ($releasePlanNode->getRootLibraryRelease()->getAllItems() as $item) {
$childName = $item->getLibrary()->getName();

// Ensure this library is allowed to release this dependency (even if shared)
if (!isset($composerData['require'][$childName]) || !$parentLibrary->isChildLibrary($childName)) {
if (!isset($composerData['require'][$childName])) {
continue;
}

Expand Down

0 comments on commit 5682d6d

Please sign in to comment.