mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 12:04:39 +01:00
Add custom script
This commit is contained in:
parent
e7ffe0928a
commit
f1c87b8ea5
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -44,4 +44,4 @@ jobs:
|
||||
run: |
|
||||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git config --local user.name "Github Actions"
|
||||
php vendor/phabel/phabel/tools/convertPhabel.php all
|
||||
php tools/convertPhabel.php all
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "nikic/php-parser",
|
||||
"name": "phabel/php-parser",
|
||||
"type": "library",
|
||||
"description": "A PHP parser written in PHP",
|
||||
"keywords": [
|
||||
|
79
tools/convertPhabel.php
Normal file
79
tools/convertPhabel.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
use Phabel\Target\Php;
|
||||
use Phabel\Traverser;
|
||||
|
||||
if (!\file_exists('composer.json')) {
|
||||
echo "This script must be run from package root".PHP_EOL;
|
||||
die(1);
|
||||
}
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
if ($argc < 2) {
|
||||
$help = <<<EOF
|
||||
Usage: {$argv[0]} target [ dry ]
|
||||
|
||||
target - Target version
|
||||
dry - 0 or 1, whether to dry-run conversion
|
||||
|
||||
EOF;
|
||||
echo $help;
|
||||
die(1);
|
||||
}
|
||||
$target = $argv[1];
|
||||
$dry = (bool) ($argv[2] ?? '');
|
||||
|
||||
if (!\file_exists('phabelConverted')) {
|
||||
\mkdir('phabelConverted');
|
||||
}
|
||||
|
||||
\passthru("git stash");
|
||||
$branch = \trim(\shell_exec("git rev-parse --abbrev-ref HEAD"));
|
||||
|
||||
foreach ($target === 'all' ? Php::VERSIONS : [$target] as $realTarget) {
|
||||
if (!$dry) {
|
||||
\passthru("git branch -D phabel_tmp");
|
||||
\passthru("git branch phabel_tmp");
|
||||
\passthru("git checkout phabel_tmp");
|
||||
}
|
||||
foreach (['8.0', $realTarget] as $target) {
|
||||
$coverage = \getenv('PHABEL_COVERAGE') ?: '';
|
||||
if ($coverage) {
|
||||
$coverage .= "-$target";
|
||||
}
|
||||
|
||||
$packages = [];
|
||||
foreach (['tools', 'src', 'bin', 'test', 'test_old', 'lib'] as $dir) {
|
||||
if (!\file_exists($dir)) {
|
||||
continue;
|
||||
}
|
||||
$packages += Traverser::run([Php::class => ['target' => $target]], $dir, $dir, $coverage);
|
||||
}
|
||||
|
||||
$str = (string) $target;
|
||||
$packages["php"] = ">=${str[0]}.${str[1]}";
|
||||
if (!empty($packages)) {
|
||||
$cmd = "composer require ";
|
||||
foreach ($packages as $package => $constraint) {
|
||||
$cmd .= \escapeshellarg("{$package}:{$constraint}")." ";
|
||||
}
|
||||
\passthru($cmd);
|
||||
}
|
||||
|
||||
\passthru("composer cs-fix");
|
||||
|
||||
if (!$dry) {
|
||||
\passthru("git add -A");
|
||||
\passthru("git commit -m ".\escapeshellarg("phabel.io: transpile to $target"));
|
||||
}
|
||||
}
|
||||
if (!$dry) {
|
||||
\passthru("git push -f origin ".\escapeshellarg("phabel_tmp:{$branch}-{$target}"));
|
||||
|
||||
\passthru("git checkout ".\escapeshellarg($branch));
|
||||
\passthru("git branch -D phabel_tmp");
|
||||
}
|
||||
\passthru("git reset --hard");
|
||||
}
|
||||
|
||||
\passthru("git stash pop");
|
Loading…
Reference in New Issue
Block a user