Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nikolaposa/version to version 4 #73

Merged
merged 8 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ cache:
- $HOME/.composer/cache/files

addons:
apt:
packages:
- jq
apt:
packages:
- jq

env:
global:
Expand All @@ -20,11 +20,10 @@ matrix:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.1
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"

# Test the latest stable release
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
Expand Down Expand Up @@ -69,8 +68,8 @@ script:
- ./vendor/bin/phpunit ${PHPUNIT_FLAGS}

after_script:
- |
if [ "$COVERAGE" = true ] && [ -e coverage.clover ]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
- |
if [ "$COVERAGE" = true ] && [ -e coverage.clover ]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
15 changes: 6 additions & 9 deletions Command/VersionBumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Formatter: <comment>%s</comment>', 'Not available'));
}

// Used for BC compatibility with nikolaposa/version 2.2
$isNikolaposaVersion2 = method_exists($version, 'withMajorIncremented');

$incrementMajor = (int) $input->getOption('major');
if ($incrementMajor > 0) {
for ($i = 0; $i < $incrementMajor; $i++) {
$version = $isNikolaposaVersion2 ? $version->withMajorIncremented() : $version->incrementMajor();
$version = $version->incrementMajor();
}
}

$incrementMinor = (int) $input->getOption('minor');
if ($incrementMinor > 0) {
for ($i = 0; $i < $incrementMinor; $i++) {
$version = $isNikolaposaVersion2 ? $version->withMinorIncremented() : $version->incrementMinor();
$version = $version->incrementMinor();
}
}

$incrementPatch = (int) $input->getOption('patch');
if ($incrementPatch > 0) {
for ($i = 0; $i < $incrementPatch; $i++) {
$version = $isNikolaposaVersion2 ? $version->withPatchIncremented() : $version->incrementPatch();
$version = $version->incrementPatch();
}
}

$preRelease = $input->getOption('prerelease');
if (!empty($preRelease)) {
if (in_array(null, $preRelease, true)) {
$preRelease = $isNikolaposaVersion2 ? array() : null;
$preRelease = null;
} else {
$preRelease = implode('.', $preRelease);
}
Expand All @@ -110,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$build = $input->getOption('build');
if (!empty($build)) {
if (in_array(null, $build, true)) {
$build = $isNikolaposaVersion2 ? array() : null;
$build = null;
} else {
$build = implode('.', $build);
}
Expand All @@ -120,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$currentVersion = $this->manager->getVersion();
if ((string) $currentVersion === (string) $version) {
$version = $isNikolaposaVersion2 ? $version->withPatchIncremented() : $version->incrementPatch();
$version = $version->incrementPatch();
}

$output->writeln(sprintf('Current version: <info>%s</info>', $currentVersion));
Expand Down
47 changes: 22 additions & 25 deletions Formatter/GitDescribeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,41 @@ class GitDescribeFormatter implements FormatterInterface
* @param Version $version
* @return Version
*/
public function format(Version $version)
public function format(Version $version): Version
{
if (preg_match('/^(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $version->getPreRelease(), $matches)) {
if ((int) $matches[1] != 0) {
// we are not on TAG commit, add "dev" and git commit hash as pre release part
$version = $version->withPreRelease('dev.' . $matches[2]);
$preRelease = $version->getPreRelease();
if (null === $preRelease) {
return $version;
}

if (preg_match('/^(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $preRelease->toString(), $matches)) {
if ('0' !== $matches[1]) {
$withPreRelease = sprintf('dev.%s', $matches[2]);
} else {
$version = $this->clearPreRelease($version);
$withPreRelease = null;
}
}

if (preg_match('/^(.*)-(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $version->getPreRelease(), $matches)) {
if ((int) $matches[2] != 0) {
// we are not on TAG commit, add "dev" and git commit hash as pre release part
$version = $version->withPreRelease($withPreRelease);
} elseif (preg_match('/^(.*)-(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $preRelease->toString(), $matches)) {
if ('0' !== $matches[2]) {
// if we are not on TAG commit, add "dev" and git commit hash as pre release part
if (empty($matches[1])) {
$version = $version->withPreRelease('dev.' . $matches[3]);
$withPreRelease = sprintf('dev.%s', $matches[3]);
} else {
$version = $version->withPreRelease(trim($matches[1], '-') . '.dev.' . $matches[3]);
$withPreRelease = sprintf('%s.dev.%s', trim($matches[1], '-'), $matches[3]);
}

} else {
if (empty($matches[1])) {
$version = $this->clearPreRelease($version);
if ('' === $matches[1]) {
$withPreRelease = null;
} else {
$version = $version->withPreRelease(trim($matches[1], '-'));
$withPreRelease = trim($matches[1], '-');
}
}

$version = $version->withPreRelease($withPreRelease);
}

return $version;
}

private function clearPreRelease(Version $version): Version
{
if (class_exists(\Version\Metadata\PreRelease::class)) {
// we cannot use null with nikolaposa/version 2.2
return $version->withPreRelease(\Version\Metadata\PreRelease::createEmpty());
} else {
return $version->withPreRelease(null);
}
}
}
4 changes: 2 additions & 2 deletions Service/VersionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Shivas\VersioningBundle\Provider\ProviderInterface;
use Shivas\VersioningBundle\Writer\WriterInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Version\Exception\InvalidVersionStringException;
use Version\Exception\InvalidVersionString;
use Version\Version;

/**
Expand Down Expand Up @@ -178,7 +178,7 @@ public function getVersionFromProvider()
}

return $version;
} catch (InvalidVersionStringException $e) {
} catch (InvalidVersionString $e) {
throw new RuntimeException(get_class($provider) . ' returned an invalid version');
}
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"wiki": "https://github.com/shivas/versioning-bundle/wiki"
},
"require": {
"php": "^7.1",
"nikolaposa/version": "^2.2 || ^3",
"php": "^7.2",
"nikolaposa/version": "^4",
"symfony/console": "^3.4 || ^4 || ^5",
"symfony/framework-bundle": "^3.4 || ^4 || ^5",
"symfony/process": "^3.4 || ^4 || ^5"
Expand Down