From b08c28aee8358538c3849a418836b9b0ac348cb8 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 21 Jul 2023 14:14:33 +0800 Subject: [PATCH 1/6] Add auto-review workflow --- .github/workflows/test-autoreview.yml | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/.github/workflows/test-autoreview.yml b/.github/workflows/test-autoreview.yml index dfe4892bdebe..79d9bd876615 100644 --- a/.github/workflows/test-autoreview.yml +++ b/.github/workflows/test-autoreview.yml @@ -29,3 +29,81 @@ jobs: php-version: '8.1' job-id: auto-review-tests group-name: AutoReview + + composer-normalize-tests: + name: Check normalized composer.json + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + + - name: Install composer normalize + run: | + composer global require ergebnis/composer-normalize --no-interaction + composer global config allow-plugins.ergebnis/composer-normalize true --no-interaction + + - name: Run on root composer.json + id: normalize-root-composer + if: ${{ always() }} + run: | + echo "ROOT_COMPOSER_RESULT<> $GITHUB_OUTPUT + echo "$(composer normalize)" >> $GITHUB_OUTPUT + echo "RCR" >> $GITHUB_OUTPUT + + - name: Run on framework composer.json + id: normalize-framework-composer + if: ${{ always() }} + working-directory: admin/framework + run: | + echo "FRAMEWORK_COMPOSER_RESULT<> $GITHUB_OUTPUT + echo "$(composer normalize)" >> $GITHUB_OUTPUT + echo "FCR" >> $GITHUB_OUTPUT + + - name: Run on starter composer.json + id: normalize-starter-composer + if: ${{ always() }} + working-directory: admin/starter + run: | + echo "STARTER_COMPOSER_RESULT<> $GITHUB_OUTPUT + echo "$(composer normalize)" >> $GITHUB_OUTPUT + echo "SCR" >> $GITHUB_OUTPUT + + - name: Analyse normalization results + run: | + if [[ '${{ steps.normalize-root-composer.conclusion }}' == 'failure' ]]; then + echo 'Normalization of root composer.json encountered a problem.'; + echo 'Please run it locally: `composer normalize`'; + exit 1; + fi + + if [[ ${{ contains(steps.normalize-root-composer.outputs.ROOT_COMPOSER_RESULT, 'Successfully normalized') }} == true ]]; then + echo 'Root composer.json is not yet normalized.'; + exit 1; + fi + + if [[ '${{ steps.normalize-framework-composer.conclusion }}' == 'failure' ]]; then + echo 'Normalization of framework composer.json encountered a problem.'; + echo 'Please run it locally: `composer normalize -d admin/framework`'; + exit 1; + fi + + if [[ ${{ contains(steps.normalize-framework-composer.outputs.FRAMEWORK_COMPOSER_RESULT, 'Successfully normalized') }} == true ]]; then + echo 'Framework composer.json is not yet normalized.'; + exit 1; + fi + + if [[ '${{ steps.normalize-starter-composer.conclusion }}' == 'failure' ]]; then + echo 'Normalization of starter composer.json encountered a problem.'; + echo 'Please run it locally: `composer normalize -d admin/framework`'; + exit 1; + fi + + if [[ ${{ contains(steps.normalize-starter-composer.outputs.STARTER_COMPOSER_RESULT, 'Successfully normalized') }} == true ]]; then + echo 'Starter composer.json is not yet normalized.'; + exit 1; + fi From bd6a8e3e28c2d1dbf409af335450aabd0fc9a81e Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 21 Jul 2023 17:53:34 +0800 Subject: [PATCH 2/6] Run composer normalize --- admin/framework/composer.json | 50 ++++++++++++------------- admin/starter/composer.json | 24 ++++++------ composer.json | 70 +++++++++++++++++------------------ 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/admin/framework/composer.json b/admin/framework/composer.json index 905e123cd89a..f93daa275b1d 100644 --- a/admin/framework/composer.json +++ b/admin/framework/composer.json @@ -1,9 +1,14 @@ { "name": "codeigniter4/framework", - "type": "project", "description": "The CodeIgniter framework v4", - "homepage": "https://codeigniter.com", "license": "MIT", + "type": "project", + "homepage": "https://codeigniter.com", + "support": { + "forum": "https://forum.codeigniter.com/", + "source": "https://github.com/codeigniter4/CodeIgniter4", + "slack": "https://codeigniterchat.slack.com" + }, "require": { "php": "^7.4 || ^8.0", "ext-intl": "*", @@ -13,10 +18,10 @@ "psr/log": "^1.1" }, "require-dev": { - "kint-php/kint": "^5.0.4", "codeigniter/coding-standard": "^1.5", "fakerphp/faker": "^1.9", "friendsofphp/php-cs-fixer": "3.13.0", + "kint-php/kint": "^5.0.4", "mikey179/vfsstream": "^1.6", "nexusphp/cs-config": "^3.6", "phpunit/phpunit": "^9.1", @@ -24,28 +29,23 @@ }, "suggest": { "ext-curl": "If you use CURLRequest class", - "ext-imagick": "If you use Image class ImageMagickHandler", - "ext-gd": "If you use Image class GDHandler", + "ext-dom": "If you use TestResponse", "ext-exif": "If you run Image class tests", - "ext-simplexml": "If you format XML", + "ext-fileinfo": "Improves mime type detection for files", + "ext-gd": "If you use Image class GDHandler", + "ext-imagick": "If you use Image class ImageMagickHandler", + "ext-libxml": "If you use TestResponse", + "ext-memcache": "If you use Cache class MemcachedHandler with Memcache", + "ext-memcached": "If you use Cache class MemcachedHandler with Memcached", "ext-mysqli": "If you use MySQL", "ext-oci8": "If you use Oracle Database", "ext-pgsql": "If you use PostgreSQL", - "ext-sqlsrv": "If you use SQL Server", - "ext-sqlite3": "If you use SQLite3", - "ext-memcache": "If you use Cache class MemcachedHandler with Memcache", - "ext-memcached": "If you use Cache class MemcachedHandler with Memcached", + "ext-readline": "Improves CLI::input() usability", "ext-redis": "If you use Cache class RedisHandler", - "ext-dom": "If you use TestResponse", - "ext-libxml": "If you use TestResponse", - "ext-xdebug": "If you use CIUnitTestCase::assertHeaderEmitted()", - "ext-fileinfo": "Improves mime type detection for files", - "ext-readline": "Improves CLI::input() usability" - }, - "config": { - "optimize-autoloader": true, - "preferred-install": "dist", - "sort-packages": true + "ext-simplexml": "If you format XML", + "ext-sqlite3": "If you use SQLite3", + "ext-sqlsrv": "If you use SQL Server", + "ext-xdebug": "If you use CIUnitTestCase::assertHeaderEmitted()" }, "autoload": { "psr-4": { @@ -55,12 +55,12 @@ "**/Database/Migrations/**" ] }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, "scripts": { "test": "phpunit" - }, - "support": { - "forum": "https://forum.codeigniter.com/", - "source": "https://github.com/codeigniter4/CodeIgniter4", - "slack": "https://codeigniterchat.slack.com" } } diff --git a/admin/starter/composer.json b/admin/starter/composer.json index cec23ba1987e..082d7b648c25 100644 --- a/admin/starter/composer.json +++ b/admin/starter/composer.json @@ -1,9 +1,14 @@ { "name": "codeigniter4/appstarter", - "type": "project", "description": "CodeIgniter4 starter app", - "homepage": "https://codeigniter.com", "license": "MIT", + "type": "project", + "homepage": "https://codeigniter.com", + "support": { + "forum": "https://forum.codeigniter.com/", + "source": "https://github.com/codeigniter4/CodeIgniter4", + "slack": "https://codeigniterchat.slack.com" + }, "require": { "php": "^7.4 || ^8.0", "codeigniter4/framework": "^4.0" @@ -13,11 +18,6 @@ "mikey179/vfsstream": "^1.6", "phpunit/phpunit": "^9.1" }, - "config": { - "optimize-autoloader": true, - "preferred-install": "dist", - "sort-packages": true - }, "autoload": { "exclude-from-classmap": [ "**/Database/Migrations/**" @@ -28,12 +28,12 @@ "Tests\\Support\\": "tests/_support" } }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, "scripts": { "test": "phpunit" - }, - "support": { - "forum": "https://forum.codeigniter.com/", - "source": "https://github.com/codeigniter4/CodeIgniter4", - "slack": "https://codeigniterchat.slack.com" } } diff --git a/composer.json b/composer.json index 981db0694265..53fc1ef47018 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,14 @@ { "name": "codeigniter4/codeigniter4", - "type": "project", "description": "The CodeIgniter framework v4", - "homepage": "https://codeigniter.com", "license": "MIT", + "type": "project", + "homepage": "https://codeigniter.com", + "support": { + "forum": "https://forum.codeigniter.com/", + "source": "https://github.com/codeigniter4/CodeIgniter4", + "slack": "https://codeigniterchat.slack.com" + }, "require": { "php": "^7.4 || ^8.0", "ext-intl": "*", @@ -13,9 +18,9 @@ "psr/log": "^1.1" }, "require-dev": { - "kint-php/kint": "^5.0.4", "codeigniter/coding-standard": "^1.5", "fakerphp/faker": "^1.9", + "kint-php/kint": "^5.0.4", "mikey179/vfsstream": "^1.6", "nexusphp/cs-config": "^3.6", "nexusphp/tachycardia": "^1.0", @@ -29,33 +34,23 @@ }, "suggest": { "ext-curl": "If you use CURLRequest class", - "ext-imagick": "If you use Image class ImageMagickHandler", - "ext-gd": "If you use Image class GDHandler", + "ext-dom": "If you use TestResponse", "ext-exif": "If you run Image class tests", - "ext-simplexml": "If you format XML", + "ext-fileinfo": "Improves mime type detection for files", + "ext-gd": "If you use Image class GDHandler", + "ext-imagick": "If you use Image class ImageMagickHandler", + "ext-libxml": "If you use TestResponse", + "ext-memcache": "If you use Cache class MemcachedHandler with Memcache", + "ext-memcached": "If you use Cache class MemcachedHandler with Memcached", "ext-mysqli": "If you use MySQL", "ext-oci8": "If you use Oracle Database", "ext-pgsql": "If you use PostgreSQL", - "ext-sqlsrv": "If you use SQL Server", - "ext-sqlite3": "If you use SQLite3", - "ext-memcache": "If you use Cache class MemcachedHandler with Memcache", - "ext-memcached": "If you use Cache class MemcachedHandler with Memcached", + "ext-readline": "Improves CLI::input() usability", "ext-redis": "If you use Cache class RedisHandler", - "ext-dom": "If you use TestResponse", - "ext-libxml": "If you use TestResponse", - "ext-xdebug": "If you use CIUnitTestCase::assertHeaderEmitted()", - "ext-fileinfo": "Improves mime type detection for files", - "ext-readline": "Improves CLI::input() usability" - }, - "config": { - "optimize-autoloader": true, - "preferred-install": "dist", - "sort-packages": true - }, - "extra": { - "branch-alias": { - "dev-develop": "4.x-dev" - } + "ext-simplexml": "If you format XML", + "ext-sqlite3": "If you use SQLite3", + "ext-sqlsrv": "If you use SQL Server", + "ext-xdebug": "If you use CIUnitTestCase::assertHeaderEmitted()" }, "autoload": { "psr-4": { @@ -71,6 +66,16 @@ "Utils\\": "utils/" } }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-develop": "4.x-dev" + } + }, "scripts": { "post-update-cmd": [ "CodeIgniter\\ComposerScripts::postUpdate", @@ -81,8 +86,6 @@ "bash -c \"XDEBUG_MODE=off phpstan analyse\"", "rector process --dry-run" ], - "sa": "@analyze", - "test": "phpunit", "cs": [ "Composer\\Config::disableProcessTimeout", "php-cs-fixer fix --ansi --verbose --dry-run --diff --config=.php-cs-fixer.user-guide.php", @@ -95,17 +98,14 @@ "php-cs-fixer fix --ansi --verbose --diff --config=.php-cs-fixer.no-header.php", "php-cs-fixer fix --ansi --verbose --diff" ], - "style": "@cs-fix" + "sa": "@analyze", + "style": "@cs-fix", + "test": "phpunit" }, "scripts-descriptions": { "analyze": "Run static analysis", - "test": "Run unit tests", "cs": "Check the coding style", - "cs-fix": "Fix the coding style" - }, - "support": { - "forum": "https://forum.codeigniter.com/", - "source": "https://github.com/codeigniter4/CodeIgniter4", - "slack": "https://codeigniterchat.slack.com" + "cs-fix": "Fix the coding style", + "test": "Run unit tests" } } From 3ef4d42004f5ec39ee83093e15a4b78fbada8289 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 25 Jul 2023 11:35:31 +0800 Subject: [PATCH 3/6] Require composer-normalize locally --- .github/workflows/test-autoreview.yml | 6 ++---- composer.json | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-autoreview.yml b/.github/workflows/test-autoreview.yml index 79d9bd876615..6753b7ebc419 100644 --- a/.github/workflows/test-autoreview.yml +++ b/.github/workflows/test-autoreview.yml @@ -42,10 +42,8 @@ jobs: with: php-version: '8.1' - - name: Install composer normalize - run: | - composer global require ergebnis/composer-normalize --no-interaction - composer global config allow-plugins.ergebnis/composer-normalize true --no-interaction + - name: Install dependencies + run: composer update - name: Run on root composer.json id: normalize-root-composer diff --git a/composer.json b/composer.json index 53fc1ef47018..f06a8df04033 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ }, "require-dev": { "codeigniter/coding-standard": "^1.5", + "ergebnis/composer-normalize": "^2.28", "fakerphp/faker": "^1.9", "kint-php/kint": "^5.0.4", "mikey179/vfsstream": "^1.6", @@ -67,6 +68,9 @@ } }, "config": { + "allow-plugins": { + "ergebnis/composer-normalize": true + }, "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true From 58dc6cdcd537877be975caf1f13aaf36c350a2f0 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 25 Jul 2023 12:01:16 +0800 Subject: [PATCH 4/6] Add test for config --- tests/system/AutoReview/ComposerJsonTest.php | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/system/AutoReview/ComposerJsonTest.php b/tests/system/AutoReview/ComposerJsonTest.php index dc9ad26b9ef8..e4abf910c492 100644 --- a/tests/system/AutoReview/ComposerJsonTest.php +++ b/tests/system/AutoReview/ComposerJsonTest.php @@ -73,12 +73,20 @@ public function testFrameworkSuggestIsTheSameWithDevSuggest(): void public function testFrameworkConfigIsTheSameWithDevSuggest(): void { - $this->checkFramework('config'); + $this->checkConfig( + $this->devComposer['config'], + $this->frameworkComposer['config'], + 'framework' + ); } public function testStarterConfigIsTheSameWithDevSuggest(): void { - $this->checkStarter('config'); + $this->checkConfig( + $this->devComposer['config'], + $this->starterComposer['config'], + 'starter' + ); } private function checkFramework(string $section): void @@ -99,6 +107,25 @@ private function checkStarter(string $section): void ); } + private function checkConfig(array $fromMain, array $fromComponent, string $component): void + { + foreach ($fromMain as $key => $expectedValue) { + if (! isset($fromComponent[$key])) { + $this->addToAssertionCount(1); + + continue; + } + + $actualValue = $fromComponent[$key]; + + $this->assertSame($expectedValue, $actualValue, sprintf( + '%s\'s value for config property "%s" is not same with the main composer.json\'s config.', + ucfirst($component), + $key + )); + } + } + private function getComposerJson(string $path): array { try { From d43095542d95c94dec7b0c0cd47dc39a98589dc1 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 25 Jul 2023 13:28:40 +0800 Subject: [PATCH 5/6] refactor ComposerJsonTest --- tests/system/AutoReview/ComposerJsonTest.php | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/system/AutoReview/ComposerJsonTest.php b/tests/system/AutoReview/ComposerJsonTest.php index e4abf910c492..ecc57c028cba 100644 --- a/tests/system/AutoReview/ComposerJsonTest.php +++ b/tests/system/AutoReview/ComposerJsonTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\AutoReview; +use InvalidArgumentException; use JsonException; use PHPUnit\Framework\TestCase; @@ -40,7 +41,7 @@ protected function setUp(): void public function testFrameworkRequireIsTheSameWithDevRequire(): void { - $this->checkFramework('require'); + $this->checkSection('require', 'framework'); } public function testFrameworkRequireDevIsTheSameWithDevRequireDev(): void @@ -68,7 +69,7 @@ public function testFrameworkRequireDevIsTheSameWithDevRequireDev(): void public function testFrameworkSuggestIsTheSameWithDevSuggest(): void { - $this->checkFramework('suggest'); + $this->checkSection('suggest', 'framework'); } public function testFrameworkConfigIsTheSameWithDevSuggest(): void @@ -89,21 +90,25 @@ public function testStarterConfigIsTheSameWithDevSuggest(): void ); } - private function checkFramework(string $section): void + private function checkSection(string $section, string $component): void { - $this->assertSame( - $this->devComposer[$section], - $this->frameworkComposer[$section], - 'The framework\'s "' . $section . '" section is not updated with the main composer.json.' - ); - } + switch (strtolower($component)) { + case 'framework': + $sectionContent = $this->frameworkComposer[$section] ?? null; + break; + + case 'starter': + $sectionContent = $this->starterComposer[$section] ?? null; + break; + + default: + throw new InvalidArgumentException(sprintf('Unknown component: %s.', $component)); + } - private function checkStarter(string $section): void - { $this->assertSame( $this->devComposer[$section], - $this->starterComposer[$section], - 'The starter\'s "' . $section . '" section is not updated with the main composer.json.' + $sectionContent, + sprintf('The %s\'s "%s" section is not updated with the main composer.json', strtolower($component), $section) ); } From fa8059b4d079d26cd0b8bec08bee5358b311163e Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 1 Aug 2023 15:37:38 +0800 Subject: [PATCH 6/6] Fix command --- .github/workflows/test-autoreview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-autoreview.yml b/.github/workflows/test-autoreview.yml index 6753b7ebc419..21f885445b63 100644 --- a/.github/workflows/test-autoreview.yml +++ b/.github/workflows/test-autoreview.yml @@ -97,7 +97,7 @@ jobs: if [[ '${{ steps.normalize-starter-composer.conclusion }}' == 'failure' ]]; then echo 'Normalization of starter composer.json encountered a problem.'; - echo 'Please run it locally: `composer normalize -d admin/framework`'; + echo 'Please run it locally: `composer normalize -d admin/starter`'; exit 1; fi