Skip to content

Commit bf9bd55

Browse files
authored
Prepare push repository logic to anywherephp/type-perfect (#75)
* prepare push repository logic * Remove null from Collector TValue generics to fix PHPStan errors The Collector interface already allows returning null from processNode() as a skip signal - null never appears in collected data, so it does not belong in the TValue generic. Newer PHPStan reports destructuring of the collected items as possibly-null because of it.
1 parent fcd4e6b commit bf9bd55

9 files changed

Lines changed: 81 additions & 67 deletions

File tree

.github/workflows/downgraded_release.yaml

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,84 @@ name: Downgraded Release
22

33
on:
44
push:
5+
branches:
6+
- main
57
tags:
6-
# avoid infinite looping, skip tags that ends with ".72"
7-
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches
88
- '*'
99

1010
jobs:
1111
downgrade_release:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: "actions/checkout@v3"
15+
- uses: "actions/checkout@v5"
1616
with:
17-
token: ${{ secrets.WORKFLOWS_TOKEN }}
17+
token: ${{ secrets.WORKFLOWS_TOKEN || github.token }}
1818

1919
-
2020
uses: "shivammathur/setup-php@v2"
2121
with:
22-
php-version: 8.2
22+
php-version: 8.4
2323
coverage: none
2424

25-
# invoke patches
2625
- run: composer install --ansi
2726

28-
# but no dev packages
29-
- run: composer update --no-dev --ansi
30-
31-
# get rector to "rector-local" directory, to avoid downgrading itself in the /vendor
32-
- run: mkdir rector-local
33-
- run: composer require rector/rector:^1.1 --working-dir rector-local --ansi
27+
# downgrade /src to PHP 7.4
28+
- run: vendor/bin/rector process src --config build/rector-downgrade-php-74.php --ansi
29+
- run: vendor/bin/ecs check src --fix --ansi
3430

35-
# downgrade to PHP 7.4
36-
- run: rector-local/vendor/bin/rector process src --config build/rector-downgrade-php-74.php --ansi
31+
# clear the dev files, the vendor is not shipped as this is a phpstan extension
32+
- run: rm -rf vendor tests ecs.php phpstan.neon phpunit.xml rector.php composer.lock .gitignore .editorconfig full-tool-build.sh
3733

38-
# clear the dev files
39-
- run: rm -rf tests rector-local ecs.php phpstan.neon phpunit.xml .editorconfig
34+
# remove the original .github, to fully override it with the target repository one below
35+
- run: rm -rf .github
4036

41-
# copy PHP 7.2 composer + workflows
37+
# copy PHP 7.4 composer + workflows
4238
- run: cp -r build/target-repository/. .
4339

44-
# clear the dev files
45-
- run: rm -rf build full-tool-build.sh rector.php phpstan-for-tests.neon tests
40+
# clear the build files
41+
- run: rm -rf build
42+
43+
# clone the remote repository, so we can commit on top of its history and push without --force
44+
# inspired by https://github.com/easy-coding-standard/ecs-src/blob/main/.github/workflows/buid_release.yaml
45+
-
46+
uses: "actions/checkout@v5"
47+
with:
48+
repository: anywherephp/type-perfect
49+
path: remote-repository
50+
token: ${{ secrets.WORKFLOWS_TOKEN }}
51+
52+
# remove remote files, to avoid piling up dead code in remote repository
53+
- run: rm -rf remote-repository/src remote-repository/config remote-repository/.github
54+
55+
# copy the downgraded code to the remote repository
56+
- run: rsync -a --exclude .git --exclude remote-repository ./ remote-repository/
4657

4758
# setup git user
4859
-
60+
working-directory: remote-repository
4961
run: |
50-
git config user.email "action@github.com"
51-
git config user.name "GitHub Action"
52-
# publish to the same repository with a new tag
53-
# see https://tomasvotruba.com/blog/how-to-release-php-81-and-72-package-in-the-same-repository/
62+
git config user.email "tomas@getrector.org"
63+
git config user.name "rector-bot"
64+
65+
# publish to remote repository without tag
5466
-
55-
name: "Tag Downgraded Code"
67+
name: "Push Downgraded Code - branch"
68+
working-directory: remote-repository
69+
if: "!startsWith(github.ref, 'refs/tags/')"
5670
run: |
57-
# separate a "git add" to add untracked (new) files too
5871
git add --all
59-
git commit -m "release PHP 7.4 downgraded"
72+
git commit -m "Updated TypePerfect to commit ${{ github.event.after }}"
73+
git push --quiet origin main
6074
61-
# force push tag, so there is only 1 version
62-
git tag "${GITHUB_REF#refs/tags/}" --force
63-
git push origin "${GITHUB_REF#refs/tags/}" --force
75+
# publish to remote repository with tag
76+
-
77+
name: "Push Downgraded Code - tag"
78+
working-directory: remote-repository
79+
if: "startsWith(github.ref, 'refs/tags/')"
80+
run: |
81+
git add --all
82+
git commit --allow-empty -m "TypePerfect ${GITHUB_REF#refs/tags/}"
83+
git push --quiet origin main
84+
git tag "${GITHUB_REF#refs/tags/}" -m "${GITHUB_REF#refs/tags/}"
85+
git push --quiet origin "${GITHUB_REF#refs/tags/}"

build/target-repository/.github/FUNDING.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Auto Closer PR
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: superbrothers/close-pull-request@v3
12+
with:
13+
# Optional. Post a issue comment just before closing a pull request.
14+
comment: |
15+
Hi, thank you for your contribution.
16+
17+
Unfortunately, this repository is read-only. It's a build of the main repository.
18+
19+
We'd like to kindly ask you to move the contribution there - https://github.com/rectorphp/type-perfect.
20+
21+
We'll check it, review it and give you feed back right way.
22+
23+
Thank you.

build/target-repository/.github/workflows/standalone_install.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

build/target-repository/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Type Perfect - Anywhere version
2+
3+
See original repository for more details: https://github.com/rectorphp/type-perfect

build/target-repository/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "rector/type-perfect",
2+
"name": "anywherephp/type-perfect",
33
"type": "phpstan-extension",
44
"description": "Next level type declaration checks",
5-
"license": "MIT",
5+
"license": "proprietary",
66
"require": {
77
"php": "^7.4|^8.0",
88
"phpstan/phpstan": "^2.1.14",

build/target-repository/phpstan-for-tests.neon

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Collector/ClassMethod/PublicClassMethodParamTypesCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Rector\TypePerfect\Printer\CollectorMetadataPrinter;
1616

1717
/**
18-
* @implements Collector<ClassMethod, array{class-string, string, string, int}|null>
18+
* @implements Collector<ClassMethod, array{class-string, string, string, int}>
1919
*/
2020
final readonly class PublicClassMethodParamTypesCollector implements Collector
2121
{

src/Collector/MethodCall/MethodCallArgTypesCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Rector\TypePerfect\ValueObject\MethodCallReference;
1717

1818
/**
19-
* @implements Collector<MethodCall, array<string>|null>
19+
* @implements Collector<MethodCall, array{string, string}>
2020
*/
2121
final readonly class MethodCallArgTypesCollector implements Collector
2222
{

0 commit comments

Comments
 (0)