diff --git a/src/Console/Command/SetupCICommand.php b/src/Console/Command/SetupCICommand.php
index 4b19f9b54d4..38d5bc85db5 100644
--- a/src/Console/Command/SetupCICommand.php
+++ b/src/Console/Command/SetupCICommand.php
@@ -4,14 +4,10 @@
namespace Rector\Console\Command;
-use Nette\Utils\FileSystem;
-use OndraM\CiDetector\CiDetector;
-use Rector\Git\RepositoryHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
-use function sprintf;
final class SetupCICommand extends Command
{
@@ -24,134 +20,15 @@ public function __construct(
protected function configure(): void
{
$this->setName('setup-ci');
- $this->setDescription('Add CI workflow to let Rector work for you');
+ $this->setDescription('[DEPRECATED] 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 === CiDetector::CI_GITLAB) {
- return $this->handleGitlabCi();
- }
-
- if ($ci === CiDetector::CI_GITHUB_ACTIONS) {
- return $this->handleGithubActions();
- }
-
- $noteMessage = sprintf(
- 'Only GitHub and GitLab are currently supported.%s Contribute your CI template to Rector to make this work: %s',
- "\n",
- 'https://github.com/rectorphp/rector-src/'
- );
-
- $this->symfonyStyle->note($noteMessage);
- return self::SUCCESS;
- }
-
- /**
- * @return CiDetector::CI_*|null
- */
- private function resolveCurrentCI(): ?string
- {
- if (file_exists(getcwd() . '/.github')) {
- return CiDetector::CI_GITHUB_ACTIONS;
- }
-
- if (file_exists(getcwd() . '/.gitlab-ci.yml')) {
- return CiDetector::CI_GITLAB;
- }
-
- return null;
- }
-
- private function addGithubActionsWorkflow(string $currentRepository, string $targetWorkflowFilePath): void
- {
- $workflowTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-github-action-check.yaml');
- $workflowContents = strtr($workflowTemplate, [
- '__CURRENT_REPOSITORY__' => $currentRepository,
- ]);
-
- FileSystem::write($targetWorkflowFilePath, $workflowContents, null);
-
- $this->symfonyStyle->newLine();
- $this->symfonyStyle->success('The ".github/workflows/rector.yaml" file was added');
-
- $this->symfonyStyle->writeln('2 more steps to run Rector in CI:');
-
- $this->symfonyStyle->newLine();
- $this->symfonyStyle->writeln(
- '1) Generate token with "repo" scope:' . \PHP_EOL . 'https://github.com/settings/tokens/new'
- );
-
- $this->symfonyStyle->newLine();
-
- $repositoryNewSecretsLink = sprintf('https://github.com/%s/settings/secrets/actions/new', $currentRepository);
- $this->symfonyStyle->writeln(
- '2) Add the token to Action secrets as "ACCESS_TOKEN":' . \PHP_EOL . $repositoryNewSecretsLink
+ $this->symfonyStyle->error(
+ 'The "setup-ci" command is deprecated and no longer generates files. Its generic template lacked caching and did not fit most setups. Add a CI workflow explicitly for your use case instead - an AI agent can tailor one to your repository.'
);
- }
-
- private function addGitlabFile(string $targetGitlabFilePath): void
- {
- $gitlabTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-gitlab-check.yaml');
- FileSystem::write($targetGitlabFilePath, $gitlabTemplate, null);
-
- $this->symfonyStyle->newLine();
- $this->symfonyStyle->success('The "gitlab/rector.yaml" file was added');
-
- $this->symfonyStyle->newLine();
- $this->symfonyStyle->writeln(
- '1) Register it in your ".gitlab-ci.yml" file:' . \PHP_EOL . 'include:' . \PHP_EOL . ' - local: gitlab/rector.yaml'
- );
- }
-
- /**
- * @return self::SUCCESS
- */
- private function handleGitlabCi(): int
- {
- // add snippet in the end of file or include it?
- $ciRectorFilePath = getcwd() . '/gitlab/rector.yaml';
-
- if (file_exists($ciRectorFilePath)) {
- $response = $this->symfonyStyle->ask(
- 'The "gitlab/rector.yaml" workflow already exists. Overwrite it?',
- 'Yes'
- );
- if (! in_array($response, ['y', 'yes', 'Yes'], true)) {
- $this->symfonyStyle->note('Nothing changed');
- return self::SUCCESS;
- }
- }
-
- $this->addGitlabFile($ciRectorFilePath);
- return self::SUCCESS;
- }
-
- /**
- * @return self::SUCCESS|self::FAILURE
- */
- private function handleGithubActions(): int
- {
- $rectorWorkflowFilePath = getcwd() . '/.github/workflows/rector.yaml';
- if (file_exists($rectorWorkflowFilePath)) {
- $response = $this->symfonyStyle->ask('The "rector.yaml" workflow already exists. Overwrite it?', 'Yes');
- if (! in_array($response, ['y', 'yes', 'Yes'], true)) {
- $this->symfonyStyle->note('Nothing changed');
- return self::SUCCESS;
- }
- }
-
- $currentRepository = RepositoryHelper::resolveGithubRepositoryName(getcwd());
- if ($currentRepository === null) {
- $this->symfonyStyle->error('Current repository name could not be resolved');
-
- return self::FAILURE;
- }
- $this->addGithubActionsWorkflow($currentRepository, $rectorWorkflowFilePath);
- return self::SUCCESS;
+ return Command::FAILURE;
}
}
diff --git a/src/Git/RepositoryHelper.php b/src/Git/RepositoryHelper.php
deleted file mode 100644
index 207ee28ad59..00000000000
--- a/src/Git/RepositoryHelper.php
+++ /dev/null
@@ -1,28 +0,0 @@
-.*?)\.git#';
-
- public static function resolveGithubRepositoryName(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;
- }
-}
diff --git a/templates/rector-github-action-check.yaml b/templates/rector-github-action-check.yaml
deleted file mode 100644
index b315f3c0820..00000000000
--- a/templates/rector-github-action-check.yaml
+++ /dev/null
@@ -1,36 +0,0 @@
-# github action that checks code with Rector
-name: Rector
-
-on:
- pull_request: null
-
-jobs:
- rector:
- runs-on: ubuntu-latest
- if: github.event.pull_request.head.repo.full_name == '__CURRENT_REPOSITORY__'
- steps:
- -
- if: github.event.pull_request.head.repo.full_name == github.repository
- uses: actions/checkout@v4
- with:
- # Must be used to trigger workflow after push
- token: ${{ secrets.ACCESS_TOKEN }}
-
- -
- uses: shivammathur/setup-php@v2
- with:
- php-version: 8.3
- coverage: none
-
- - uses: "ramsey/composer-install@v3"
-
- - run: vendor/bin/rector --ansi
- # @todo apply coding standard if used
-
- -
- # commit only to core contributors who have repository access
- uses: stefanzweifel/git-auto-commit-action@v5
- with:
- commit_message: '[rector] Rector fixes'
- commit_author: 'GitHub Action '
- commit_user_email: 'action@github.com'
diff --git a/templates/rector-gitlab-check.yaml b/templates/rector-gitlab-check.yaml
deleted file mode 100644
index 8ac3fb4c47c..00000000000
--- a/templates/rector-gitlab-check.yaml
+++ /dev/null
@@ -1,27 +0,0 @@
-stages:
- - setup
- - rector
- - commit_changes
-
-setup:
- stage: setup
- # see https://github.com/thecodingmachine/docker-images-php
- image: thecodingmachine/php:8.3-v4-slim-cli
-
-rector:
- stage: rector
- script:
- - vendor/bin/rector --ansi
- # @todo apply coding standard if used
-
-commit_changes:
- stage: commit_changes
- script:
- - git config --global user.email "ci@gitlab.com"
- - git config --global user.name "GitLab CI"
- # - git checkout $CI_COMMIT_REF_NAME
- - git add .
- - git commit -m "[rector] Rector fixes"
- - git push origin $CI_COMMIT_REF_NAME
- only:
- - merge_requests