[DX] Warn about ->withPhpSets() called multiple times, to avoid inval… #6570
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
# builds the content of https://github.com/rectorphp/rector | |
# inspiration from https://github.com/phpstan/phpstan-src/blob/master/.github/workflows/phar.yml | |
name: Build Scoped Rector | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
env: | |
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361 | |
COMPOSER_ROOT_VERSION: "dev-main" | |
jobs: | |
build_scoped_rector: | |
# Don't run on forks. | |
if: github.repository == 'rectorphp/rector-src' | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
# sometime, when 2 or more consecutive PRs merged, the checkout rectorphp/rector-src is overlapped | |
# and reverting other commit change | |
# this should not happen on create a tag, so wait first | |
- | |
name: "Wait before checkout rectorphp/rector-src on create a tag" | |
if: "startsWith(github.ref, 'refs/tags/')" | |
run: sleep 20 | |
- | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.2 | |
coverage: none | |
# fixes https://github.com/rectorphp/rector/pull/4559/checks?check_run_id=1359814403, see https://github.com/shivammathur/setup-php#composer-github-oauth | |
env: | |
COMPOSER_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
# install do not use composer/ramsey github action package, it uses cache including "dev", we want to avoid it here | |
# this run is needed to install patches, the --no-dev skips them | |
- run: composer install --ansi | |
# to remove dev dependencies | |
- run: composer install --no-dev --ansi | |
# early downgrade individual functions | |
- run: bin/rector process src/functions/node_helper.php -c build/config/config-downgrade.php --ansi | |
# 1. copy files to $NESTED_DIRECTORY directory Exclude the scoped/nested directories to prevent rsync from copying in a loop | |
- run: rsync --exclude rector-build -av * rector-build --quiet | |
- run: rm -rf rector-build/rules-tests rector-build/tests rector-build/bin/generate-changelog.php rector-build/bin/validate-phpstan-version.php rector-build/vendor/tracy/tracy/examples rector-build/vendor/symfony/console/Tester rector-build/vendor/symfony/console/Event rector-build/vendor/symfony/console/EventListener rector-build/vendor/tracy/tracy/examples rector-build/vendor/tracy/tracy/src/Bridges rector-build/vendor/tracy/tracy/src/Tracy/Bar rector-build/vendor/tracy/tracy/src/Tracy/Session rector-build/vendor/symfony/service-contracts/Test | |
# 2. downgrade rector | |
- run: php -d memory_limit=-1 bin/rector process rector-build/bin rector-build/config rector-build/src rector-build/rules rector-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs | |
# 3. prefix classes | |
- run: sh build/build-rector-scoped.sh rector-build rector-prefixed-downgraded | |
# 4. lint the code for PHP 7.4 - this must happen here, as setup-php allows only one PHP version switch: https://github.com/shivammathur/setup-php/issues/434 | |
- | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 7.4 | |
coverage: none | |
- run: composer global require php-parallel-lint/php-parallel-lint --ansi | |
- run: /home/runner/.composer/vendor/bin/parallel-lint rector-prefixed-downgraded --exclude rector-prefixed-downgraded/stubs --exclude rector-prefixed-downgraded/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded/vendor/rector/rector-generator/templates --exclude rector-prefixed-downgraded/vendor/symfony/console/Debug/CliRequest.php | |
# 5. copy repository meta files | |
- run: | | |
cp -R build/target-repository/. rector-prefixed-downgraded | |
cp -R templates rector-prefixed-downgraded/ | |
cp CONTRIBUTING.md rector-prefixed-downgraded/ | |
cp preload.php rector-prefixed-downgraded/ | |
# 6. clone remote repository, so we can push it | |
- | |
uses: "actions/checkout@v4" | |
with: | |
repository: rectorphp/rector | |
path: remote-repository | |
token: ${{ secrets.ACCESS_TOKEN }} | |
# remove remote files, to avoid piling up dead code in remote repository | |
- run: rm -rf remote-repository/.github remote-repository/e2e remote-repository/docs remote-repository/config remote-repository/src remote-repository/rules remote-repository/packages remote-repository/vendor remote-repository/stubs-rector | |
- run: cp -a rector-prefixed-downgraded/. remote-repository | |
- run: rm -rf remote-repository/bin/add-phpstan-self-replace.php remote-repository/bin/test-fixture-stats.php | |
# 7. setup git | |
- | |
working-directory: remote-repository | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "Tomas Votruba" | |
# commit metadata | |
- | |
name: "Get Git log" | |
id: git-log | |
run: | | |
echo "log<<EOF" >> $GITHUB_OUTPUT | |
echo "$(git log ${{ github.event.before }}..${{ github.event.after }} --reverse --pretty='https://github.com/rectorphp/rector-src/commit/%H %s')" >> $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
# 8.A publish it to remote repository without tag | |
- | |
name: "Commit Prefixed - main" | |
working-directory: remote-repository | |
if: "!startsWith(github.ref, 'refs/tags/')" | |
env: | |
INPUT_LOG: ${{ steps.git-log.outputs.log }} | |
run: | | |
git add --all | |
git commit -m "Updated Rector to commit ${{ github.event.after }}" -m "$INPUT_LOG" | |
git push --quiet origin main | |
# 8.B publish it to remote repository with tag | |
- | |
name: "Commit Prefixed - tag" | |
working-directory: remote-repository | |
if: "startsWith(github.ref, 'refs/tags/')" | |
env: | |
INPUT_LOG: ${{ steps.git-log.outputs.log }} | |
run: | | |
git add --all | |
git commit -m "Rector ${GITHUB_REF#refs/tags/}" -m "$INPUT_LOG" | |
git push --quiet origin main | |
git tag ${GITHUB_REF#refs/tags/} -m "${GITHUB_REF#refs/tags/}" | |
git push --quiet origin ${GITHUB_REF#refs/tags/} |