From 3aef146b6c5f18405ce4ab6871a2fccbcb5c8924 Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Tue, 7 May 2024 23:11:27 +0200 Subject: [PATCH] [TASK] Update CI scripts --- .github/workflows/dependabot-auto-merge.yml | 48 ++++++++++++--------- .github/workflows/rector.yaml | 2 +- .gitignore | 3 +- rector.php => build/rector/rector.php | 47 +++++++++++--------- composer.json | 4 +- 5 files changed, 58 insertions(+), 46 deletions(-) rename rector.php => build/rector/rector.php (76%) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index bfe9483..986ede3 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -1,8 +1,10 @@ -# Based on https://github.com/spatie/package-skeleton-laravel/blob/main/.github/workflows/dependabot-auto-merge.yml +# Copied from https://github.com/spatie/package-skeleton-laravel/blob/main/.github/workflows/dependabot-auto-merge.yml +# See https://docs.github.com/en/enterprise-cloud@latest/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#enable-auto-merge-on-a-pull-request name: dependabot-auto-merge -on: - pull_request_target: - types: [opened, reopened] + +# We're using pull_request_target instead of pull_request due to permission issues with the pull_request target: +# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#responding-to-events +on: pull_request_target permissions: pull-requests: write @@ -10,33 +12,37 @@ permissions: jobs: dependabot: + name: "Dependabot auto-merge" runs-on: ubuntu-latest timeout-minutes: 5 + if: ${{ github.actor == 'dependabot[bot]' }} steps: - name: "Dependabot metadata" - id: dependabot-metadata + # https://docs.github.com/en/enterprise-cloud@latest/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#fetch-metadata-about-a-pull-request + id: metadata uses: dependabot/fetch-metadata@v2.1.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - - name: "Output updated dependencies (JSON)" - run: echo steps.dependabot-metadata.outputs.updated-dependencies-json - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: "Auto-merge Dependabot PRs for semver-minor updates" - if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} - run: gh pr merge --auto --squash "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + # does not work, see https://github.com/dependabot/fetch-metadata/issues/499 + # - name: "Auto-merge Dependabot PRs for semver-minor updates" + # if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-minor' }} + # run: gh pr merge --auto --rebase "$PR_URL" + # env: + # PR_URL: "${{ github.event.pull_request.html_url }}" + # github-token: "${{ secrets.GITHUB_TOKEN }}" + # + # - name: "Auto-merge Dependabot PRs for semver-patch updates" + # if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' }} + # run: gh pr merge --auto --rebase "$PR_URL" + # env: + # PR_URL: "${{ github.event.pull_request.html_url }}" + # github-token: "${{ secrets.GITHUB_TOKEN }}" - - name: "Auto-merge Dependabot PRs for semver-patch updates" - if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} - run: gh pr merge --auto --squash "$PR_URL" + - name: "Enable auto-merge" + if: ${{ steps.metadata.outputs.dependency-type == 'direct:development' }} + run: gh pr merge -R "${{ github.repository }}" --squash --auto "${{ github.event.pull_request.number }}" env: - PR_URL: ${{ github.event.pull_request.html_url }} GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml index a296baf..cfe3c3a 100644 --- a/.github/workflows/rector.yaml +++ b/.github/workflows/rector.yaml @@ -27,7 +27,7 @@ jobs: - uses: ramsey/composer-install@v3 - name: "Run Rector" - run: vendor/bin/rector --ansi + run: vendor/bin/rector process --config build/rector/rector.php --ansi - name: "Run PHP CS Fixer" run: vendor/bin/php-cs-fixer fix --ansi diff --git a/.gitignore b/.gitignore index 7687605..e9570d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.idea/ /.phpunit.cache/ -/build/ +/build/* +!/build/rector/ /vendor/ /.php-cs-fixer.cache /composer.lock diff --git a/rector.php b/build/rector/rector.php similarity index 76% rename from rector.php rename to build/rector/rector.php index 12cc1a4..023c4c9 100644 --- a/rector.php +++ b/build/rector/rector.php @@ -12,35 +12,40 @@ use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector; -use Rector\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector; use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; +use Rector\ValueObject\PhpVersion; -return RectorConfig::configure() - ->withPaths([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - // uncomment to reach your current PHP version - //->withPhpSets() - ->withSets([ +return static function (RectorConfig $rectorConfig) { + $rectorConfig->paths([ + __DIR__ . '/../../src', + __DIR__ . '/../../tests', + ]); + $rectorConfig->phpVersion(PhpVersion::PHP_74); + $rectorConfig->sets([ LevelSetList::UP_TO_PHP_74, - ]) - ->withRules([ - AddVoidReturnTypeWhereNoReturnRector::class, - TypedPropertyFromAssignsRector::class, - TypedPropertyFromStrictConstructorRector::class, - TypedPropertyFromStrictSetUpRector::class, + ]); + $rectorConfig->rules([ + // Privatization PrivatizeFinalClassMethodRector::class, - DeclareStrictTypesRector::class, - ReturnTypeFromStrictTypedPropertyRector::class, + + // TypeDeclaration AddMethodCallBasedStrictParamTypeRector::class, AddParamTypeFromPropertyTypeRector::class, + AddVoidReturnTypeWhereNoReturnRector::class, ReturnTypeFromStrictNativeCallRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, - ]) - //->withConfiguredRule(AddPropertyTypeDeclarationRector::class, []) - ->withConfiguredRule(AddParamTypeDeclarationRector::class, []) - ->withImportNames(true, true, false); + ReturnTypeFromStrictTypedPropertyRector::class, + + TypedPropertyFromAssignsRector::class, + TypedPropertyFromStrictConstructorRector::class, + TypedPropertyFromStrictSetUpRector::class, + + DeclareStrictTypesRector::class, + ]); + $rectorConfig->ruleWithConfiguration(AddParamTypeDeclarationRector::class, []); + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(false); +}; diff --git a/composer.json b/composer.json index c9fd7dc..cdd4898 100644 --- a/composer.json +++ b/composer.json @@ -52,13 +52,13 @@ "scripts": { "ci:composer:normalize": "@composer normalize --no-check-lock --dry-run", "ci:php:php-cs-fixer": "vendor/bin/php-cs-fixer fix -v --dry-run --diff", + "ci:php:rector": "vendor/bin/rector process --dry-run", "ci:php:stan": "vendor/bin/phpstan analyse --no-progress", - "ci:rector": "vendor/bin/rector process --dry-run", "ci:tests:acceptance": "vendor/bin/behat --no-colors --no-snippets --format junit --out reports", "ci:tests:unit": "vendor/bin/phpunit --no-coverage --colors=never", "fix:composer:normalize": "@composer normalize --no-check-lock", "fix:php:php-cs-fixer": "vendor/bin/php-cs-fixer fix", - "fix:rector": "vendor/bin/rector process", + "fix:php:rector": "vendor/bin/rector process", "local:clean": "rm -Rf build", "local:tests:acceptance": "vendor/bin/behat --colors --no-snippets", "local:tests:unit": "vendor/bin/phpunit --no-coverage",