Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Makefile tasks with Castor tasks #37

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/CODE_OF_CONDUCT.md export-ignore
/castor.php export-ignore
/ecs.php export-ignore
/infection.json export-ignore
/Makefile export-ignore
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/infection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
with:
php-version: "8.3"
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
tools: castor

- name: "Checkout code"
uses: "actions/checkout@v4"
Expand All @@ -29,4 +30,4 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute Infection"
run: "make ci-mu"
run: "castor infect --ci"
13 changes: 9 additions & 4 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.3"
tools: castor

- name: "Checkout code"
uses: "actions/checkout@v4"
Expand Down Expand Up @@ -66,6 +67,7 @@ jobs:
php-version: "${{ matrix.php-version }}"
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
coverage: "xdebug"
tools: castor

- name: "Checkout code"
uses: "actions/checkout@v4"
Expand All @@ -77,7 +79,7 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute unit tests"
run: "make ci-cc"
run: "castor test --coverage-text"

static_analysis:
name: "3️⃣ Static Analysis"
Expand All @@ -91,6 +93,7 @@ jobs:
with:
php-version: "8.3"
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
tools: castor

- name: "Checkout code"
uses: "actions/checkout@v4"
Expand All @@ -105,7 +108,7 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute static analysis"
run: "make st"
run: "castor stan"

coding_standards:
name: "4️⃣ Coding Standards"
Expand All @@ -119,6 +122,7 @@ jobs:
with:
php-version: "8.3"
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
tools: castor

- name: "Checkout code"
uses: "actions/checkout@v4"
Expand All @@ -133,7 +137,7 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Check coding style"
run: "make ci-cs"
run: "castor cs"

rector_checkstyle:
name: "6️⃣ Rector Checkstyle"
Expand All @@ -147,6 +151,7 @@ jobs:
with:
php-version: "8.3"
extensions: "json, mbstring, openssl, sqlite3, curl, uuid"
tools: castor
coverage: "xdebug"

- name: "Checkout code"
Expand All @@ -162,7 +167,7 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute Rector"
run: "make rector"
run: "castor rector"

exported_files:
name: "7️⃣ Exported files"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
/composer.lock
/.phpunit.result.cache
/.castor.stub.php
/.phpunit.cache
50 changes: 0 additions & 50 deletions Makefile

This file was deleted.

106 changes: 106 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

use Castor\Attribute\AsTask;
use function Castor\io;
use function Castor\run;

#[AsTask(description: 'Run mutation testing')]
function infect(int $minMsi = 0, int $minCoveredMsi = 0, bool $ci = false): void
{
io()->title('Running infection');
$nproc = run('nproc', quiet: true);
if (! $nproc->isSuccessful()) {
io()->error('Cannot determine the number of processors');
return;
}
$threads = (int) $nproc->getOutput();
$command = [
'php',
'vendor/bin/infection',
sprintf('--min-msi=%s', $minMsi),
sprintf('--min-covered-msi=%s', $minCoveredMsi),
sprintf('--threads=%s', $threads),
];
if ($ci) {
$command[] = '--logger-github';
$command[] = '-s';
}
$environment = [
'XDEBUG_MODE' => 'coverage',
];
run($command, environment: $environment);
}

#[AsTask(description: 'Run tests')]
function test(bool $coverageHtml = false, bool $coverageText = false, null|string $group = null): void
{
io()->title('Running tests');
$command = ['php', 'vendor/bin/phpunit', '--color'];
$environment = [
'XDEBUG_MODE' => 'off',
];
if ($coverageHtml) {
$command[] = '--coverage-html=build/coverage';
$environment['XDEBUG_MODE'] = 'coverage';
}
if ($coverageText) {
$command[] = '--coverage-text';
$environment['XDEBUG_MODE'] = 'coverage';
}
if ($group !== null) {
$command[] = sprintf('--group=%s', $group);
}
run($command, environment: $environment);
}

#[AsTask(description: 'Coding standards check')]
function cs(bool $fix = false): void
{
io()->title('Running coding standards check');
$command = ['php', 'vendor/bin/ecs', 'check'];
$environment = [
'XDEBUG_MODE' => 'off',
];
if ($fix) {
$command[] = '--fix';
}
run($command, environment: $environment);
}

#[AsTask(description: 'Running PHPStan')]
function stan(): void
{
io()->title('Running PHPStan');
$command = ['php', 'vendor/bin/phpstan', 'analyse'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}

#[AsTask(description: 'Validate Composer configuration')]
function validate(): void
{
io()->title('Validating Composer configuration');
$command = ['composer', 'validate'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}

#[AsTask(description: 'Run Rector')]
function rector(bool $fix = false): void
{
io()->title('Running Rector');
$command = ['php', 'vendor/bin/rector', 'process', '--ansi'];
if (! $fix) {
$command[] = '--dry-run';
}
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
__DIR__ . '/build',
__DIR__ . '/vendor',
__DIR__ . '/var',
__DIR__ . '/.castor.stub.php',
PhpUnitTestClassRequiresCoversFixer::class,
]
);
Expand Down