Skip to content

Commit

Permalink
Allow releases based on relative versions
Browse files Browse the repository at this point in the history
It’s now possible to use ‘major’ instead of 2.0 (when 1.0 or 1.5 exists)
  • Loading branch information
sstok committed Feb 11, 2017
1 parent 0ad43b2 commit 3aeaca3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Cli/Handler/ReleaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ private function validateBranchCompatibility(string $branch, Version $version)

private function validateVersion(string $version): Version
{
$version = Version::fromString($version);
if (in_array(strtolower($version), ['alpha', 'beta', 'rc', 'stable', 'major', 'minor', 'patch'], true)) {
$version = Version::fromString($this->git->getLastTagOnBranch())->increase(strtolower($version));
} else {
$version = Version::fromString($version);
}

if (!$this->io->isInteractive()) {
return $version;
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/HubKitApplicationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function (PreHandleEvent $event) {

->beginCommand('release')
->setDescription('Make a new release for the current branch')
->addArgument('version', Argument::REQUIRED | Argument::STRING, 'Version to make')
->addArgument('version', Argument::REQUIRED | Argument::STRING, 'Version to make (supports relative, eg. minor, alpha, ...)')
->addOption('all-categories', null, Option::NO_VALUE | Option::BOOLEAN, 'Show all categories (including empty)')
->addOption('no-edit', null, Option::NO_VALUE | Option::BOOLEAN, 'Don\'t open the editor for editing the release page')
->addOption('pre-release', null, Option::NO_VALUE | Option::BOOLEAN, 'Mark as pre-release (not production ready)')
Expand Down
7 changes: 6 additions & 1 deletion src/Helper/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ public function increase(string $stability): Version
return $this->increaseStable();

default:
throw new \InvalidArgumentException('Unknown or unsupported stability provided: '.$stability);
throw new \InvalidArgumentException(
sprintf(
'Unknown stability "%s", accepts "%s" '.$stability,
implode('", "', ['alpha', 'beta', 'rc', 'stable', 'major', 'minor', 'patch'])
)
);
}
}

Expand Down
26 changes: 26 additions & 0 deletions tests/Handler/ReleaseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,32 @@ public function it_asks_confirmation_when_target_branch_has_a_mismatch_and_abort
$this->executeHandler($args); // default answer is no
}

/** @test */
public function it_creates_a_new_release_with_a_relative_version()
{
$this->expectTags(['0.1.0', '1.0.0', '2.0.0']);
$this->git->getLastTagOnBranch()->willReturn('2.5.0');
$this->expectMatchingVersionBranchNotExists('3.0');

$this->git->getLogBetweenCommits('2.5.0', 'master')->willReturn(self::COMMITS);

$this->expectEditorReturns("### Added\n- Introduce a new API for ValuesBag", 'Drop support for older PHP versions');

$url = $this->expectTagAndGitHubRelease('3.0.0', 'Drop support for older PHP versions');

$args = $this->getArgs('major');
$this->executeHandler($args);

$this->assertOutputMatches(
[
'Preparing release 3.0.0 (target branch master)',
'Please wait...',
'Successfully released 3.0.0',
$url,
]
);
}

private function getArgs(string $version): Args
{
$format = ArgsFormat::build()
Expand Down

0 comments on commit 3aeaca3

Please sign in to comment.