-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add possibility to downgrade releases
- Loading branch information
1 parent
a38bf93
commit bd85f72
Showing
8 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
*.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 | ||
phpstan-baseline.php export-ignore | ||
rector-downgrade.php export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,98 @@ 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 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Create release | ||
uses: actions/create-release@latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | ||
uses: crazy-max/ghaction-github-release@v2 | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: ${{ github.ref }} | ||
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: Setup PHP ${{ env.TARGET_PHP_VERSION }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ env.TARGET_PHP_VERSION }} | ||
coverage: none | ||
env: | ||
COMPOSER_TOKEN: ${{ secrets.RELEASE_TOKEN }} | ||
|
||
- 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@v4 | ||
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: [email protected] | ||
add_options: '-u' | ||
create_branch: true | ||
|
||
- name: Delete branch | ||
run: | | ||
git switch ${{ env.DEFAULT_BRANCH }} | ||
git branch -D ${{ steps.branch_name.outputs.BRANCH }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) 2023 CodeIgniter Foundation <[email protected]> | ||
* | ||
* 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\FunctionLike\DowngradeMixedTypeDeclarationRector; | ||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector; | ||
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(DowngradeNonCapturingCatchesRector::class); | ||
$config->rule(DowngradePropertyPromotionRector::class); | ||
$config->rule(DowngradeTrailingCommasInParamUseRector::class); | ||
$config->rule(DowngradeMixedTypeDeclarationRector::class); | ||
$config->rule(DowngradeUnionTypeDeclarationRector::class); | ||
$config->rule(DowngradeUnionTypeTypedPropertyRector::class); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) 2023 CodeIgniter Foundation <[email protected]> | ||
* | ||
* 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) 2023 CodeIgniter Foundation <[email protected]> | ||
* | ||
* 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<int, string> | ||
*/ | ||
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.'); | ||
} | ||
} | ||
} |