Skip to content

Commit 38c242e

Browse files
authored
Make use of entropy fw, downgrade and scope to ease use (#12)
1 parent 2176561 commit 38c242e

22 files changed

+370
-301
lines changed

.github/workflows/code_analysis.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ jobs:
2727
name: 'Tests'
2828
run: vendor/bin/phpunit
2929

30+
-
31+
name: 'Main run'
32+
run: php bin/behastan
33+
3034
-
3135
name: 'Check Active Classes'
32-
run: vendor/bin/class-leak check bin src --ansi
36+
run: vendor/bin/class-leak check bin src --skip-type="Entropy\Console\Contract\CommandInterface" --skip-type="Rector\Behastan\Contract\RuleInterface"
3337

3438
name: ${{ matrix.actions.name }}
3539
runs-on: ubuntu-latest
@@ -39,7 +43,7 @@ jobs:
3943
# see https://github.com/shivammathur/setup-php
4044
- uses: shivammathur/setup-php@v2
4145
with:
42-
php-version: 8.2
46+
php-version: 8.3
4347
coverage: none
4448

4549
# composer install cache - https://github.com/ramsey/composer-install
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Downgraded Release
2+
3+
on:
4+
push:
5+
tags:
6+
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches
7+
- '*'
8+
9+
jobs:
10+
downgrade_release:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: "actions/checkout@v3"
15+
with:
16+
token: ${{ secrets.WORKFLOWS_TOKEN }}
17+
18+
-
19+
uses: "shivammathur/setup-php@v2"
20+
with:
21+
php-version: 8.3
22+
coverage: none
23+
24+
# invoke patches
25+
- run: composer install --ansi
26+
27+
# but no dev packages
28+
- run: composer update --no-dev --ansi
29+
30+
# get rector to "rector-local" directory, to avoid downgrading itself in the /vendor
31+
- run: mkdir rector-local
32+
- run: composer require rector/rector --working-dir rector-local --ansi
33+
34+
# downgrade to PHP 7.4
35+
- run: rector-local/vendor/bin/rector process bin src vendor --config build/rector-downgrade-php.php --ansi
36+
37+
# clear the dev files
38+
- run: rm -rf tests ecs.php phpstan.neon phpunit.xml .gitignore .editorconfig
39+
40+
# prefix and scope
41+
- run: sh prefix-code.sh
42+
43+
# copy PHP 7.4 composer + workflows
44+
- run: cp -r build/target-repository/. .
45+
46+
# clear the dev files
47+
- run: rm -rf build prefix-code.sh full-tool-build.sh scoper.php rector.php php-scoper.phar rector-local
48+
49+
# setup git user
50+
-
51+
run: |
52+
git config user.email "action@github.com"
53+
git config user.name "GitHub Action"
54+
# publish to the same repository with a new tag
55+
# see https://tomasvotruba.com/blog/how-to-release-php-81-and-72-package-in-the-same-repository/
56+
-
57+
name: "Tag Downgraded Code"
58+
run: |
59+
# separate a "git add" to add untracked (new) files too
60+
git add --all
61+
git commit -m "release PHP 7.2 downgraded"
62+
63+
# force push tag, so there is only 1 version
64+
git tag "${GITHUB_REF#refs/tags/}" --force
65+
git push origin "${GITHUB_REF#refs/tags/}" --force

bin/behastan.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
declare(strict_types=1);
44

55
use Rector\Behastan\DependencyInjection\ContainerFactory;
6-
use Symfony\Component\Console\Application;
7-
use Symfony\Component\Console\Input\ArgvInput;
8-
use Symfony\Component\Console\Output\ConsoleOutput;
96

107
$possibleAutoloadPaths = [
118
// dependency
@@ -28,10 +25,8 @@
2825
require_once $scoperAutoloadFilepath;
2926
}
3027

31-
$containerFactory = new ContainerFactory();
32-
$container = $containerFactory->create();
28+
$container = ContainerFactory::create();
29+
$consoleApplication = $container->make(\Entropy\Console\ConsoleApplication::class);
3330

34-
$application = $container->make(Application::class);
35-
36-
$exitCode = $application->run(new ArgvInput(), new ConsoleOutput());
31+
$exitCode = $consoleApplication->run($argv);
3732
exit($exitCode);

build/build-scoped.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
# inspired from https://github.com/rectorphp/rector/blob/main/build/build-rector-scoped.sh
4+
5+
# see https://stackoverflow.com/questions/66644233/how-to-propagate-colors-from-bash-script-to-github-action?noredirect=1#comment117811853_66644233
6+
export TERM=xterm-color
7+
8+
# show errors
9+
set -e
10+
11+
# script fails if trying to access to an undefined variable
12+
set -u
13+
14+
15+
# functions
16+
note()
17+
{
18+
MESSAGE=$1;
19+
printf "\n";
20+
echo "\033[0;33m[NOTE] $MESSAGE\033[0m";
21+
}
22+
23+
24+
# configure here
25+
BUILD_DIRECTORY=$1
26+
RESULT_DIRECTORY=$2
27+
28+
# ---------------------------
29+
30+
note "Starts"
31+
32+
# 2. scope it
33+
note "Running scoper with '$RESULT_DIRECTORY' output directory"
34+
wget https://github.com/humbug/php-scoper/releases/download/0.18.18/php-scoper.phar -N --no-verbose
35+
36+
# create directory
37+
mkdir "$RESULT_DIRECTORY" -p
38+
39+
# Work around possible PHP memory limits
40+
php -d memory_limit=-1 php-scoper.phar add-prefix bin src stubs vendor composer.json --output-dir "../$RESULT_DIRECTORY" --config scoper.php --force --ansi --working-dir "$BUILD_DIRECTORY"
41+
42+
note "Show prefixed files in '$RESULT_DIRECTORY'"
43+
ls -l $RESULT_DIRECTORY
44+
45+
note "Dumping Composer Autoload"
46+
composer dump-autoload --working-dir "$RESULT_DIRECTORY" --ansi --classmap-authoritative --no-dev
47+
48+
# make bin/behastan runnable without "php"
49+
chmod 777 "$RESULT_DIRECTORY/bin/behastan"
50+
chmod 777 "$RESULT_DIRECTORY/bin/behastan.php"
51+
52+
note "Finished"

build/rector-downgrade-php.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withDowngradeSets(php72: true)
9+
->withSkip([
10+
'*/Tests/*',
11+
'*/tests/*',
12+
]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
github: tomasvotruba
3+
custom: https://www.paypal.me/rectorphp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Bare Run
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
bare_run:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php_version: ['7.2', '7.4', '8.0', '8.2']
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
-
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php_version }}
21+
coverage: none
22+
23+
- run: php bin/behastan
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "rector/behastan",
3+
"description": "Static analysis for Behat definitions and context files",
4+
"license": "MIT",
5+
"require": {
6+
"php": ">=7.2"
7+
},
8+
"bin": [
9+
"bin/behastan"
10+
],
11+
"autoload": {
12+
"psr-4": {
13+
"Rector\\Behastan\\": "src"
14+
}
15+
}
16+
}

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
],
88
"require": {
99
"php": "^8.2",
10-
"illuminate/container": "^11.41|^12.37",
1110
"nette/utils": "^4.0",
11+
"entropy/entropy": "dev-main",
1212
"nikic/php-parser": "^5.6",
13-
"symfony/console": "^6.4|^7.0|^8.0",
14-
"symfony/finder": "^6.4|^7.0|^8.0",
13+
"symfony/finder": "^7.0",
1514
"webmozart/assert": "^1.12"
1615
},
1716
"require-dev": {
@@ -40,7 +39,8 @@
4039
"sort-packages": true,
4140
"allow-plugins": {
4241
"phpstan/extension-installer": true
43-
}
42+
},
43+
"platform-check": false
4444
},
4545
"scripts": {
4646
"check-cs": "vendor/bin/ecs check --ansi",

full-tool-build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# add patches
4+
composer install --ansi
5+
6+
# but skip dev dependencies
7+
composer update --no-dev --ansi
8+
9+
# remove tests and useless files, to make downgraded, scoped and deployed codebase as small as possible
10+
rm -rf tests
11+
12+
# downgrade with rector
13+
mkdir rector-local
14+
composer require rector/rector --working-dir rector-local
15+
rector-local/vendor/bin/rector process bin src vendor --config build/rector-downgrade-php-72.php --ansi
16+
17+
# prefix
18+
sh prefix-code.sh

0 commit comments

Comments
 (0)