resolve rector verison in own command

This commit is contained in:
Tomas Votruba 2022-05-29 22:31:20 +02:00
parent 12b019ac62
commit 35351fe156
2 changed files with 59 additions and 0 deletions

View File

@ -48,6 +48,9 @@ jobs:
# install only prod dependencies - do not use ramsey, it uses cache including "dev", we want to avoid it here
- run: composer install --no-dev --ansi
# resolve rector version
- run: bin/resolve-version.php
# early downgrade individual functions
- run: bin/rector process src/functions -c build/config/config-downgrade.php --ansi

56
bin/resolve-version.php Executable file
View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
// resolve git version stored in released rector
// tag for tagged one, hash for dev
/**
* Inspired by https://github.com/composer/composer/blob/master/src/Composer/Composer.php
* See https://github.com/composer/composer/blob/6587715d0f8cae0cd39073b3bc5f018d0e6b84fe/src/Composer/Compiler.php#L208
*
* @see \Rector\Core\Tests\Application\VersionResolverTest
*/
final class VersionResolver
{
/**
* @var int
*/
private const SUCCESS_CODE = 0;
public function resolve(): string
{
// resolve current tag
exec('git tag --points-at', $tagExecOutput, $tagExecResultCode);
if ($tagExecResultCode !== self::SUCCESS_CODE) {
die('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;
}
}
exec('git log --pretty="%H" -n1 HEAD', $commitHashExecOutput, $commitHashResultCode);
if ($commitHashResultCode !== 0) {
die('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, '"');
}
}
$versionResolver = new VersionResolver();
echo $versionResolver->resolve() . PHP_EOL;