From 08f3d30aa486c55a39a51b3d0d7762ef768c09ea Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 4 Jan 2022 14:51:10 +0800 Subject: [PATCH] Auto-review required dependency matching --- .github/workflows/test-autoreview.yml | 49 +++++++++++++++++++++++++ .github/workflows/test-phpunit.yml | 2 +- composer.json | 1 + phpunit.xml.dist | 3 ++ tests/AutoReview/ComposerJsonTest.php | 51 +++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-autoreview.yml create mode 100644 tests/AutoReview/ComposerJsonTest.php diff --git a/.github/workflows/test-autoreview.yml b/.github/workflows/test-autoreview.yml new file mode 100644 index 000000000000..28f1230b0073 --- /dev/null +++ b/.github/workflows/test-autoreview.yml @@ -0,0 +1,49 @@ +name: Automatic Code Review + +on: + pull_request: + paths: + - composer.json + - spark + - '**.php' + - .github/workflows/test-autoreview.yml + push: + paths: + - composer.json + - spark + - '**.php' + - .github/workflows/test-autoreview.yml + +jobs: + auto-review-tests: + name: Automatic Code Review + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + coverage: none + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer update --ansi + env: + COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} + + - name: Run AutoReview Tests + run: vendor/bin/phpunit --color=always --group=auto-review --no-coverage diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml index 2fb7f6d66dd1..50809c95abda 100644 --- a/.github/workflows/test-phpunit.yml +++ b/.github/workflows/test-phpunit.yml @@ -126,7 +126,7 @@ jobs: run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV - name: Test with PHPUnit - run: script -e -c "vendor/bin/phpunit --color=always" + run: script -e -c "vendor/bin/phpunit --color=always --exclude-group=auto-review" env: DB: ${{ matrix.db-platforms }} TERM: xterm-256color diff --git a/composer.json b/composer.json index 6799259fdf62..ecf61daa3d80 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "autoload-dev": { "psr-4": { "CodeIgniter\\": "tests/system/", + "CodeIgniter\\AutoReview\\": "tests/AutoReview/", "Utils\\": "utils/" } }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index de2f81aae07e..6965a686f8e2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -36,6 +36,9 @@ + + ./tests/AutoReview + ./tests/system ./tests/system/Database diff --git a/tests/AutoReview/ComposerJsonTest.php b/tests/AutoReview/ComposerJsonTest.php new file mode 100644 index 000000000000..752f9723e0ed --- /dev/null +++ b/tests/AutoReview/ComposerJsonTest.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\AutoReview; + +use JsonException; +use PHPUnit\Framework\TestCase; + +/** + * @internal + * + * @coversNothing + * @group auto-review + */ +final class ComposerJsonTest extends TestCase +{ + public function testFrameworkRequireIsTheSameWithDevRequire(): void + { + $devComposer = $this->getComposerJson(dirname(__DIR__, 2) . '/composer.json'); + $frameworkComposer = $this->getComposerJson(dirname(__DIR__, 2) . '/admin/framework/composer.json'); + + $this->assertSame( + $devComposer['require'], + $frameworkComposer['require'], + 'The framework\'s "require" section is not updated with the main composer.json.' + ); + } + + private function getComposerJson(string $path): array + { + try { + return json_decode((string) file_get_contents($path), true, 512, JSON_THROW_ON_ERROR); + } catch (JsonException $e) { + $this->fail(sprintf( + 'The composer.json at "%s" is not readable or does not exist. Error was "%s".', + clean_path($path), + $e->getMessage() + )); + } + } +}