From af66a2fd7c7b2c380dedd4cbdc08484e31943716 Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Fri, 26 Jan 2024 22:40:26 +0100 Subject: [PATCH] [TASK] Improve CI inspired by TYPO3 EXT:tea --- .editorconfig | 4 + .github/dependabot.yaml | 22 ++-- .github/workflows/code_analysis.yaml | 95 +++++++++-------- .github/workflows/docs.yaml | 78 +++++++------- .github/workflows/monthly_pull_requests.yaml | 63 ++++++++++++ .github/workflows/rector.yaml | 102 ++++++++++--------- .github/workflows/weekly_pull_requests.yaml | 64 ------------ composer.json | 87 +++++++++------- 8 files changed, 267 insertions(+), 248 deletions(-) create mode 100644 .github/workflows/monthly_pull_requests.yaml delete mode 100644 .github/workflows/weekly_pull_requests.yaml diff --git a/.editorconfig b/.editorconfig index e2a5c9fdc..d82b61e7f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,4 +14,8 @@ insert_final_newline = true indent_style = tab [*.yaml.inc] +indent_size = 2 + +# YAML-Files +[{*.yml,*.yaml}] indent_size = 2 \ No newline at end of file diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index ec5cb99c6..205bc3c23 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -1,16 +1,14 @@ version: 2 updates: - - - package-ecosystem: composer - directory: "/" - open-pull-requests-limit: 5 - schedule: - interval: monthly + - package-ecosystem: composer + directory: "/" + open-pull-requests-limit: 5 + schedule: + interval: monthly - - - package-ecosystem: github-actions - directory: "/" - open-pull-requests-limit: 5 - schedule: - interval: monthly + - package-ecosystem: github-actions + directory: "/" + open-pull-requests-limit: 5 + schedule: + interval: monthly diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 8eebc2098..95efc3a29 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -1,55 +1,54 @@ name: Code Analysis on: - pull_request: null - push: - branches: - - "main" + pull_request: null + push: + branches: + - "main" env: - # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 - COMPOSER_ROOT_VERSION: "dev-main" + # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 + COMPOSER_ROOT_VERSION: "dev-main" jobs: - code_analysis: - strategy: - fail-fast: false - matrix: - php-versions: [ 7.4, 8.0, 8.1 ] - actions: - - - name: "PHP Linter" - run: vendor/bin/parallel-lint src config tests - - - - name: 'Composer Validate' - run: composer validate --ansi - - - - name: 'Tests' - run: vendor/bin/phpunit - - - - name: 'Check TYPO3 Rector configs' - run: composer check-typo3-rector - - - - name: 'PHPStan' - run: composer analyze - - name: "${{ matrix.php-versions }} ${{ matrix.actions.name }}" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - # see https://github.com/shivammathur/setup-php - - - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - coverage: none - - - uses: "ramsey/composer-install@v2" - - - run: ${{ matrix.actions.run }} + code_analysis: + strategy: + fail-fast: false + matrix: + php-versions: [ 7.4, 8.0, 8.1 ] + actions: + - name: "PHP Linter" + run: "composer ci:php:lint" + + - name: 'Composer Validate' + run: composer validate --strict --ansi + + - name: 'Tests' + run: vendor/bin/phpunit + + - name: 'Check TYPO3 Rector configs' + run: "composer ci:check-typo3-rector" + + - name: 'PHPStan' + run: "composer ci:php:stan" + + name: "${{ matrix.php-versions }} ${{ matrix.actions.name }}" + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + # see https://github.com/shivammathur/setup-php + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + + # see https://github.com/ramsey/composer-install + - name: "Install Composer dependencies" + uses: ramsey/composer-install@v2 + + - name: "Run command" + run: ${{ matrix.actions.run }} diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index e92e16535..3f3f7f78d 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -1,44 +1,48 @@ name: Docs on: - push: - branches: - - "main" + push: + branches: + - "main" env: - # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 - COMPOSER_ROOT_VERSION: "dev-main" + # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 + COMPOSER_ROOT_VERSION: "dev-main" jobs: - docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - coverage: none - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # see https://github.com/ramsey/composer-install - - uses: "ramsey/composer-install@v2" - - - name: Install rule doc generator - run: composer require symplify/rule-doc-generator:^11.1 --with-all-dependencies - - - name: Generate documentation - run: composer docs - - - name: Uninstall rule doc generator - run: composer remove symplify/rule-doc-generator - - - uses: stefanzweifel/git-auto-commit-action@v5.0.0 - with: - commit_message: '[DOCS] Generate documentation' - commit_options: '--no-verify --signoff' - branch: "main" - push_options: '--force' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + docs: + runs-on: ubuntu-latest + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + coverage: none + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # see https://github.com/ramsey/composer-install + - name: "Install Composer dependencies" + uses: ramsey/composer-install@v2 + + - name: "Install rule doc generator" + run: composer require symplify/rule-doc-generator:^11.1 --with-all-dependencies + + - name: "Generate documentation" + run: "composer docs:generate" + + - name: "Uninstall rule doc generator" + run: composer remove symplify/rule-doc-generator + + - name: "Commit documentation" + uses: stefanzweifel/git-auto-commit-action@v5.0.0 + with: + commit_message: '[DOCS] Generate documentation' + commit_options: '--no-verify --signoff' + branch: "main" + push_options: '--force' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/monthly_pull_requests.yaml b/.github/workflows/monthly_pull_requests.yaml new file mode 100644 index 000000000..ac5a6339d --- /dev/null +++ b/.github/workflows/monthly_pull_requests.yaml @@ -0,0 +1,63 @@ +name: Monthly Pull Requests + +on: + schedule: + # https://crontab.guru/every-month + - cron: "0 0 1 * *" + +env: + # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 + COMPOSER_ROOT_VERSION: "dev-main" + +jobs: + weekly_pull_requests: + # Don't run on forks. + if: github.repository == 'sabbelasichon/typo3-rector' + strategy: + fail-fast: false + matrix: + actions: + - name: 'Apply Coding Standard' + run: "composer fix:style" + branch: 'automated-apply-coding-standards' + + name: ${{ matrix.actions.name }} + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v4 + with: + token: ${{ secrets.ACCESS_TOKEN }} + + # see https://github.com/shivammathur/setup-php + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + + - name: "Install Composer dependencies" + uses: ramsey/composer-install@v2 + + - name: "Run command" + run: ${{ matrix.actions.run }} + + # see https://github.com/peter-evans/create-pull-request + - name: "Create pull-request" + uses: peter-evans/create-pull-request@v5.0.2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "[AUTOMATED] ${{ matrix.actions.name }}" + base: 'main' + branch: ${{ matrix.actions.branch }} + title: '[AUTOMATED] ${{ matrix.actions.name }}' + delete-branch: true + + - name: "Enable Pull Request Automerge" + if: steps.cpr.outputs.pull-request-operation == 'created' + uses: peter-evans/enable-pull-request-automerge@v3 + with: + token: ${{ secrets.ACCESS_TOKEN }} + pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} + merge-method: squash diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index ecb5e7b44..84e6f2ef8 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -13,62 +13,66 @@ name: Rector on: - pull_request: null + pull_request: null env: - # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 - COMPOSER_ROOT_VERSION: "dev-main" + # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 + COMPOSER_ROOT_VERSION: "dev-main" jobs: - rector: - # Don't run on forks. - if: github.repository == 'sabbelasichon/typo3-rector' - timeout-minutes: 10 - runs-on: ubuntu-latest - steps: - # workaround for missing secret in fork PRs - see https://github.com/actions/checkout/issues/298 - # see https://github.com/rectorphp/rector/commit/d395e1c28b8e6a56711dcc2e10490a82965850e4 - - - if: github.event.pull_request.head.repo.full_name == github.repository - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - # Must be used to trigger workflow after push - token: ${{ secrets.ACCESS_TOKEN }} + rector: + # Don't run on forks. + if: github.repository == 'sabbelasichon/typo3-rector' + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + # workaround for missing secret in fork PRs - see https://github.com/actions/checkout/issues/298 + # see https://github.com/rectorphp/rector/commit/d395e1c28b8e6a56711dcc2e10490a82965850e4 + - name: "Checkout" + if: github.event.pull_request.head.repo.full_name == github.repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + # Must be used to trigger workflow after push + token: ${{ secrets.ACCESS_TOKEN }} - # in forks, the token is not available - so we cannot use eit - - - if: github.event.pull_request.head.repo.full_name != github.repository - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} + # in forks, the token is not available - so we cannot use eit + - name: "Checkout" + if: github.event.pull_request.head.repo.full_name != github.repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} - - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.4 - coverage: none + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none - - run: composer install --no-progress --ansi + # see https://github.com/ramsey/composer-install + - name: "Install Composer dependencies" + uses: ramsey/composer-install@v2 - ## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future - - run: vendor/bin/rector process --ansi + ## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future + - name: "Run Rector" + run: "composer fix:rector" - - run: vendor/bin/ecs check --fix --ansi + - name: "Run Easy Coding Standard" + run: "composer fix:style" - # see https://github.com/EndBug/add-and-commit - - - # commit only to core contributors who have repository access - if: github.event.pull_request.head.repo.full_name == github.repository - uses: EndBug/add-and-commit@v9.1.3 - with: - # The arguments for the `git add` command (see the paragraph below for more info) - add: . - message: "[CI] Rector Rectify" - author_name: "GitHub Action" - author_email: "action@github.com" - env: - # to get push access - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + # see https://github.com/EndBug/add-and-commit + - name: "Commit changes" + # commit only to core contributors who have repository access + if: github.event.pull_request.head.repo.full_name == github.repository + uses: EndBug/add-and-commit@v9.1.3 + with: + # The arguments for the `git add` command (see the paragraph below for more info) + add: . + message: "[CI] Rector Rectify" + author_name: "GitHub Action" + author_email: "action@github.com" + env: + # to get push access + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/.github/workflows/weekly_pull_requests.yaml b/.github/workflows/weekly_pull_requests.yaml deleted file mode 100644 index 81684c46b..000000000 --- a/.github/workflows/weekly_pull_requests.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: Weekly Pull Requests - -on: - schedule: - # https://crontab.guru/once-a-week - - cron: "0 0 * * 0" - -env: - # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 - COMPOSER_ROOT_VERSION: "dev-main" - -jobs: - weekly_pull_requests: - # Don't run on forks. - if: github.repository == 'sabbelasichon/typo3-rector' - strategy: - fail-fast: false - matrix: - actions: - - - name: 'Apply Coding Standard' - run: "composer fix-style" - branch: 'automated-apply-coding-standards' - - - name: ${{ matrix.actions.name }} - runs-on: ubuntu-latest - - steps: - - - uses: actions/checkout@v4 - with: - token: ${{ secrets.ACCESS_TOKEN }} - - # see https://github.com/shivammathur/setup-php - - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.4 - coverage: none - - - uses: "ramsey/composer-install@v2" - - - run: ${{ matrix.actions.run }} - - # see https://github.com/peter-evans/create-pull-request - - - name: Create pull-request - uses: peter-evans/create-pull-request@v5.0.2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: "[AUTOMATED] ${{ matrix.actions.name }}" - base: 'main' - branch: ${{ matrix.actions.branch }} - title: '[AUTOMATED] ${{ matrix.actions.name }}' - delete-branch: true - - - name: Enable Pull Request Automerge - if: steps.cpr.outputs.pull-request-operation == 'created' - uses: peter-evans/enable-pull-request-automerge@v3 - with: - token: ${{ secrets.ACCESS_TOKEN }} - pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} - merge-method: squash diff --git a/composer.json b/composer.json index 825a48866..7c3b72800 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,11 @@ { "name": "ssch/typo3-rector", - "type": "rector-extension", "description": "Instant fixes for your TYPO3 code by using Rector.", - "keywords": ["dev"], - "homepage": "https://packagist.org/packages/ssch/typo3-rector", - "support": { - "docs": "https://github.com/sabbelasichon/typo3-rector/tree/main/docs", - "issues": "https://github.com/sabbelasichon/typo3-rector/issues", - "source": "https://github.com/sabbelasichon/typo3-rector", - "chat": "https://typo3.slack.com/archives/C019R5LAA6A" - }, "license": "MIT", + "type": "rector-extension", + "keywords": [ + "dev" + ], "authors": [ { "name": "Sebastian Schreiber", @@ -18,8 +13,18 @@ }, { "name": "Henrik Elsner" + }, + { + "name": "Simon Schaufelberger" } ], + "homepage": "https://packagist.org/packages/ssch/typo3-rector", + "support": { + "issues": "https://github.com/sabbelasichon/typo3-rector/issues", + "chat": "https://typo3.slack.com/archives/C019R5LAA6A", + "source": "https://github.com/sabbelasichon/typo3-rector", + "docs": "https://github.com/sabbelasichon/typo3-rector/tree/main/docs" + }, "require": { "php": "^7.4 || ^8.0", "ext-dom": "*", @@ -40,6 +45,7 @@ "webmozart/assert": "^1.11.0" }, "require-dev": { + "ergebnis/composer-normalize": "^2.28", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpstan/extension-installer": "^1.3.1", "phpstan/phpstan-phpunit": "^1.3.15", @@ -48,6 +54,9 @@ "symfony/http-kernel": "^5.4.34 || ^6.4.2 || ^7.0.2", "symplify/easy-coding-standard": "^12.1.8" }, + "conflict": { + "phpstan/phpstan": ">= 1.10.28" + }, "autoload": { "psr-4": { "Ssch\\TYPO3Rector\\": "src", @@ -55,7 +64,6 @@ } }, "autoload-dev": { - "classmap": ["stubs"], "psr-4": { "Ssch\\TYPO3Rector\\Generator\\": "utils/generator/src", "Ssch\\TYPO3Rector\\Tests\\": "tests", @@ -63,48 +71,51 @@ "Ssch\\TYPO3Rector\\Rules\\Tests\\": "utils/rules/tests", "Ssch\\TYPO3Rector\\Rules\\": "utils/rules/src" }, + "classmap": [ + "stubs" + ], "exclude-from-classmap": [ "**.php.inc" ] }, "config": { + "allow-plugins": { + "phpstan/extension-installer": true, + "ergebnis/composer-normalize": true + }, "optimize-autoloader": true, - "update-with-dependencies": true, - "sort-packages": true, "platform-check": false, - "allow-plugins": { - "phpstan/extension-installer": true - } - }, - "scripts": { - "contribute": [ - "@fix-rector", - "@fix-style", - "@analyze", - "@phpstan-generate-baseline" - ], - "check-style": "@php vendor/bin/ecs check --ansi", - "fix-style": "@php vendor/bin/ecs check --fix --ansi", - "analyze": "@php vendor/bin/phpstan analyse --memory-limit=-1 --ansi", - "phpstan-generate-baseline": "@php vendor/bin/phpstan analyse --generate-baseline --memory-limit=-1 --ansi --allow-empty-baseline", - "test": "@php vendor/bin/phpunit", - "docs": "@php vendor/bin/rule-doc-generator generate src --output-file docs/all_rectors_overview.md --ansi", - "rector": "@php vendor/bin/rector process --dry-run --ansi", - "fix-rector": "@php vendor/bin/rector process --ansi", - "check-typo3-rector": "@php vendor/bin/rector process src/Helper --config templates/rector.php --dry-run --ansi", - "lint-php": "@php vendor/bin/parallel-lint src config tests" + "sort-packages": true, + "update-with-dependencies": true }, "extra": { + "branch-alias": { + "dev-main": "1.0-dev" + }, "rector": { "includes": [ "config/config.php" ] - }, - "branch-alias": { - "dev-main": "1.0-dev" } }, - "conflict": { - "phpstan/phpstan": ">= 1.10.28" + "scripts": { + "ci:check-style": "@php vendor/bin/ecs check --ansi", + "ci:check-typo3-rector": "@php vendor/bin/rector process src/Helper --config templates/rector.php --dry-run --ansi", + "ci:composer:normalize": "@composer normalize --no-check-lock --dry-run", + "ci:php:lint": "@php vendor/bin/parallel-lint src config tests", + "ci:php:stan": "@php vendor/bin/phpstan analyse --memory-limit=-1 --ansi", + "ci:rector": "@php vendor/bin/rector process --dry-run --ansi", + "ci:tests:unit": "@php vendor/bin/phpunit", + "docs:generate": "@php vendor/bin/rule-doc-generator generate src --output-file docs/all_rectors_overview.md --ansi", + "fix:composer:normalize": "@composer normalize --no-check-lock", + "fix:rector": "@php vendor/bin/rector process --ansi", + "fix:style": "@php vendor/bin/ecs check --fix --ansi", + "local:contribute": [ + "@fix:rector", + "@fix:style", + "@ci:php:stan", + "@phpstan:baseline" + ], + "phpstan:baseline": "@php vendor/bin/phpstan analyse --generate-baseline --memory-limit=-1 --ansi --allow-empty-baseline" } }