From 13b4a07c8b1a340d84925fa96ab47070f6c9ca2d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 17 Feb 2024 01:10:32 +0800 Subject: [PATCH] Remove downgrade hacks --- .gitattributes | 2 - .github/workflows/release.yml | 77 ------------------------------ .github/workflows/test-phpunit.yml | 12 +---- .php-cs-fixer.dist.php | 3 -- bin/rector-downgrade.php | 48 ------------------- bin/transform-source | 26 ---------- composer.json | 8 ++-- src/ComposerJsonRewriter.php | 49 ------------------- 8 files changed, 4 insertions(+), 221 deletions(-) delete mode 100644 bin/rector-downgrade.php delete mode 100644 bin/transform-source delete mode 100644 src/ComposerJsonRewriter.php diff --git a/.gitattributes b/.gitattributes index dcc2486..1a36cc4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,11 @@ *.php text eol=lf .github/ export-ignore -bin/ export-ignore tests/ export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore .php-cs-fixer.dist.php export-ignore -src/ComposerJsonRewriter.php export-ignore src/ComposerScripts.php export-ignore phpunit.dist.xml export-ignore phpstan.neon.dist export-ignore diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index be8bb94..79a0bbb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,12 +5,6 @@ on: tags: - '**' -env: - COMPOSER_ROOT_VERSION: '1.x-dev' - DEFAULT_BRANCH: '1.x' - TARGET_PHP_VERSION: '7.4' - TARGET_PHP_VERSION_ID: 70400 - jobs: build: name: Create a release @@ -26,74 +20,3 @@ jobs: token: ${{ secrets.RELEASE_TOKEN }} draft: true prerelease: false - - build_downgraded_release: - name: Build release for lower PHP version - runs-on: ubuntu-latest - needs: build - timeout-minutes: 10 - - permissions: - # Give the default GITHUB_TOKEN write permission to commit and push the - # added or changed files to the repository. - contents: write - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup PHP 8.1 - uses: shivammathur/setup-php@v2 - with: - php-version: '8.1' - coverage: none - env: - COMPOSER_TOKEN: ${{ secrets.RELEASE_TOKEN }} - - - name: Get branch name - id: branch_name - run: echo "BRANCH=build-downgrade-to-${{ env.TARGET_PHP_VERSION_ID }}" >> $GITHUB_OUTPUT - - - name: Install dependencies - run: composer update --ansi - - - name: Downgrade src - run: php bin/transform-source ${{ env.TARGET_PHP_VERSION_ID }} - - - name: Run lint on src - run: vendor/bin/parallel-lint src --colors --show-deprecated - - - name: Get tag for downgraded release - id: tag-downgraded - run: echo "${{ format('DOWNGRADED_TAG={0}.{1}', github.ref_name, env.TARGET_PHP_VERSION_ID) }}" >> $GITHUB_OUTPUT - - - name: Import GPG signing information - uses: crazy-max/ghaction-import-gpg@v6 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.PASSPHRASE }} - git_config_global: true - git_user_signingkey: true - git_commit_gpgsign: true - git_tag_gpgsign: true - - - name: Commit and tag - uses: stefanzweifel/git-auto-commit-action@v5 - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - with: - commit_message: 'Release PHPStan CodeIgniter to target PHP ${{ env.TARGET_PHP_VERSION }}' - branch: ${{ steps.branch_name.outputs.BRANCH }} - tagging_message: ${{ steps.tag-downgraded.outputs.DOWNGRADED_TAG }} - commit_options: '--gpg-sign' - commit_user_name: paulbalandan - commit_user_email: paulbalandan@gmail.com - add_options: '-u' - create_branch: true - - - name: Delete local and remote branches - run: | - git switch ${{ env.DEFAULT_BRANCH }} - git branch -D ${{ steps.branch_name.outputs.BRANCH }} - git push origin -d ${{ steps.branch_name.outputs.BRANCH }} - git branch -a diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml index eed5c77..4abc6bb 100644 --- a/.github/workflows/test-phpunit.yml +++ b/.github/workflows/test-phpunit.yml @@ -20,14 +20,10 @@ on: - 'composer.json' - 'phpunit.dist.xml' -env: - TARGET_PHP_VERSION: '7.4' - TARGET_PHP_VERSION_ID: 70400 - jobs: extension-tests: name: PHPUnit Extension Tests [PHP ${{ matrix.php-version }}] - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false @@ -66,11 +62,5 @@ jobs: - name: Install dependencies run: composer update --ansi - - name: Downgrade src - run: php bin/transform-source ${{ env.TARGET_PHP_VERSION_ID }} - - - name: Run lint on src - run: vendor/bin/parallel-lint src --colors --show-deprecated - - name: Run Extension Tests run: vendor/bin/phpunit --no-coverage diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 08940ec..587517c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -20,14 +20,11 @@ $finder = Finder::create() ->files() ->in([ - __DIR__ . '/bin', __DIR__ . '/src', __DIR__ . '/tests', ]) ->append([ __FILE__, - __DIR__ . '/bin/parse-php-version', - __DIR__ . '/bin/transform-source', ]); $overrides = [ diff --git a/bin/rector-downgrade.php b/bin/rector-downgrade.php deleted file mode 100644 index d6f1c03..0000000 --- a/bin/rector-downgrade.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -use Rector\Config\RectorConfig; -use Rector\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector; -use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector; -use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector; -use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector; -use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector; -use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector; -use Rector\DowngradePhp80\Rector\NullsafeMethodCall\DowngradeNullsafeToTernaryOperatorRector; -use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector; -use Rector\DowngradePhp81\Rector\FunctionLike\DowngradePureIntersectionTypeRector; -use Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector; - -return static function (RectorConfig $config): void { - $targetPhpVersionId = (int) getenv('TARGET_PHP_VERSION_ID'); - - $config->paths([__DIR__ . '/../src']); - $config->phpVersion($targetPhpVersionId); - $config->disableParallel(); - - if ($targetPhpVersionId < 80100) { - $config->rule(DowngradePureIntersectionTypeRector::class); - $config->rule(DowngradeReadonlyPropertyRector::class); - } - - if ($targetPhpVersionId < 80000) { - $config->rule(DowngradeMatchToSwitchRector::class); - $config->rule(DowngradeMixedTypeDeclarationRector::class); - $config->rule(DowngradeNonCapturingCatchesRector::class); - $config->rule(DowngradeNullsafeToTernaryOperatorRector::class); - $config->rule(DowngradePropertyPromotionRector::class); - $config->rule(DowngradeTrailingCommasInParamUseRector::class); - $config->rule(DowngradeUnionTypeDeclarationRector::class); - $config->rule(DowngradeUnionTypeTypedPropertyRector::class); - } -}; diff --git a/bin/transform-source b/bin/transform-source deleted file mode 100644 index 42aac52..0000000 --- a/bin/transform-source +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env php - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -require __DIR__ . '/../vendor/autoload.php'; - -use CodeIgniter\PHPStan\ComposerJsonRewriter; - -$targetPhpVersionId = (int) $argv[1]; - -putenv("TARGET_PHP_VERSION_ID={$targetPhpVersionId}"); -echo 'TARGET_PHP_VERSION_ID: ' . $targetPhpVersionId . PHP_EOL . PHP_EOL; - -(new ComposerJsonRewriter())->rewriteUsingPhp($targetPhpVersionId); -passthru('php vendor/bin/rector process -c bin/rector-downgrade.php --ansi --no-diffs'); -passthru('php vendor/bin/php-cs-fixer fix -v --ansi'); diff --git a/composer.json b/composer.json index cf479ba..4153d94 100644 --- a/composer.json +++ b/composer.json @@ -30,15 +30,13 @@ "require-dev": { "codeigniter/coding-standard": "^1.7", "codeigniter4/shield": "^1.0", - "friendsofphp/php-cs-fixer": "^3.20", - "nexusphp/cs-config": "^3.12", - "php-parallel-lint/php-parallel-lint": "^1.3", + "friendsofphp/php-cs-fixer": "^3.49", + "nexusphp/cs-config": "^3.21", "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "^10.2", - "rector/rector": "^1.0.0" + "phpunit/phpunit": "^10.5" }, "repositories": [ { diff --git a/src/ComposerJsonRewriter.php b/src/ComposerJsonRewriter.php deleted file mode 100644 index ea381ba..0000000 --- a/src/ComposerJsonRewriter.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter\PHPStan; - -use RuntimeException; - -/** - * @internal - */ -final class ComposerJsonRewriter -{ - private string $composerJson = __DIR__ . '/../composer.json'; - - /** - * @var array - */ - private array $replacements = [ - 70400 => '^7.4 || ^8.0', - 80000 => '^8.0', - ]; - - public function rewriteUsingPhp(int $targetPhpVersionId): void - { - if (! isset($this->replacements[$targetPhpVersionId])) { - throw new RuntimeException(sprintf('Rewriting composer.json to PHP_VERSION_ID %d is not supported.', $targetPhpVersionId)); - } - - $composerJson = json_decode((string) @file_get_contents($this->composerJson), true, 512, JSON_THROW_ON_ERROR); - - $composerJson['require']['php'] = $this->replacements[$targetPhpVersionId]; - - $composerJson = json_encode($composerJson, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES) . "\n"; - - if (file_put_contents($this->composerJson, $composerJson) === false) { - throw new RuntimeException('Rewriting to composer.json failed.'); - } - } -}