From 2940366cf8d26678374e9294bb9c623960376ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 8 Oct 2024 16:03:06 +0200 Subject: [PATCH] Split static analysis workflow This should allow downstream projects to better prepare for the Psalm removal: they can use the new phpstan workflow whenever they want to drop Psalm, and when all of them do, then we can drop the static analysis workflow form this repository. --- .github/workflows/phpstan.yml | 54 +++++++++++++++++++ .github/workflows/static-analysis.yml | 34 +----------- ...roperties.json => phpstan.properties.json} | 5 +- .../{static-analysis.yml => phpstan.yml} | 6 +-- 4 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/phpstan.yml rename workflow-templates/{static-analysis.properties.json => phpstan.properties.json} (65%) rename workflow-templates/{static-analysis.yml => phpstan.yml} (80%) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..c7373fa --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,54 @@ + +name: "Static Analysis with PHPStan" + +on: + workflow_call: + inputs: + php-version: + description: "The PHP version to use when running the job" + default: "8.3" + required: false + type: "string" + composer-root-version: + description: "The version of the package being tested, in case of circular dependencies." + required: false + type: "string" + composer-options: + description: "Additional flags for the composer install command." + default: "--prefer-dist" + required: false + type: "string" + +jobs: + phpstan: + name: "PHPStan" + runs-on: "ubuntu-22.04" + + strategy: + matrix: + php-version: + - "${{ inputs.php-version }}" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Set COMPOSER_ROOT_VERSION" + run: | + echo "COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}" >> $GITHUB_ENV + if: "${{ inputs.composer-root-version }}" + + - name: "Install dependencies with Composer" + uses: "ramsey/composer-install@v3" + with: + dependency-versions: "highest" + composer-options: "${{ inputs.composer-options }}" + + - name: "Run a static analysis with phpstan/phpstan" + run: "vendor/bin/phpstan analyse -v" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 391797b..80aad86 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,5 +1,5 @@ -name: "Static Analysis" +name: "Static Analysis (deprecated in favor of phpstan.yml)" on: workflow_call: @@ -21,37 +21,7 @@ on: jobs: phpstan: - name: "PHPStan" - runs-on: "ubuntu-22.04" - - strategy: - matrix: - php-version: - - "${{ inputs.php-version }}" - - steps: - - name: "Checkout code" - uses: "actions/checkout@v4" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - - - name: "Set COMPOSER_ROOT_VERSION" - run: | - echo "COMPOSER_ROOT_VERSION=${{ inputs.composer-root-version }}" >> $GITHUB_ENV - if: "${{ inputs.composer-root-version }}" - - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v3" - with: - dependency-versions: "highest" - composer-options: "${{ inputs.composer-options }}" - - - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan analyse -v" + uses: "./.github/workflows/phpstan.yml" psalm: name: "Psalm" diff --git a/workflow-templates/static-analysis.properties.json b/workflow-templates/phpstan.properties.json similarity index 65% rename from workflow-templates/static-analysis.properties.json rename to workflow-templates/phpstan.properties.json index e256cda..37187f7 100644 --- a/workflow-templates/static-analysis.properties.json +++ b/workflow-templates/phpstan.properties.json @@ -1,12 +1,11 @@ { - "name": "Static analysis", + "name": "Static analysis with PHPStan", "description": "Perform static analysis on the source code and tests", "iconName": "doctrine-logo", "categories": [ "PHP" ], "filePatterns": [ - "^phpstan\\.neon(?:\\.dist)$", - "^psalm\\.xml$" + "^phpstan\\.neon(?:\\.dist)$" ] } diff --git a/workflow-templates/static-analysis.yml b/workflow-templates/phpstan.yml similarity index 80% rename from workflow-templates/static-analysis.yml rename to workflow-templates/phpstan.yml index f59905f..623e2d7 100644 --- a/workflow-templates/static-analysis.yml +++ b/workflow-templates/phpstan.yml @@ -6,21 +6,19 @@ on: branches: - "*.x" paths: - - ".github/workflows/static-analysis.yml" + - ".github/workflows/phpstan.yml" - "composer.*" - "src/**" # but some packages use lib - "phpstan*" - - "psalm*" - "tests/**" push: branches: - "*.x" paths: - - ".github/workflows/static-analysis.yml" + - ".github/workflows/phpstan.yml" - "composer.*" - "src/**" # but some packages use lib - "phpstan*" - - "psalm*" - "tests/**" jobs: