-
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.
- Loading branch information
1 parent
4aa594a
commit 751dbe2
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
templates/downgrade/.github/workflows/downgraded_release.yaml
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,67 @@ | ||
name: Downgraded Release | ||
|
||
on: | ||
push: | ||
tags: | ||
# avoid infinite looping, skip tags that ends with ".72" | ||
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches | ||
- '*' | ||
|
||
jobs: | ||
downgrade_release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- | ||
uses: "actions/checkout@v3" | ||
with: | ||
token: ${{ secrets.ACCESS_TOKEN }} | ||
|
||
- | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
php-version: 8.2 | ||
coverage: none | ||
|
||
# invoke patches | ||
- run: composer install --ansi | ||
|
||
# but no dev packages | ||
- run: composer update --no-dev --ansi | ||
|
||
# get rector to "rector-local" directory, to avoid downgrading itself in the /vendor | ||
- run: mkdir rector-local | ||
- run: composer require rector/rector --working-dir rector-local --ansi | ||
|
||
# downgrade to PHP 7.2 | ||
- run: rector-local/vendor/bin/rector process src bin vendor --config build/rector-downgrade-php-72.php --ansi | ||
|
||
# clear the dev files | ||
- run: rm -rf tests ecs.php phpstan.neon phpunit.xml .gitignore .editorconfig | ||
|
||
# prefix and scope | ||
- run: sh prefix-code.sh | ||
|
||
# copy PHP 7.2 composer + workflows | ||
- run: cp -r build/target-repository/. . | ||
|
||
# clear the dev files | ||
- run: rm -rf build prefix-code.sh full-tool-build.sh scoper.php rector.php rector-local php-scoper.phar | ||
|
||
# setup git user | ||
- | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "GitHub Action" | ||
# publish to the same repository with a new tag | ||
# see https://tomasvotruba.com/blog/how-to-release-php-81-and-72-package-in-the-same-repository/ | ||
- | ||
name: "Tag Downgraded Code" | ||
run: | | ||
# separate a "git add" to add untracked (new) files too | ||
git add --all | ||
git commit -m "release PHP 7.2 downgraded" | ||
# force push tag, so there is only 1 version | ||
git tag "${GITHUB_REF#refs/tags/}" --force | ||
git push origin "${GITHUB_REF#refs/tags/}" --force |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
|
||
return RectorConfig::configure() | ||
->withDowngradeSets(php72: true) | ||
->withSkip([ | ||
// typical tests locations | ||
'*/Tests/*', | ||
'*/tests/*', | ||
__DIR__ . '/../../tests', | ||
]); |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
# inspired from https://github.com/rectorphp/rector/blob/main/build/build-rector-scoped.sh | ||
|
||
# see https://stackoverflow.com/questions/66644233/how-to-propagate-colors-from-bash-script-to-github-action?noredirect=1#comment117811853_66644233 | ||
export TERM=xterm-color | ||
|
||
# show errors | ||
set -e | ||
|
||
# script fails if trying to access to an undefined variable | ||
set -u | ||
|
||
|
||
# functions | ||
note() | ||
{ | ||
MESSAGE=$1; | ||
printf "\n"; | ||
echo "\033[0;33m[NOTE] $MESSAGE\033[0m"; | ||
} | ||
|
||
# --------------------------- | ||
|
||
# 2. scope it | ||
note "Downloading php-scoper 0.18.3" | ||
wget https://github.com/humbug/php-scoper/releases/download/0.18.3/php-scoper.phar -N --no-verbose | ||
|
||
|
||
note "Running php-scoper" | ||
|
||
# Work around possible PHP memory limits | ||
# @todo detect dirs, that exist | ||
php -d memory_limit=-1 php-scoper.phar add-prefix src bin vendor composer.json --config scoper.php --force --ansi --output-dir scoped-code | ||
|
||
# the output code is in "/scoped-code", lets move it up | ||
# the local directories have to be empty to move easily | ||
rm -r src bin vendor composer.json | ||
mv scoped-code/* . | ||
|
||
note "Dumping Composer Autoload" | ||
composer dump-autoload --ansi --classmap-authoritative --no-dev | ||
|
||
# make bin runnable without "php" | ||
# @todo detect bin files if any | ||
chmod 777 "bin/class-leak" | ||
chmod 777 "bin/class-leak.php" | ||
|
||
note "Finished" |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
$nowDateTime = new DateTime('now'); | ||
$timestamp = $nowDateTime->format('Ym'); | ||
|
||
// see https://github.com/humbug/php-scoper | ||
return [ | ||
// @todo detect :) | ||
'prefix' => 'ClassLeak' . $timestamp, | ||
'expose-constants' => ['#^SYMFONY\_[\p{L}_]+$#'], | ||
// @todo detect | ||
'exclude-namespaces' => ['#^TomasVotruba\\\\ClassLeak#', '#^Symfony\\\\Polyfill#'], | ||
'exclude-files' => [ | ||
// do not prefix "trigger_deprecation" from symfony - https://github.com/symfony/symfony/commit/0032b2a2893d3be592d4312b7b098fb9d71aca03 | ||
// these paths are relative to this file location, so it should be in the root directory | ||
'vendor/symfony/deprecation-contracts/function.php', | ||
], | ||
'patchers' => [], | ||
]; |