From 7cff8e279946a1b4b0689fd5b9da832d6990a65a Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Tue, 6 Feb 2024 21:13:30 +0300 Subject: [PATCH] autofix ecs & rector --- .github/workflows/autofix.yaml | 89 +++++++++++++++++++++++++++++++ .github/workflows/code-style.yaml | 41 -------------- .github/workflows/rector.yaml | 41 -------------- rector.php | 4 ++ 4 files changed, 93 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/autofix.yaml delete mode 100644 .github/workflows/code-style.yaml delete mode 100644 .github/workflows/rector.yaml diff --git a/.github/workflows/autofix.yaml b/.github/workflows/autofix.yaml new file mode 100644 index 000000000..04170977c --- /dev/null +++ b/.github/workflows/autofix.yaml @@ -0,0 +1,89 @@ +name: fixer + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + autofix: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: mbstring, pgsql, mysql, sqlite, redis, memcached, bcmath + coverage: pcov + env: + runner: self-hosted + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run rector-fix + run: composer rector-fix + + - name: Run ecs-fix + run: composer ecs-fix + + - name: Run rector + run: composer rector + + - name: Run ecs + run: composer ecs + + - name: Run parabench + run: composer parabench + + - name: "Check if build has changed" + if: success() + id: has-changes + run: | + echo "stdout<> $GITHUB_OUTPUT + echo "$(git diff --stat)" >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + - name: Import GPG key + if: ${{ steps.has-changes.outputs.stdout }} + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_BOT }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + fingerprint: ${{ secrets.GPG_FINGERPRINT }} + git_config_global: true + git_user_signingkey: true + git_commit_gpgsign: true + git_committer_name: Github bot + git_committer_email: bot@babichev.net + + - name: "Commit files" + if: ${{ steps.has-changes.outputs.stdout }} + env: + GH_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + gh pr checkout ${{ github.event.pull_request.number }} + git commit -S -m "autofix" -a + + - name: "Push changes" + if: ${{ steps.has-changes.outputs.stdout }} + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + run: git push -u origin HEAD diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml deleted file mode 100644 index 217d24b4a..000000000 --- a/.github/workflows/code-style.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: code-style - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - ecs: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: bcmath - env: - runner: self-hosted - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run ecs - run: composer ecs diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml deleted file mode 100644 index d164fcf1d..000000000 --- a/.github/workflows/rector.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: rector - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - rector: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: bcmath - env: - runner: self-hosted - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run rector - run: composer rector diff --git a/rector.php b/rector.php index 945b1ac02..e10f29768 100644 --- a/rector.php +++ b/rector.php @@ -16,6 +16,10 @@ // Define what rule sets will be applied $config->import(PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES); $config->import(PHPUnitSetList::PHPUNIT_100); + $config->import(SetList::STRICT_BOOLEANS); + $config->import(SetList::PRIVATIZATION); + $config->import(SetList::EARLY_RETURN); + $config->import(SetList::INSTANCEOF); $config->import(SetList::CODE_QUALITY); $config->import(SetList::DEAD_CODE); $config->import(SetList::PHP_82);