Skip to content

Commit

Permalink
TASK: Support pre-release tags in next release tag calculation
Browse files Browse the repository at this point in the history
The calculation of the next version with a pre-release suffix in the
current version failed, e.g. the calculation of the next patch version
1.2.2 for the current pre-release version 1.2.1-p1.
  • Loading branch information
alexander-nitsche committed Jun 20, 2023
1 parent df9b4be commit c6de6c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build/classes/SemanticVersioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class SemanticVersioning
public function getNextReleaseTag($tag, $releaseType)
{
$tagPrefix = substr($tag, 0, strcspn($tag, '0123456789'));
$tagVersion = substr($tag, strlen($tagPrefix));
if (($tagSuffixPos = strpos($tag, '-')) !== false) {
$tagVersion = substr($tag, strlen($tagPrefix), $tagSuffixPos);
} else {
$tagVersion = substr($tag, strlen($tagPrefix));
}
$tagVersionParts = explode('.', $tagVersion);
$releaseVersionParts = $tagVersionParts + [0, 0, 0];
$releaseVersionParts = array_slice($releaseVersionParts, 0, $releaseType + 1);
Expand Down
1 change: 1 addition & 0 deletions tests/build/SemanticVersioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function getNextReleaseTagDataProvider()
['1', SemanticVersioning::MINOR_RELEASE, '1.1'],
['1', SemanticVersioning::MAJOR_RELEASE, '2'],
['v1.0.1', SemanticVersioning::PATCH_RELEASE, 'v1.0.2'],
['1.0.1-p1', SemanticVersioning::PATCH_RELEASE, '1.0.2'],
];
}

Expand Down

0 comments on commit c6de6c9

Please sign in to comment.