Skip to content

Commit

Permalink
remove lass process
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 29, 2022
1 parent cd04248 commit d292e9d
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use DateTime;
use Rector\Core\Exception\VersionException;
use Symfony\Component\Process\Process;

/**
* Inspired by https://github.com/composer/composer/blob/master/src/Composer/Composer.php
Expand All @@ -26,66 +25,50 @@ final class VersionResolver
*/
public const RELEASE_DATE = '@release_date@';

/**
* @var string
*/
private const GIT = 'git';

/**
* @var int
*/
private const SUCCESS_CODE = 0;

public static function resolvePackageVersion(): string
{
// needed to keep exec() in the rector directory, not depending on cwd of run command of scoper
$repositoryDirectory = __DIR__ . '/../..';

// resolve current tag
$commandLine = sprintf('cd %s && git tag --points-at', $repositoryDirectory);
exec($commandLine, $tagExecOutput, $tagExecResultCode);
exec('git tag --points-at', $tagExecOutput, $tagExecResultCode);

if ($tagExecResultCode !== self::SUCCESS_CODE) {
throw new VersionException(
'Ensure to run compile from composer git repository clone and that git binary is available.'
);
}

// debug output
var_dump($tagExecOutput);

if ($tagExecOutput !== []) {
$tag = $tagExecOutput[0];
if ($tag !== '') {
return $tag;
}
}

$commandLine = sprintf('cd %s && git log --pretty="%%H" -n1 HEAD', $repositoryDirectory);
exec($commandLine, $commitHashExecOutput, $commitHashResultCode);
exec('git log --pretty="%H" -n1 HEAD', $commitHashExecOutput, $commitHashResultCode);

if ($commitHashResultCode !== 0) {
throw new VersionException(
'Ensure to run compile from composer git repository clone and that git binary is available.'
);
}

// debug output
var_dump($commitHashExecOutput);

$version = trim($commitHashExecOutput[0]);
return trim($version, '"');
}

public static function resolverReleaseDateTime(): DateTime
{
$process = new Process([self::GIT, 'log', '-n1', '--pretty=%ci', 'HEAD'], __DIR__);
if ($process->run() !== 0) {
exec('git log -n1 --pretty=%ci HEAD', $output, $resultCode);
if ($resultCode !== self::SUCCESS_CODE) {
throw new VersionException(
'You must ensure to run compile from composer git repository clone and that git binary is available.'
);
}

return new DateTime(trim($process->getOutput()));
return new DateTime(trim($output[0]));
}
}

0 comments on commit d292e9d

Please sign in to comment.