From 8cb7d54d4798bcfb46a2652ffc713e2fe25fdc0e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 18 Mar 2024 21:03:28 +0100 Subject: [PATCH] Add basic downgrade release (#11) --- .github/workflows/downgraded_release.yaml | 66 +++++++++++++++++++ build/build-scoped.sh | 52 +++++++++++++++ build/rector-downgrade-php-72.php | 15 +++++ build/target-repository/.github/FUNDING.yml | 3 + .../.github/workflows/bare_run.yaml | 23 +++++++ build/target-repository/composer.json | 11 ++++ full-tool-build.sh | 18 +++++ scoper.php | 26 ++++++++ 8 files changed, 214 insertions(+) create mode 100644 .github/workflows/downgraded_release.yaml create mode 100755 build/build-scoped.sh create mode 100644 build/rector-downgrade-php-72.php create mode 100644 build/target-repository/.github/FUNDING.yml create mode 100644 build/target-repository/.github/workflows/bare_run.yaml create mode 100644 build/target-repository/composer.json create mode 100644 full-tool-build.sh create mode 100644 scoper.php diff --git a/.github/workflows/downgraded_release.yaml b/.github/workflows/downgraded_release.yaml new file mode 100644 index 00000000..fd74bffc --- /dev/null +++ b/.github/workflows/downgraded_release.yaml @@ -0,0 +1,66 @@ +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.WORKFLOWS_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 bin src 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 + + # setup git user + - + run: | + git config user.email "action@github.com" + 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 diff --git a/build/build-scoped.sh b/build/build-scoped.sh new file mode 100755 index 00000000..2a143f85 --- /dev/null +++ b/build/build-scoped.sh @@ -0,0 +1,52 @@ +#!/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"; +} + + +# configure here +BUILD_DIRECTORY=$1 +RESULT_DIRECTORY=$2 + +# --------------------------- + +note "Starts" + +# 2. scope it +note "Running scoper with '$RESULT_DIRECTORY' output directory" +wget https://github.com/humbug/php-scoper/releases/download/0.17.5/php-scoper.phar -N --no-verbose + +# create directory +mkdir "$RESULT_DIRECTORY" -p + +# Work around possible PHP memory limits +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" + +note "Show prefixed files in '$RESULT_DIRECTORY'" +ls -l $RESULT_DIRECTORY + +note "Dumping Composer Autoload" +composer dump-autoload --working-dir "$RESULT_DIRECTORY" --ansi --classmap-authoritative --no-dev + +# make bin/rule-doc-generator runnable without "php" +chmod 777 "$RESULT_DIRECTORY/bin/rule-doc-generator" +chmod 777 "$RESULT_DIRECTORY/bin/rule-doc-generator.php" + +note "Finished" diff --git a/build/rector-downgrade-php-72.php b/build/rector-downgrade-php-72.php new file mode 100644 index 00000000..68641a45 --- /dev/null +++ b/build/rector-downgrade-php-72.php @@ -0,0 +1,15 @@ +sets([DowngradeLevelSetList::DOWN_TO_PHP_72]); + + $rectorConfig->skip([ + '*/Tests/*', + '*/tests/*', + ]); +}; diff --git a/build/target-repository/.github/FUNDING.yml b/build/target-repository/.github/FUNDING.yml new file mode 100644 index 00000000..f797866a --- /dev/null +++ b/build/target-repository/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms +github: tomasvotruba +custom: https://www.paypal.me/rectorphp diff --git a/build/target-repository/.github/workflows/bare_run.yaml b/build/target-repository/.github/workflows/bare_run.yaml new file mode 100644 index 00000000..ce9961d3 --- /dev/null +++ b/build/target-repository/.github/workflows/bare_run.yaml @@ -0,0 +1,23 @@ +name: Bare Run + +on: [pull_request, push] + +jobs: + bare_run: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php_version: ['7.2', '7.3', '7.4', '8.0', '8.2'] + + steps: + - uses: actions/checkout@v2 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + coverage: none + + - run: php bin/rule-doc-generator list --ansi diff --git a/build/target-repository/composer.json b/build/target-repository/composer.json new file mode 100644 index 00000000..ee615ac1 --- /dev/null +++ b/build/target-repository/composer.json @@ -0,0 +1,11 @@ +{ + "name": "symplify/rule-doc-generator", + "description": "Documentation generator for coding standard or static analysis rules", + "license": "MIT", + "require": { + "php": ">=7.2" + }, + "bin": [ + "bin/rule-doc-generator" + ] +} diff --git a/full-tool-build.sh b/full-tool-build.sh new file mode 100644 index 00000000..94f37107 --- /dev/null +++ b/full-tool-build.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# add patches +composer install --ansi + +# but skip dev dependencies +composer update --no-dev --ansi + +# remove tests and useless files, to make downgraded, scoped and deployed codebase as small as possible +rm -rf tests + +# downgrade with rector +mkdir rector-local +composer require rector/rector --working-dir rector-local +rector-local/vendor/bin/rector process bin src vendor --config build/rector-downgrade-php-72.php --ansi + +# prefix +sh prefix-code.sh diff --git a/scoper.php b/scoper.php new file mode 100644 index 00000000..536c0ae4 --- /dev/null +++ b/scoper.php @@ -0,0 +1,26 @@ +format('Ym'); + +// @see https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md + +// see https://github.com/humbug/php-scoper +return [ + 'prefix' => 'RuleDocGenerator' . $timestamp, + 'expose-constants' => ['#^SYMFONY\_[\p{L}_]+$#'], + 'exclude-namespaces' => ['#^Symplify\\\\RuleDocGenerator#', '#^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', + 'stubs/PhpCsFixer/AbstractFixer.php', + 'stubs/Rector/Core/Contract/Rector/RectorInterface.php', + ], + + // @todo unprefix class names? +];