Updated Rector to commit 8a0b8381d5435f9152e71e2dc437e604aebef9e2

8a0b8381d5 [DX] Add setup-ci command to ease integration to CI (#3425)
This commit is contained in:
Tomas Votruba 2023-02-28 17:00:04 +00:00
parent b8fc1aed27
commit 4714a9c55d
7 changed files with 143 additions and 12 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '8ef705e16046c3e6a8b87f81ea466ebc6ae3faf1';
public const PACKAGE_VERSION = '8a0b8381d5435f9152e71e2dc437e604aebef9e2';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-02-28 15:50:12';
public const RELEASE_DATE = '2023-02-28 16:55:40';
/**
* @var int
*/

View File

@ -0,0 +1,81 @@
<?php
declare (strict_types=1);
namespace Rector\Core\Console\Command;
use RectorPrefix202302\Nette\Utils\FileSystem;
use RectorPrefix202302\Nette\Utils\Strings;
use RectorPrefix202302\OndraM\CiDetector\CiDetector;
use RectorPrefix202302\Symfony\Component\Console\Command\Command;
use RectorPrefix202302\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix202302\Symfony\Component\Console\Output\OutputInterface;
use RectorPrefix202302\Symfony\Component\Console\Style\SymfonyStyle;
use RectorPrefix202302\Symfony\Component\Process\Process;
final class SetupCICommand extends Command
{
/**
* @var string
* @see https://regex101.com/r/etcmog/1
*/
private const GITHUB_REPOSITORY_REGEX = '#github\\.com:(?<repository_name>.*?)\\.git#';
/**
* @readonly
* @var \Symfony\Component\Console\Style\SymfonyStyle
*/
private $symfonyStyle;
public function __construct(SymfonyStyle $symfonyStyle)
{
$this->symfonyStyle = $symfonyStyle;
parent::__construct();
}
protected function configure() : void
{
$this->setName('setup-ci');
$this->setDescription('Add CI workflow to let Rector work for you');
}
protected function execute(InputInterface $input, OutputInterface $output) : int
{
// detect current CI
$ci = $this->resolveCurrentCI();
if ($ci === null) {
$this->symfonyStyle->error('No CI detected');
return self::FAILURE;
}
if ($ci === CiDetector::CI_GITHUB_ACTIONS) {
$rectorWorkflowFilePath = \getcwd() . '/.github/workflows/rector.yaml';
if (\file_exists($rectorWorkflowFilePath)) {
$this->symfonyStyle->warning('The "rector.yaml" workflow already exists');
return self::SUCCESS;
}
$currentRepository = $this->resolveCurrentRepositoryName(\getcwd());
if ($currentRepository === null) {
$this->symfonyStyle->error('Current repository name could not be resolved');
return self::FAILURE;
}
$workflowTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-github-action-check.yaml');
$workflowContents = \strtr($workflowTemplate, ['__CURRENT_REPOSITORY__' => $currentRepository]);
FileSystem::write($rectorWorkflowFilePath, $workflowContents);
$this->symfonyStyle->success('The "rector.yaml" workflow was added');
}
return Command::SUCCESS;
}
/**
* @return CiDetector::CI_*|null
*/
private function resolveCurrentCI() : ?string
{
if (\file_exists(\getcwd() . '/.github')) {
return CiDetector::CI_GITHUB_ACTIONS;
}
return null;
}
private function resolveCurrentRepositoryName(string $currentDirectory) : ?string
{
// resolve current repository name
$process = new Process(['git', 'remote', 'get-url', 'origin'], $currentDirectory, null, null, null);
$process->run();
$output = $process->getOutput();
$match = Strings::match($output, self::GITHUB_REPOSITORY_REGEX);
return $match['repository_name'] ?? null;
}
}

View File

@ -0,0 +1,48 @@
# github action that checks code with Rector
name: Rector
on:
pull_request: null
jobs:
rector:
# Don't run on forks.
if: github.repository == '__CURRENT_REPOSITORY__'
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v3
with:
# needed to trigger workflow after push
token: ${{ secrets.ACCESS_TOKEN }}
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
- uses: "ramsey/composer-install@v2"
## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future
- run: vendor/bin/rector --ansi
- run: vendor/bin/ecs check --fix --ansi
# see https://github.com/EndBug/add-and-commit
-
# commit only to core contributors who have repository access
if: github.event.pull_request.head.repo.full_name == github.repository
uses: EndBug/add-and-commit@v7.5.0
with:
# The arguments for the `git add` command (see the paragraph below for more info)
add: .
message: "[rector] Rector fixes"
author_name: "GitHub Action"
author_email: "action@github.com"
env:
# to get push access
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit09fb3ecb88f579aa11191a4dd47a5c20::getLoader();
return ComposerAutoloaderInitce0d6d3deeb5e8d7f8a446c811f2b28b::getLoader();

View File

@ -1393,6 +1393,7 @@ return array(
'Rector\\Core\\Console\\Command\\InitCommand' => $baseDir . '/src/Console/Command/InitCommand.php',
'Rector\\Core\\Console\\Command\\ListRulesCommand' => $baseDir . '/src/Console/Command/ListRulesCommand.php',
'Rector\\Core\\Console\\Command\\ProcessCommand' => $baseDir . '/src/Console/Command/ProcessCommand.php',
'Rector\\Core\\Console\\Command\\SetupCICommand' => $baseDir . '/src/Console/Command/SetupCICommand.php',
'Rector\\Core\\Console\\Command\\WorkerCommand' => $baseDir . '/src/Console/Command/WorkerCommand.php',
'Rector\\Core\\Console\\ConsoleApplication' => $baseDir . '/src/Console/ConsoleApplication.php',
'Rector\\Core\\Console\\ExitCode' => $baseDir . '/src/Console/ExitCode.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit09fb3ecb88f579aa11191a4dd47a5c20
class ComposerAutoloaderInitce0d6d3deeb5e8d7f8a446c811f2b28b
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit09fb3ecb88f579aa11191a4dd47a5c20
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit09fb3ecb88f579aa11191a4dd47a5c20', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitce0d6d3deeb5e8d7f8a446c811f2b28b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit09fb3ecb88f579aa11191a4dd47a5c20', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitce0d6d3deeb5e8d7f8a446c811f2b28b', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitce0d6d3deeb5e8d7f8a446c811f2b28b::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitce0d6d3deeb5e8d7f8a446c811f2b28b::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20
class ComposerStaticInitce0d6d3deeb5e8d7f8a446c811f2b28b
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1640,6 +1640,7 @@ class ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20
'Rector\\Core\\Console\\Command\\InitCommand' => __DIR__ . '/../..' . '/src/Console/Command/InitCommand.php',
'Rector\\Core\\Console\\Command\\ListRulesCommand' => __DIR__ . '/../..' . '/src/Console/Command/ListRulesCommand.php',
'Rector\\Core\\Console\\Command\\ProcessCommand' => __DIR__ . '/../..' . '/src/Console/Command/ProcessCommand.php',
'Rector\\Core\\Console\\Command\\SetupCICommand' => __DIR__ . '/../..' . '/src/Console/Command/SetupCICommand.php',
'Rector\\Core\\Console\\Command\\WorkerCommand' => __DIR__ . '/../..' . '/src/Console/Command/WorkerCommand.php',
'Rector\\Core\\Console\\ConsoleApplication' => __DIR__ . '/../..' . '/src/Console/ConsoleApplication.php',
'Rector\\Core\\Console\\ExitCode' => __DIR__ . '/../..' . '/src/Console/ExitCode.php',
@ -3125,9 +3126,9 @@ class ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit09fb3ecb88f579aa11191a4dd47a5c20::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitce0d6d3deeb5e8d7f8a446c811f2b28b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitce0d6d3deeb5e8d7f8a446c811f2b28b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitce0d6d3deeb5e8d7f8a446c811f2b28b::$classMap;
}, null, ClassLoader::class);
}