-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…itching #11 - create+switch default branch on release
- Loading branch information
Showing
19 changed files
with
973 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ jobs: | |
uses: "actions/checkout@v2" | ||
|
||
- name: "Release" | ||
uses: "laminas/automatic-releases@v1" | ||
uses: "laminas/automatic-releases@v1.0.0" | ||
with: | ||
command-name: "laminas:automatic-releases:release" | ||
env: | ||
|
@@ -27,11 +27,21 @@ jobs: | |
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} | ||
|
||
- name: "Create Merge-Up Pull Request" | ||
uses: "laminas/automatic-releases@v1" | ||
uses: "laminas/automatic-releases@v1.0.0" | ||
with: | ||
command-name: "laminas:automatic-releases:create-merge-up-pull-request" | ||
env: | ||
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} | ||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} | ||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} | ||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} | ||
|
||
- name: "Create and/or Switch to new Release Branch" | ||
uses: "laminas/[email protected]" | ||
with: | ||
command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" | ||
env: | ||
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} | ||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} | ||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} | ||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@manually-tested | ||
Feature: Default branch switching | ||
|
||
Scenario: A new minor branch is created and set as default branch on release | ||
Given following existing branches: | ||
| branch | | ||
| 1.0.x | | ||
| 1.1.x | | ||
| 1.2.x | | ||
And following open milestones: | ||
| name | | ||
| 1.2.0 | | ||
And the default branch is "1.0.x" | ||
When I close milestone "1.2.0" | ||
Then these should be the existing branches: | ||
| branch | | ||
| 1.0.x | | ||
| 1.1.x | | ||
| 1.2.x | | ||
| 1.3.x | | ||
And the default branch should be "1.3.x" | ||
|
||
Scenario: The latest pre-existing minor release branch is set as default branch on a successful release | ||
Given following existing branches: | ||
| branch | | ||
| 1.0.x | | ||
| 1.1.x | | ||
| 1.2.x | | ||
| 1.3.x | | ||
And following open milestones: | ||
| name | | ||
| 1.2.0 | | ||
And the default branch is "1.0.x" | ||
When I close milestone "1.2.0" | ||
Then these should be the existing branches: | ||
| branch | | ||
| 1.0.x | | ||
| 1.1.x | | ||
| 1.2.x | | ||
| 1.3.x | | ||
And the default branch should be "1.3.x" | ||
|
||
Scenario: A pre-existing branch of a greater major release is set as default branch on release | ||
Given following existing branches: | ||
| branch | | ||
| 1.0.x | | ||
| 1.1.x | | ||
| 1.2.x | | ||
| 2.0.x | | ||
| 2.1.x | | ||
And following open milestones: | ||
| name | | ||
| 1.2.0 | | ||
And the default branch is "1.0.x" | ||
When I close milestone "1.2.0" | ||
Then these should be the existing branches: | ||
| branch | | ||
| 1.0.x | | ||
| 1.1.x | | ||
| 1.2.x | | ||
| 2.0.x | | ||
| 2.1.x | | ||
And the default branch should be "2.1.x" | ||
|
||
Scenario: Branch is not switched when no minor release branch exists | ||
Given following existing branches: | ||
| branch | | ||
| foo | | ||
| bar | | ||
| master | | ||
| develop | | ||
And following open milestones: | ||
| name | | ||
| 1.2.0 | | ||
And the default branch is "develop" | ||
When I close milestone "1.2.0" | ||
Then these should be the existing branches: | ||
| branch | | ||
| foo | | ||
| bar | | ||
| master | | ||
| develop | | ||
And the default branch should be "develop" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,6 @@ | |
"mutators": { | ||
"@default": true | ||
}, | ||
"minMsi": 59, | ||
"minCoveredMsi": 59 | ||
"minMsi": 62, | ||
"minCoveredMsi": 62 | ||
} |
82 changes: 82 additions & 0 deletions
82
src/Application/Command/SwitchDefaultBranchToNextMinor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Application\Command; | ||
|
||
use Laminas\AutomaticReleases\Environment\Variables; | ||
use Laminas\AutomaticReleases\Git\Fetch; | ||
use Laminas\AutomaticReleases\Git\GetMergeTargetCandidateBranches; | ||
use Laminas\AutomaticReleases\Git\Push; | ||
use Laminas\AutomaticReleases\Github\Api\V3\SetDefaultBranch; | ||
use Laminas\AutomaticReleases\Github\Event\Factory\LoadCurrentGithubEvent; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class SwitchDefaultBranchToNextMinor extends Command | ||
{ | ||
private Variables $variables; | ||
private LoadCurrentGithubEvent $loadGithubEvent; | ||
private Fetch $fetch; | ||
private GetMergeTargetCandidateBranches $getMergeCandidates; | ||
private Push $push; | ||
private SetDefaultBranch $switchDefaultBranch; | ||
|
||
public function __construct( | ||
Variables $variables, | ||
LoadCurrentGithubEvent $loadGithubEvent, | ||
Fetch $fetch, | ||
GetMergeTargetCandidateBranches $getMergeCandidates, | ||
Push $push, | ||
SetDefaultBranch $switchDefaultBranch | ||
) { | ||
parent::__construct('laminas:automatic-releases:switch-default-branch-to-next-minor'); | ||
|
||
$this->variables = $variables; | ||
$this->loadGithubEvent = $loadGithubEvent; | ||
$this->fetch = $fetch; | ||
$this->getMergeCandidates = $getMergeCandidates; | ||
$this->push = $push; | ||
$this->switchDefaultBranch = $switchDefaultBranch; | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$event = $this->loadGithubEvent->__invoke(); | ||
$repositoryPath = $this->variables->githubWorkspacePath(); | ||
|
||
Assert::directory($repositoryPath . '/.git'); | ||
|
||
$this->fetch->__invoke( | ||
$event->repository() | ||
->uriWithTokenAuthentication($this->variables->githubToken()), | ||
$repositoryPath | ||
); | ||
|
||
$mergeCandidates = $this->getMergeCandidates->__invoke($repositoryPath); | ||
$releaseVersion = $event->version(); | ||
$newestBranch = $mergeCandidates->newestReleaseBranch(); | ||
|
||
if ($newestBranch === null) { | ||
$output->writeln('No stable branches found: cannot switch default branch'); | ||
|
||
return 0; | ||
} | ||
|
||
$nextDefaultBranch = $mergeCandidates->newestFutureReleaseBranchAfter($releaseVersion); | ||
|
||
if (! $mergeCandidates->contains($nextDefaultBranch)) { | ||
$this->push->__invoke( | ||
$repositoryPath, | ||
$newestBranch->name(), | ||
$nextDefaultBranch->name() | ||
); | ||
} | ||
|
||
$this->switchDefaultBranch->__invoke($event->repository(), $nextDefaultBranch); | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.