Skip to content

Commit

Permalink
try cwed
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 29, 2022
1 parent ac64e0b commit 366995d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 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\Console\Command\Command;
use Symfony\Component\Process\Process;

/**
Expand All @@ -32,12 +31,21 @@ final class VersionResolver
*/
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
exec('git tag --points-at', $tagExecOutput, $tagExecResultCode);
$commandLine = sprintf('cd %s && git tag --points-at', $repositoryDirectory);
exec($commandLine, $tagExecOutput, $tagExecResultCode);

if ($tagExecResultCode !== Command::SUCCESS) {
if ($tagExecResultCode !== self::SUCCESS_CODE) {
throw new VersionException(
'Ensure to run compile from composer git repository clone and that git binary is available.'
);
Expand All @@ -50,9 +58,10 @@ public static function resolvePackageVersion(): string
}
}

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

if ($commitHashResultCode !== Command::SUCCESS) {
if ($commitHashResultCode !== 0) {
throw new VersionException(
'Ensure to run compile from composer git repository clone and that git binary is available.'
);
Expand All @@ -65,7 +74,7 @@ public static function resolvePackageVersion(): string
public static function resolverReleaseDateTime(): DateTime
{
$process = new Process([self::GIT, 'log', '-n1', '--pretty=%ci', 'HEAD'], __DIR__);
if ($process->run() !== Command::SUCCESS) {
if ($process->run() !== 0) {
throw new VersionException(
'You must ensure to run compile from composer git repository clone and that git binary is available.'
);
Expand Down

0 comments on commit 366995d

Please sign in to comment.