diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 31465a5..6e22e0a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,12 @@ name: CI -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: + branches: + - '*' jobs: testsuite: diff --git a/.github/workflows/phar-build.yaml b/.github/workflows/phar-build.yaml index 972bcf6..5059428 100644 --- a/.github/workflows/phar-build.yaml +++ b/.github/workflows/phar-build.yaml @@ -17,13 +17,16 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.4' extensions: json, fileinfo tools: composer - name: Install dependencies run: composer install --no-dev --optimize-autoloader + - name: Inject version from tag + run: sed -i "s/public const VERSION = .*/public const VERSION = '\${{ github.ref_name }}';/" src/Application.php + - name: Build PHAR run: composer build-phar diff --git a/.gitignore b/.gitignore index 89e29e1..08f09d0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ .env infection.log phive.phar -cognitive-analysis.phar +phpcca.phar diff --git a/box.json.dist b/box.json.dist index a1ca119..bfd0e5b 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,8 +1,13 @@ { - "main": "./bin/phpcca", + "main": "bin/phpcca", "compression": "GZ", "output": "phpcca.phar", "force-autodiscovery": true, + "compactors": [ + "KevinGH\\Box\\Compactor\\Json", + "KevinGH\\Box\\Compactor\\Php", + "KevinGH\\Box\\Compactor\\PhpScoper" + ], "files": [ "config.yml", "composer.json", diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100755 index 0000000..b50f70a --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,10 @@ +# Get the latest tag reachable from the previous commit +TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null) + +if [ -n "$TAG" ]; then + sed -i "s/public const VERSION = .*/public const VERSION = '$TAG';/" src/Application.php + git add src/Application.php + echo "Version set to $TAG" +else + echo "No previous tag found." +fi diff --git a/src/Application.php b/src/Application.php index 065e409..9f0b448 100644 --- a/src/Application.php +++ b/src/Application.php @@ -49,6 +49,8 @@ */ class Application { + public const VERSION = '1.3.0'; + private ContainerBuilder $containerBuilder; public function __construct() @@ -231,6 +233,10 @@ private function registerCommands(): void private function configureApplication(): void { $this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class) + ->setArguments([ + 'Cognitive Code Analysis', + self::VERSION + ]) ->setPublic(true) ->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)]) ->addMethodCall('add', [new Reference(ChurnCommand::class)]); diff --git a/src/Command/EventHandler/VerboseHandler.php b/src/Command/EventHandler/VerboseHandler.php index 8d6a073..c408207 100644 --- a/src/Command/EventHandler/VerboseHandler.php +++ b/src/Command/EventHandler/VerboseHandler.php @@ -25,10 +25,7 @@ public function __construct( public function __invoke(SourceFilesFound|FileProcessed $event): void { - if ( - $this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG) - && $this->input->getOption(CognitiveMetricsCommand::OPTION_DEBUG) === false - ) { + if (!$this->isDebugEnabled()) { return; } @@ -62,4 +59,13 @@ private function formatBytes(int $size): string return round($size, 2) . ' ' . $units[$index]; } + + /** + * @return bool + */ + public function isDebugEnabled(): bool + { + return $this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG) + && $this->input->getOption(CognitiveMetricsCommand::OPTION_DEBUG) === false; + } }