This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EasyCI] Move ValidateFileLengthCommand to easy-ci command (#2913)
* [EasyCI] Move ValidateFileLengthCommand to easy-ci command * fix * fix * fix
- Loading branch information
1 parent
055e5d9
commit 155e540
Showing
7 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/easy-ci/src/Command/ValidateFileLengthCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\EasyCI\Command; | ||
|
||
use Symplify\EasyCI\Finder\ProjectFilesFinder; | ||
use Symplify\EasyCI\Resolver\TooLongFilesResolver; | ||
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 Symplify\PackageBuilder\Console\ShellCode; | ||
use Symplify\PackageBuilder\ValueObject\Option; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
final class ValidateFileLengthCommand extends Command | ||
{ | ||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private $symfonyStyle; | ||
|
||
/** | ||
* @var ProjectFilesFinder | ||
*/ | ||
private $projectFilesFinder; | ||
|
||
/** | ||
* @var TooLongFilesResolver | ||
*/ | ||
private $tooLongFilesResolver; | ||
|
||
public function __construct( | ||
ProjectFilesFinder $projectFilesFinder, | ||
SymfonyStyle $symfonyStyle, | ||
TooLongFilesResolver $tooLongFilesResolver | ||
) { | ||
$this->symfonyStyle = $symfonyStyle; | ||
|
||
parent::__construct(); | ||
|
||
$this->projectFilesFinder = $projectFilesFinder; | ||
$this->tooLongFilesResolver = $tooLongFilesResolver; | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setDescription('[CI] Make sure the file path length are not breaking normal Windows max length'); | ||
$this->addArgument(Option::SOURCES, InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Path to project'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
/** @var string[] $sources */ | ||
$sources = (array) $input->getArgument(Option::SOURCES); | ||
|
||
$fileInfos = $this->projectFilesFinder->find($sources); | ||
$tooLongFileInfos = $this->tooLongFilesResolver->resolve($fileInfos); | ||
|
||
if ($tooLongFileInfos === []) { | ||
$message = sprintf('Checked %d files - all fit max file length', count($fileInfos)); | ||
$this->symfonyStyle->success($message); | ||
|
||
return ShellCode::SUCCESS; | ||
} | ||
|
||
foreach ($tooLongFileInfos as $tooLongFileInfo) { | ||
$message = sprintf( | ||
'Paths for file "%s" has %d chars, but must be shorter than %d.', | ||
$tooLongFileInfo->getRealPath(), | ||
strlen($tooLongFileInfo->getRealPath()), | ||
TooLongFilesResolver::MAX_FILE_LENGTH | ||
); | ||
|
||
$this->symfonyStyle->warning($message); | ||
} | ||
|
||
return ShellCode::ERROR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\EasyCI\Finder; | ||
|
||
use Symplify\SmartFileSystem\Finder\SmartFinder; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class ProjectFilesFinder | ||
{ | ||
/** | ||
* @var SmartFinder | ||
*/ | ||
private $smartFinder; | ||
|
||
public function __construct(SmartFinder $smartFinder) | ||
{ | ||
$this->smartFinder = $smartFinder; | ||
} | ||
|
||
/** | ||
* @return SmartFileInfo[] | ||
*/ | ||
public function find(array $sources): array | ||
{ | ||
$paths = []; | ||
foreach ($sources as $source) { | ||
$paths[] = getcwd() . DIRECTORY_SEPARATOR . $source; | ||
} | ||
|
||
return $this->smartFinder->find($paths, '*'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\EasyCI\Resolver; | ||
|
||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class TooLongFilesResolver | ||
{ | ||
/** | ||
* In windows the max-path length is 260 chars. we give a bit room for the path up to the rector project | ||
* @var int | ||
*/ | ||
public const MAX_FILE_LENGTH = 200; | ||
|
||
/** | ||
* @param SmartFileInfo[] $fileInfos | ||
* @return SmartFileInfo[] | ||
*/ | ||
public function resolve(array $fileInfos): array | ||
{ | ||
return array_filter($fileInfos, function (SmartFileInfo $fileInfo): bool { | ||
$filePathLength = strlen($fileInfo->getRealPath()); | ||
return $filePathLength > self::MAX_FILE_LENGTH; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters