Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Makefile with castor.php and update workflow
Browse files Browse the repository at this point in the history
A new castor.php file is introduced, replacing the existing Makefile which has been removed. This update modifies the GitHub workflows to call the appropriate Castor tasks. Minor changes are also made to existing source files and static analysis configurations to include the new castor.php file.
Spomky committed Jul 20, 2024
1 parent cc698c6 commit a7dbc24
Showing 10 changed files with 244 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@
/.mergify.yml export-ignore
/babel.config.js export-ignore
/CODE_OF_CONDUCT.md export-ignore
/castor.php export-ignore
/deptrac.yaml export-ignore
/ecs.php export-ignore
/infection.json export-ignore
/jest.config.js export-ignore
/Makefile export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml.dist export-ignore
3 changes: 2 additions & 1 deletion .github/workflows/infection.yml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ jobs:
with:
php-version: "8.3"
extensions: "ctype, curl, dom, json, libxml, mbstring, openssl, phar, simplexml, sodium, tokenizer, xml, xmlwriter, zlib"
tools: "castor"
coverage: "xdebug"

- name: "Checkout code"
@@ -30,4 +31,4 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute Infection"
run: "make ci-mu"
run: "castor infect"
24 changes: 13 additions & 11 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ jobs:
with:
php-version: "8.3"
coverage: "none"
tools: "castor"

- name: "Checkout code"
uses: "actions/checkout@v4"
@@ -42,7 +43,7 @@ jobs:
dependency-versions: "highest"

- name: "Check source code for syntax errors"
run: "composer exec -- parallel-lint src/ tests/"
run: "castor lint"

php_tests:
name: "2️⃣ Unit and functional tests"
@@ -66,6 +67,7 @@ jobs:
with:
php-version: "${{ matrix.php-version }}"
extensions: "ctype, curl, dom, json, libxml, mbstring, openssl, phar, simplexml, sodium, tokenizer, xml, xmlwriter, zlib"
tools: "castor"
coverage: "xdebug"

- name: "Checkout code"
@@ -80,10 +82,7 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute tests (PHP)"
run: "make ci-cc"

- name: "Fix code coverage paths"
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
run: "castor test"

js_tests:
name: "2️⃣ JS tests"
@@ -103,6 +102,7 @@ jobs:
with:
php-version: "${{ matrix.php-version }}"
extensions: "ctype, curl, dom, json, libxml, mbstring, openssl, phar, simplexml, sodium, tokenizer, xml, xmlwriter, zlib"
tools: "castor"
coverage: "xdebug"

- name: "Checkout code"
@@ -117,7 +117,7 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute tests (JS)"
run: "make js"
run: "castor js"

static_analysis:
name: "3️⃣ Static Analysis"
@@ -131,6 +131,7 @@ jobs:
with:
php-version: "8.3"
extensions: "ctype, curl, dom, json, libxml, mbstring, openssl, phar, simplexml, sodium, tokenizer, xml, xmlwriter, zlib"
tools: "castor"
coverage: "none"

- name: "Checkout code"
@@ -149,7 +150,7 @@ jobs:
run: "composer dump-autoload --optimize --strict-psr"

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

coding_standards:
name: "4️⃣ Coding Standards"
@@ -163,6 +164,7 @@ jobs:
with:
php-version: "8.3"
extensions: "ctype, curl, dom, json, libxml, mbstring, openssl, phar, simplexml, sodium, tokenizer, xml, xmlwriter, zlib"
tools: "castor"
coverage: "none"

- name: "Checkout code"
@@ -181,11 +183,10 @@ jobs:
composer-options: "--optimize-autoloader"

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

- name: "Deptrac"
run: |
vendor/bin/deptrac analyse --fail-on-uncovered --no-cache
run: "castor deptrac"

rector_checkstyle:
name: "6️⃣ Rector Checkstyle"
@@ -199,6 +200,7 @@ jobs:
with:
php-version: "8.3"
extensions: "ctype, curl, dom, json, libxml, mbstring, openssl, phar, simplexml, sodium, tokenizer, xml, xmlwriter, zlib"
tools: "castor"
coverage: "xdebug"

- name: "Checkout code"
@@ -214,7 +216,7 @@ jobs:
composer-options: "--optimize-autoloader"

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

exported_files:
name: "7️⃣ Exported files"
57 changes: 0 additions & 57 deletions Makefile

This file was deleted.

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

declare(strict_types=1);

use Castor\Attribute\AsOption;
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(
#[AsOption(description: 'Fix issues if possible')]
bool $fix = false,
#[AsOption(description: 'Clear cache')]
bool $clearCache = false
): void {
io()->title('Running coding standards check');
$command = ['php', 'vendor/bin/ecs', 'check'];
$environment = [
'XDEBUG_MODE' => 'off',
];
if ($fix) {
$command[] = '--fix';
}
if ($clearCache) {
$command[] = '--clear-cache';
}
run($command, environment: $environment);
}

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

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

$command = ['composer', 'dump-autoload', '--optimize', '--strict-psr'];
run($command, environment: $environment);
}

/**
* @param array<string> $allowedLicenses
*/
#[AsTask(description: 'Check licenses')]
function checkLicenses(
array $allowedLicenses = ['Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause', 'ISC', 'MIT', 'MPL-2.0', 'OSL-3.0']
): void {
io()->title('Checking licenses');
$allowedExceptions = [];
$command = ['composer', 'licenses', '-f', 'json'];
$environment = [
'XDEBUG_MODE' => 'off',
];
$result = run($command, environment: $environment, quiet: true);
if (! $result->isSuccessful()) {
io()->error('Cannot determine licenses');
exit(1);
}
$licenses = json_decode((string) $result->getOutput(), true);
$disallowed = array_filter(
$licenses['dependencies'],
static fn (array $info, $name) => ! in_array($name, $allowedExceptions, true)
&& count(array_diff($info['license'], $allowedLicenses)) === 1,
\ARRAY_FILTER_USE_BOTH
);
$allowed = array_filter(
$licenses['dependencies'],
static fn (array $info, $name) => in_array($name, $allowedExceptions, true)
|| count(array_diff($info['license'], $allowedLicenses)) === 0,
\ARRAY_FILTER_USE_BOTH
);
if (count($disallowed) > 0) {
io()
->table(
['Package', 'License'],
array_map(
static fn ($name, $info) => [$name, implode(', ', $info['license'])],
array_keys($disallowed),
$disallowed
)
);
io()
->error('Disallowed licenses found');
exit(1);
}
io()
->table(
['Package', 'License'],
array_map(
static fn ($name, $info) => [$name, implode(', ', $info['license'])],
array_keys($allowed),
$allowed
)
);
io()
->success('All licenses are allowed');
}

#[AsTask(description: 'Run Rector')]
function rector(
#[AsOption(description: 'Fix issues if possible')]
bool $fix = false,
#[AsOption(description: 'Clear cache')]
bool $clearCache = false
): void {
io()->title('Running Rector');
$command = ['php', 'vendor/bin/rector', 'process', '--ansi'];
if (! $fix) {
$command[] = '--dry-run';
}
if ($clearCache) {
$command[] = '--clear-cache';
}
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}

#[AsTask(description: 'Run Rector')]
function deptrac(): void
{
io()->title('Running Rector');
$command = ['php', 'vendor/bin/deptrac', 'analyse', '--fail-on-uncovered', '--no-cache'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}

#[AsTask(description: 'Run Linter')]
function lint(): void
{
io()->title('Running Linter');
$command = ['composer', 'exec', '--', 'parallel-lint', __DIR__ . '/src/', __DIR__ . '/tests/'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}

#[AsTask(description: 'Run JS tests')]
function js(): void
{
io()->title('Running JS tests');
run(['npm', 'install', '--force']);
run(['npm', 'test']);
}
4 changes: 3 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
@@ -89,5 +89,7 @@
]);

$config->parallel();
$config->paths([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']);
$config->paths(
[__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php', __DIR__ . '/castor.php']
);
};
9 changes: 5 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
@@ -17,8 +17,7 @@

return static function (RectorConfig $config): void {
$config->import(SetList::DEAD_CODE);
$config->import(LevelSetList::UP_TO_PHP_82);
$config->import(SymfonySetList::SYMFONY_60);
$config->import(SymfonySetList::SYMFONY_64);
$config->import(SymfonySetList::SYMFONY_50_TYPES);
$config->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
$config->import(SymfonySetList::SYMFONY_CODE_QUALITY);
@@ -28,8 +27,10 @@
$config->import(DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES);
$config->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
$config->import(PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES);
$config->import(PHPUnitSetList::PHPUNIT_100);
$config->paths([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']);
$config->import(PHPUnitSetList::PHPUNIT_110);
$config->paths(
[__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php', __DIR__ . '/castor.php']
);
$config->skip([
__DIR__ . '/src/symfony/src/DependencyInjection/Configuration.php',
__DIR__ . '/src/symfony/src/Routing/Loader.php',
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in src/symfony/src/Security/Guesser/RequestBodyUserEntityGuesser.php

GitHub Actions / 3️⃣ Static Analysis

Ignored error pattern #^Call to an undefined method Symfony\\Component\\HttpFoundation\\Request\:\:getContentType\(\)\.$# in path /home/runner/work/webauthn-framework/webauthn-framework/src/symfony/src/Security/Guesser/RequestBodyUserEntityGuesser.php was not matched in reported errors.

Check failure on line 1 in src/symfony/src/Security/Guesser/RequestBodyUserEntityGuesser.php

GitHub Actions / 3️⃣ Static Analysis

Ignored error pattern #^Call to function method_exists\(\) with Symfony\\Component\\HttpFoundation\\Request and 'getContentTypeFormat' will always evaluate to true\.$# in path /home/runner/work/webauthn-framework/webauthn-framework/src/symfony/src/Security/Guesser/RequestBodyUserEntityGuesser.php was not matched in reported errors.

declare(strict_types=1);

@@ -27,10 +27,7 @@

public function findUserEntity(Request $request): PublicKeyCredentialUserEntity
{
$format = method_exists(
$request,
'getContentTypeFormat'
) ? $request->getContentTypeFormat() : $request->getContentType();
$format = $request->getContentTypeFormat();
$format === 'json' || throw InvalidDataException::create($format, 'Only JSON content type allowed');
$content = $request->getContent();

Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@
use Webauthn\PublicKeyCredentialRequestOptions;
use Webauthn\PublicKeyCredentialSource;

final class CheckClientDataCollectorType implements CeremonyStep
final readonly class CheckClientDataCollectorType implements CeremonyStep
{
private readonly ClientDataCollectorManager $clientDataCollectorManager;
private ClientDataCollectorManager $clientDataCollectorManager;

public function __construct(
null|ClientDataCollectorManager $clientDataCollectorManager = null,
4 changes: 2 additions & 2 deletions src/webauthn/src/CeremonyStep/CheckSignature.php
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@
use Webauthn\Util\CoseSignatureFixer;
use function is_array;

final class CheckSignature implements CeremonyStep
final readonly class CheckSignature implements CeremonyStep
{
private readonly Manager $algorithmManager;
private Manager $algorithmManager;

public function __construct(
null|Manager $algorithmManager = null,

0 comments on commit a7dbc24

Please sign in to comment.