mirror of https://github.com/rectorphp/rector.git
144 lines
7.1 KiB
YAML
144 lines
7.1 KiB
YAML
# 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: 30
|
|
|
|
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 120
|
|
|
|
-
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
-
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: 8.1
|
|
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 only prod dependencies - do not use ramsey, it uses cache including "dev", we want to avoid it here
|
|
- run: composer install --no-dev --ansi
|
|
|
|
# resolve rector version
|
|
- run: php bin/resolve-version.php
|
|
|
|
# early downgrade individual functions
|
|
- run: bin/rector process src/functions -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/packages-tests rector-build/rules-tests rector-build/tests rector-build/bin/generate-changelog.php rector-build/bin/validate-phpstan-version.php rector-build/bin/clean-phpstan.php rector-build/vendor/tracy/tracy/examples
|
|
|
|
# 2. downgrade rector
|
|
- run: sh build/downgrade-rector.sh rector-build
|
|
|
|
# scoped using php-scoper.phar which require #[\ReturnTypeWillChange] inside so use php 8.0 for scoping
|
|
-
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: 8.0
|
|
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 }}
|
|
|
|
# 3. prefix classes
|
|
- run: sh build/build-rector-scoped.sh rector-build rector-prefixed-downgraded
|
|
|
|
# 4. lint the code for PHP 7.2 - 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.2
|
|
coverage: none
|
|
- run: composer global require php-parallel-lint/php-parallel-lint
|
|
- run: /home/runner/.composer/vendor/bin/parallel-lint rector-prefixed-downgraded --exclude rector-prefixed-downgraded/stubs --exclude rector-prefixed-downgraded/vendor/rector/rector-nette/tests --exclude rector-prefixed-downgraded/vendor/symfony/polyfill-mbstring/bootstrap80.php --exclude rector-prefixed-downgraded/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded/vendor/ssch/typo3-rector/templates/maker --exclude rector-prefixed-downgraded/vendor/symfony/console/Event --exclude rector-prefixed-downgraded/vendor/symfony/console/EventListener --exclude rector-prefixed-downgraded/vendor/symfony/console/Tester --exclude rector-prefixed-downgraded/vendor/rector/rector-generator/templates --exclude rector-prefixed-downgraded/vendor/symfony/contracts/Cache/ItemInterface.php --exclude rector-prefixed-downgraded/vendor/symfony/dependency-injection/ExpressionLanguageProvider.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@v3"
|
|
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/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
|
|
|
|
# 7. setup git
|
|
-
|
|
working-directory: remote-repository
|
|
run: |
|
|
git config user.email "tomas.vot@gmail.com"
|
|
git config user.name "Tomas Votruba"
|
|
|
|
# commit metadata
|
|
-
|
|
name: "Get Git log"
|
|
id: git-log
|
|
run: echo ::set-output name=log::$(git log ${{ github.event.before }}..${{ github.event.after }} --reverse --pretty='%H %s' | sed -e 's/^/https:\/\/github.com\/rectorphp\/rector-src\/commit\//')
|
|
|
|
# 8.A publish it to remote repository without tag
|
|
-
|
|
name: "Commit Prefixed - main"
|
|
working-directory: remote-repository
|
|
if: "!startsWith(github.ref, 'refs/tags/')"
|
|
run: |
|
|
git add --all
|
|
git commit -m "Updated Rector to commit ${{ github.event.after }}" -m "${{ steps.git-log.outputs.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/')"
|
|
run: |
|
|
git add --all
|
|
git commit -m "Rector ${GITHUB_REF#refs/tags/}" -m "${{ steps.git-log.outputs.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/}
|
|
|
|
# run bare run test
|
|
- run: cd remote-repository && bin/rector list --ansi && cd ..
|