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 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/bin/
/composer.lock
/vendor/
/docker-compose.yml
dontub marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 12 additions & 11 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 @@ -18,13 +18,14 @@ matrix:
fast_finish: true
include:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.4
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.1
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
dontub marked this conversation as resolved.
Show resolved Hide resolved

# Test the latest stable release
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
Expand Down Expand Up @@ -69,8 +70,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
46 changes: 16 additions & 30 deletions Formatter/GitDescribeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Shivas\VersioningBundle\Formatter;

use Version\Extension\PreRelease;
use Version\Version;

/**
Expand All @@ -15,44 +16,29 @@ 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]);
} else {
$version = $this->clearPreRelease($version);
}
$preRelease = $version->getPreRelease();
if (!$preRelease instanceof PreRelease) {
kevin-lot marked this conversation as resolved.
Show resolved Hide resolved
return $version;
}

if (preg_match('/^(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $preRelease->toString(), $matches)) {
$withPreRelease = (int) $matches[1] != 0 ? sprintf('dev.%s', $matches[2]) : null;
kevin-lot marked this conversation as resolved.
Show resolved Hide resolved
$version = $version->withPreRelease($withPreRelease);
}

if (preg_match('/^(.*)-(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $version->getPreRelease(), $matches)) {
if (preg_match('/^(.*)-(\d+)-g([a-fA-F0-9]{7,40})(-dirty)?$/', $preRelease->toString(), $matches)) {
kevin-lot marked this conversation as resolved.
Show resolved Hide resolved
if ((int) $matches[2] != 0) {
kevin-lot marked this conversation as resolved.
Show resolved Hide resolved
// 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]);
} else {
$version = $version->withPreRelease(trim($matches[1], '-') . '.dev.' . $matches[3]);
}
// if we are not on TAG commit, add "dev" and git commit hash as pre release part
$withPreRelease = empty($matches[1]) ? sprintf('dev.%s', $matches[3]) : sprintf('%s.dev.%s', trim($matches[1], '-'), $matches[3]);
kevin-lot marked this conversation as resolved.
Show resolved Hide resolved
$version = $version->withPreRelease($withPreRelease);
} else {
if (empty($matches[1])) {
$version = $this->clearPreRelease($version);
} else {
$version = $version->withPreRelease(trim($matches[1], '-'));
}
$withPreRelease = empty($matches[1]) ? null : trim($matches[1], '-');
kevin-lot marked this conversation as resolved.
Show resolved Hide resolved
$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