From c5b75c12851fa9fbb15273796f4f6096816213f3 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 | 49 +++++++++++++++++++ .github/workflows/static-analysis.yml | 34 +++---------- ...roperties.json => phpstan.properties.json} | 5 +- .../{static-analysis.yml => phpstan.yml} | 6 +-- 4 files changed, 60 insertions(+), 34 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} (79%) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..2170ec8 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,49 @@ + +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 (PHP: ${{ inputs.php-version }})" + runs-on: "ubuntu-22.04" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ inputs.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 9e6f4d8..b0aaf7d 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -21,35 +21,15 @@ on: jobs: phpstan: - name: "PHPStan (PHP: ${{ inputs.php-version }})" - runs-on: "ubuntu-22.04" - - steps: - - name: "Checkout code" - uses: "actions/checkout@v4" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ inputs.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" + name: "PHPStan (deprecated in favor of phpstan.yml)" + uses: "./.github/workflows/phpstan.yml" + with: + php-version: "${{ inputs.php-version }}" + composer-root-version: "${{ inputs.composer-root-version }}" + composer-options: "${{ inputs.composer-options }}" psalm: - name: "Psalm (PHP: ${{ inputs.php-version }})" + name: "Psalm (PHP: ${{ inputs.php-version }}, deprecated without a replacement)" runs-on: "ubuntu-22.04" steps: 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 79% rename from workflow-templates/static-analysis.yml rename to workflow-templates/phpstan.yml index 3d15207..075a7f4 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/**" - "phpstan*" - - "psalm*" - "tests/**" push: branches: - "*.x" paths: - - ".github/workflows/static-analysis.yml" + - ".github/workflows/phpstan.yml" - "composer.*" - "src/**" - "phpstan*" - - "psalm*" - "tests/**" jobs: