Skip to content

Commit c97cbf7

Browse files
Add ability to auto downgrade tag release (#92)
Add ability to auto downgrade tag release Co-authored-by: Tomas Votruba <tomas.vot@gmail.com>
1 parent e3f770f commit c97cbf7

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Downgraded Release
2+
3+
# https://tomasvotruba.com/blog/how-to-release-php-81-and-72-package-in-the-same-repository/
4+
# https://github.com/TomasVotruba/cognitive-complexity/blob/main/.github/workflows/downgraded_release.yaml
5+
# https://github.com/symplify/config-transformer/blob/main/.github/workflows/downgraded_release.yaml
6+
7+
on:
8+
push:
9+
tags:
10+
- '*'
11+
12+
jobs:
13+
downgrade_release:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
-
18+
uses: "actions/checkout@v3"
19+
20+
-
21+
uses: "shivammathur/setup-php@v2"
22+
with:
23+
php-version: 8.1
24+
coverage: none
25+
26+
- uses: "ramsey/composer-install@v2"
27+
28+
# downgrade /src to PHP 7.2
29+
- run: vendor/bin/rector process src --config build/rector-downgrade-php-72.php --ansi
30+
- run: vendor/bin/ecs check src --fix --ansi
31+
32+
# copy PHP 7.2 composer
33+
- run: cp build/composer-php-72.json composer.json
34+
35+
# clear the dev files
36+
- run: rm -rf build .github tests stubs easy-ci.php ecs.php phpstan.neon phpunit.xml
37+
38+
# setup git user
39+
-
40+
run: |
41+
git config user.email "action@github.com"
42+
git config user.name "GitHub Action"
43+
44+
# publish to the same repository with a new tag
45+
-
46+
name: "Tag Downgraded Code"
47+
run: |
48+
git commit -a -m "release PHP 7.2 downgraded ${GITHUB_REF#refs/tags/}"
49+
50+
# force push tag, so there is only 1 version
51+
git tag "${GITHUB_REF#refs/tags/}" --force
52+
git push origin "${GITHUB_REF#refs/tags/}" --force

build/composer-php-72.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "driftingly/rector-laravel",
3+
"type": "rector-extension",
4+
"license": "MIT",
5+
"description": "Rector upgrades rules for Laravel Framework",
6+
"require": {
7+
"php": "^7.2 || ^8.0"
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"RectorLaravel\\": "src"
12+
}
13+
},
14+
"autoload-dev": {
15+
"classmap": ["stubs"]
16+
},
17+
"minimum-stability": "dev",
18+
"prefer-stable": true
19+
}

build/rector-downgrade-php-72.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\DowngradeLevelSetList;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);
10+
};

src/Rector/StaticCall/RequestStaticValidateToInjectRector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use PhpParser\Node\Expr\StaticCall;
1111
use PhpParser\Node\Expr\Variable;
1212
use PhpParser\Node\Identifier;
13+
use PhpParser\Node\Name\FullyQualified;
14+
use PhpParser\Node\Param;
1315
use PhpParser\Node\Stmt\Class_;
1416
use PhpParser\Node\Stmt\ClassMethod;
1517
use PHPStan\Type\ObjectType;
@@ -88,7 +90,7 @@ public function refactor(Node $node): ?Node
8890

8991
$requestParam = $this->addRequestParameterIfMissing($node, new ObjectType('Illuminate\Http\Request'));
9092

91-
if ($requestParam === null) {
93+
if (! $requestParam instanceof Param) {
9294
return null;
9395
}
9496

@@ -132,7 +134,7 @@ private function shouldSkip(StaticCall|FuncCall $node): bool
132134
return ! $this->isName($node, 'request');
133135
}
134136

135-
private function addRequestParameterIfMissing(Node $node, ObjectType $objectType): ?Node\Param
137+
private function addRequestParameterIfMissing(Node $node, ObjectType $objectType): ?Param
136138
{
137139
$classMethod = $this->betterNodeFinder->findParentType($node, ClassMethod::class);
138140

@@ -148,9 +150,9 @@ private function addRequestParameterIfMissing(Node $node, ObjectType $objectType
148150
return $paramNode;
149151
}
150152

151-
$classMethod->params[] = $paramNode = new Node\Param(new Variable(
153+
$classMethod->params[] = $paramNode = new Param(new Variable(
152154
'request'
153-
), null, new Node\Name\FullyQualified($objectType->getClassName()));
155+
), null, new FullyQualified($objectType->getClassName()));
154156

155157
return $paramNode;
156158
}

0 commit comments

Comments
 (0)