Skip to content

Commit 1848984

Browse files
Refining the Box Config and App Versioning (#41)
* Refining the Box Config and App Versioning * Updating CI Action * Refining the version handling * Revert "Refining the version handling" * Refining the version handling * Adding tag script * Reverting a change to the Box Config * Minor refactoring / clean code
1 parent 14efd09 commit 1848984

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '*'
410

511
jobs:
612
testsuite:

.github/workflows/phar-build.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ jobs:
1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: '8.2'
20+
php-version: '8.4'
2121
extensions: json, fileinfo
2222
tools: composer
2323

2424
- name: Install dependencies
2525
run: composer install --no-dev --optimize-autoloader
2626

27+
- name: Inject version from tag
28+
run: sed -i "s/public const VERSION = .*/public const VERSION = '\${{ github.ref_name }}';/" src/Application.php
29+
2730
- name: Build PHAR
2831
run: composer build-phar
2932

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
.env
1111
infection.log
1212
phive.phar
13-
cognitive-analysis.phar
13+
phpcca.phar

box.json.dist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
2-
"main": "./bin/phpcca",
2+
"main": "bin/phpcca",
33
"compression": "GZ",
44
"output": "phpcca.phar",
55
"force-autodiscovery": true,
6+
"compactors": [
7+
"KevinGH\\Box\\Compactor\\Json",
8+
"KevinGH\\Box\\Compactor\\Php",
9+
"KevinGH\\Box\\Compactor\\PhpScoper"
10+
],
611
"files": [
712
"config.yml",
813
"composer.json",

scripts/tag.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Get the latest tag reachable from the previous commit
2+
TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null)
3+
4+
if [ -n "$TAG" ]; then
5+
sed -i "s/public const VERSION = .*/public const VERSION = '$TAG';/" src/Application.php
6+
git add src/Application.php
7+
echo "Version set to $TAG"
8+
else
9+
echo "No previous tag found."
10+
fi

src/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
*/
5050
class Application
5151
{
52+
public const VERSION = '1.3.0';
53+
5254
private ContainerBuilder $containerBuilder;
5355

5456
public function __construct()
@@ -231,6 +233,10 @@ private function registerCommands(): void
231233
private function configureApplication(): void
232234
{
233235
$this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class)
236+
->setArguments([
237+
'Cognitive Code Analysis',
238+
self::VERSION
239+
])
234240
->setPublic(true)
235241
->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)])
236242
->addMethodCall('add', [new Reference(ChurnCommand::class)]);

src/Command/EventHandler/VerboseHandler.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public function __construct(
2525

2626
public function __invoke(SourceFilesFound|FileProcessed $event): void
2727
{
28-
if (
29-
$this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG)
30-
&& $this->input->getOption(CognitiveMetricsCommand::OPTION_DEBUG) === false
31-
) {
28+
if (!$this->isDebugEnabled()) {
3229
return;
3330
}
3431

@@ -62,4 +59,13 @@ private function formatBytes(int $size): string
6259

6360
return round($size, 2) . ' ' . $units[$index];
6461
}
62+
63+
/**
64+
* @return bool
65+
*/
66+
public function isDebugEnabled(): bool
67+
{
68+
return $this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG)
69+
&& $this->input->getOption(CognitiveMetricsCommand::OPTION_DEBUG) === false;
70+
}
6571
}

0 commit comments

Comments
 (0)