Skip to content

Commit

Permalink
ci: add rule static asset file must include in split repo (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyPradana authored Sep 14, 2024
1 parent bc15060 commit 2c51864
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
->exclude(__DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'Template')
->append(['.php-cs-fixer.php', 'monorepo-builder.php', 'rector.php', './bin/split-repo.php']);
->append(['.php-cs-fixer.php', 'rector.php', 'split-repo.php', './bin/split-repo.php']);

$rules = [
'@Symfony' => true,
Expand Down
30 changes: 30 additions & 0 deletions bin/split-repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public function validate(): int
$progressbar->maks = count($paths);

foreach ($paths as $path) {
$validate_assets = $this->validateAssetsFile(dirname(__DIR__), $path);
if (false === empty($validate_assets)) {
foreach ($validate_assets as $error) {
$progressbar->complete = static fn (): string => (string) fail($error);
$progressbar->current = $progressbar->maks + 1;
$progressbar->tick();

return 1;
}
}

if (false === $this->validateComposerVersion($composer_path = dirname(__DIR__) . $path . 'composer.json', $packages, $version)) {
$progressbar->complete = static fn (): string => (string) fail('failed!');
$progressbar->current = $progressbar->maks + 1;
Expand Down Expand Up @@ -89,6 +100,25 @@ private function validateComposerVersion(string $path, array $packages, string $
return true;
}

/**
* Validate static asset file must include in split repo.
*
* @return string[]
*/
private function validateAssetsFile(string $base, string $path): array
{
$errors = [];
if (false === file_exists("{$base}{$path}LICENSE")) {
$errors[] = "license not found in {$path}.";
}

if (false === file_exists("{$base}{$path}.github/workflows/close-pull-request.yml")) {
$errors[] = "close pr github workflow not found in {$path}.";
}

return $errors;
}

/**
* Load split configuration.
*
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
level: 6
paths:
- bin
- src

reportUnmatchedIgnoredErrors: true
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/bin',
__DIR__ . '/src',
]);

Expand Down
32 changes: 16 additions & 16 deletions split-repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
declare(strict_types=1);

return [
'tag_version' => "0.35.6",
'tag_version' => '0.35.6',
'split_repositorys' => [
'sonypradana/cache' => '/src/System/Cache/',
'sonypradana/cache' => '/src/System/Cache/',
'sonypradana/collection' => '/src/System/Collection/',
'sonypradana/console' => '/src/System/Console/',
'sonypradana/container' => '/src/System/Container/',
'sonypradana/cron' => '/src/System/Cron/',
'sonypradana/database' => '/src/System/Database/',
'sonypradana/file' => '/src/System/File/',
'sonypradana/http' => '/src/System/Http/',
'sonypradana/macroable' => '/src/System/Macroable/',
'sonypradana/router' => '/src/System/Router/',
'sonypradana/security' => '/src/System/Security/',
'sonypradana/support' => '/src/System/Support/',
'sonypradana/template' => '/src/System/Template/',
'sonypradana/text' => '/src/System/Text/',
'sonypradana/time' => '/src/System/Time/',
'sonypradana/view' => '/src/System/View/',
'sonypradana/console' => '/src/System/Console/',
'sonypradana/container' => '/src/System/Container/',
'sonypradana/cron' => '/src/System/Cron/',
'sonypradana/database' => '/src/System/Database/',
'sonypradana/file' => '/src/System/File/',
'sonypradana/http' => '/src/System/Http/',
'sonypradana/macroable' => '/src/System/Macroable/',
'sonypradana/router' => '/src/System/Router/',
'sonypradana/security' => '/src/System/Security/',
'sonypradana/support' => '/src/System/Support/',
'sonypradana/template' => '/src/System/Template/',
'sonypradana/text' => '/src/System/Text/',
'sonypradana/time' => '/src/System/Time/',
'sonypradana/view' => '/src/System/View/',
],
];
13 changes: 13 additions & 0 deletions src/System/Cache/.github/workflows/close-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Close Pull Request

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: "Thank you for your pull request. However, this repository is a read-only sub-split. Please submit your PR to https://github.com/sonypradana/php-library instead. Thanks!"
21 changes: 21 additions & 0 deletions src/System/Cache/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2024 Angger Pradana

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 comments on commit 2c51864

Please sign in to comment.