From efc969e6411704d02e004045cb8b1da5d263970c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 2 Mar 2023 15:22:13 +0000 Subject: [PATCH] Improve setup-ci command with helper links and allow override (#3438) --- src/Console/Command/SetupCICommand.php | 65 +++++++++++++++++++------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/Console/Command/SetupCICommand.php b/src/Console/Command/SetupCICommand.php index 061e09cb1f7..23ba40fdeb8 100644 --- a/src/Console/Command/SetupCICommand.php +++ b/src/Console/Command/SetupCICommand.php @@ -42,29 +42,62 @@ protected function execute(InputInterface $input, OutputInterface $output): int 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'); + if ($ci !== CiDetector::CI_GITHUB_ACTIONS) { + $noteMessage = sprintf( + 'Only Github Action is supported for now.%sCreate an issue to add your CI %s', + PHP_EOL, + 'https://github.com/rectorphp/rector/issues/' + ); + + $this->symfonyStyle->note($noteMessage); + return self::SUCCESS; + } + + $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 = $this->resolveCurrentRepositoryName(getcwd()); - if ($currentRepository === null) { - $this->symfonyStyle->error('Current repository name could not be resolved'); + $currentRepository = $this->resolveCurrentRepositoryName(getcwd()); + if ($currentRepository === null) { + $this->symfonyStyle->error('Current repository name could not be resolved'); - return self::FAILURE; - } + return self::FAILURE; + } - $workflowTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-github-action-check.yaml'); + $workflowTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-github-action-check.yaml'); - $workflowContents = strtr($workflowTemplate, [ - '__CURRENT_REPOSITORY__' => $currentRepository, - ]); + $workflowContents = strtr($workflowTemplate, [ + '__CURRENT_REPOSITORY__' => $currentRepository, + ]); - FileSystem::write($rectorWorkflowFilePath, $workflowContents); - $this->symfonyStyle->success('The "rector.yaml" workflow was added'); - } + FileSystem::write($rectorWorkflowFilePath, $workflowContents); + + $this->symfonyStyle->newLine(); + + $this->symfonyStyle->note('The "rector.yaml" workflow was added'); + $this->symfonyStyle->newLine(); + + $this->symfonyStyle->title('2 steps more to run you Github Action:'); + $this->symfonyStyle->writeln( + '1) Generate new Github Token here:' . + PHP_EOL . + 'https://github.com/settings/tokens/new' + ); + + $this->symfonyStyle->newLine(); + + $this->symfonyStyle->writeln( + '2) Add it to your repository secrets under "GITHUB_TOKE" name:' + . PHP_EOL . + sprintf('https://github.com/%s/settings/secrets/actions/new', $currentRepository) + ); + + $this->symfonyStyle->newLine(); return Command::SUCCESS; }