Skip to content

Commit b90ce0e

Browse files
committed
ci(support): Add checkSoarBinary script to validate executable files
- Introduce `checkSoarBinary` method in `ComposerScripts` class to verify file executability. - Add command to `composer.json` for easy access to the new script. - Ensure all binary files in the `bin` directory follow executability rules to avoid runtime errors. - Provide success and error messages using SymfonyStyle.
1 parent c4212a4 commit b90ce0e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@
153153
"benchmark": "@php ./vendor/bin/phpbench run --report=aggregate --ansi -v",
154154
"cghooks": "@php ./vendor/bin/cghooks --ansi -v",
155155
"cghooks-ignore": "[ ! -f \"./vendor/bin/cghooks\" ] && exit 0 || php ./vendor/bin/cghooks --ansi -v",
156+
"check-soar-binary": "Guanguans\\SoarPHP\\Support\\ComposerScripts::checkSoarBinary",
156157
"checks": [
157158
"@composer-normalize",
158159
"@composer-validate",
160+
"@check-soar-binary",
159161
"@dump-soar-yaml-config",
160162
"@json-lint",
161163
"@md-lint",

src/Support/ComposerScripts.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,40 @@
2020
use Illuminate\Support\Stringable;
2121
use Rector\Config\RectorConfig;
2222
use Rector\DependencyInjection\LazyContainerFactory;
23+
use Symfony\Component\Console\Input\ArgvInput;
24+
use Symfony\Component\Console\Output\ConsoleOutput;
25+
use Symfony\Component\Console\Style\SymfonyStyle;
2326
use Symfony\Component\Yaml\Yaml;
2427

2528
/**
2629
* @internal
2730
*/
2831
final class ComposerScripts
2932
{
33+
/**
34+
* @see \Composer\Util\Silencer
35+
*
36+
* @noinspection PhpUnused
37+
*/
38+
public static function checkSoarBinary(Event $event): int
39+
{
40+
self::requireAutoload($event);
41+
42+
$symfonyStyle = self::makeSymfonyStyle();
43+
44+
foreach ((array) glob(__DIR__.'/../../bin/soar.*-*') as $file) {
45+
if (!is_executable($file)) {
46+
$symfonyStyle->error("The file [$file] is not executable.");
47+
48+
exit(1);
49+
}
50+
}
51+
52+
$symfonyStyle->success('No errors');
53+
54+
return 0;
55+
}
56+
3057
/**
3158
* @noinspection PhpUnused
3259
*
@@ -41,7 +68,7 @@ public static function dumpSoarYamlConfig(Event $event): int
4168
Yaml::dump(input: self::resolveSoarConfig()->all(), indent: 2)
4269
);
4370

44-
$event->getIO()->write('<info>操作成功</info>');
71+
self::makeSymfonyStyle()->success('No errors');
4572

4673
return 0;
4774
}
@@ -169,6 +196,11 @@ public static function makeRectorConfig(): RectorConfig
169196
return (new LazyContainerFactory)->create();
170197
}
171198

199+
private static function makeSymfonyStyle(): SymfonyStyle
200+
{
201+
return new SymfonyStyle(new ArgvInput, new ConsoleOutput);
202+
}
203+
172204
private static function requireAutoload(Event $event): void
173205
{
174206
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';

0 commit comments

Comments
 (0)