From 693e82cd971d8b28d957016c68978fdfb341c40a Mon Sep 17 00:00:00 2001 From: Herbert Roth Date: Mon, 20 Jan 2025 16:10:52 +0100 Subject: [PATCH] Update static analysis. --- .github/workflows/codeception.yaml | 114 +++++++++++++------ .github/workflows/static-analysis.yaml | 145 +++++++++++++++---------- composer.json | 5 +- 3 files changed, 169 insertions(+), 95 deletions(-) diff --git a/.github/workflows/codeception.yaml b/.github/workflows/codeception.yaml index c60432f..a8e3c00 100644 --- a/.github/workflows/codeception.yaml +++ b/.github/workflows/codeception.yaml @@ -1,50 +1,94 @@ -name: "Codeception Tests" +name: "Codeception Tests centralised" on: - # Enable Later. - #schedule: - # - cron: '0 3 * * 1,3,5' - pull_request: - branches: - - "[0-9]+.[0-9]+" - - "[0-9]+.x" - - "feature-*" + schedule: + - cron: '0 3 * * 1,3,5' + workflow_dispatch: push: branches: - "[0-9]+.[0-9]+" - "[0-9]+.x" + - "feature-*" + pull_request: + types: [opened, synchronize, reopened] env: PIMCORE_PROJECT_ROOT: ${{ github.workspace }} - APP_ENV: test - PIMCORE_TEST: 1 + PRIVATE_REPO: ${{ github.event.repository.private }} jobs: - codeception-tests: - name: "Codeception tests" - runs-on: "ubuntu-20.04" - continue-on-error: ${{ matrix.experimental }} - strategy: - matrix: - include: - - { php-version: 8.3, dependencies: lowest, pimcore_version: "", experimental: false } - - { php-version: 8.4, dependencies: highest, pimcore_version: "", experimental: false } - + setup-matrix: + runs-on: ubuntu-latest + outputs: + php_versions: ${{ steps.parse-php-versions.outputs.php_versions }} + matrix: ${{ steps.set-matrix.outputs.matrix }} + private_repo: ${{ env.PRIVATE_REPO }} steps: - - name: "Checkout code" - uses: "actions/checkout@v2" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: xdebug - ini-values: display_errors=On, display_startup_errors=On, error_reporting=32767 - php-version: "${{ matrix.php-version }}" + - name: Checkout reusable workflow repo + uses: actions/checkout@v4 + with: + repository: pimcore/workflows-collection-public + ref: main + path: reusable-workflows - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" - with: - dependency-versions: "${{ matrix.dependencies }}" + - name: Parse PHP versions from composer.json + id: parse-php-versions + run: | + if [ -f composer.json ]; then + php_versions=$(jq -r '.require.php' composer.json | grep -oP '\d+\.\d+' | tr '\n' ',' | sed 's/,$//') + if [ -z "$php_versions" ]; then + echo "No PHP versions found in composer.json" + echo "Setting default PHP value" + echo "php_versions=default" >> $GITHUB_OUTPUT + else + echo "php_versions=$php_versions" >> $GITHUB_OUTPUT + echo "#### php versions #### : $php_versions" + fi + else + echo "composer.json not found" + exit 1 + fi - - name: "Run Codeception" - run: "vendor/bin/codecept run -c . -vvv --xml --coverage-xml" + - name: Set up matrix + id: set-matrix + run: | + php_versions="${{ steps.parse-php-versions.outputs.php_versions }}" + + MATRIX_JSON=$(cat reusable-workflows/codeception-tests-configuration/matrix-config.json) + + IFS=',' read -ra VERSIONS_ARRAY <<< "$php_versions" + + FILTERED_MATRIX_JSON=$(echo $MATRIX_JSON | jq --arg php_versions "$php_versions" ' + { + matrix: [ + .configs[] | + select(.php_version == $php_versions) | + .matrix[] + ] + }') + + ENCODED_MATRIX_JSON=$(echo $FILTERED_MATRIX_JSON | jq -c .) + + echo "matrix=${ENCODED_MATRIX_JSON}" >> $GITHUB_OUTPUT + + codeception-tests: + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + uses: pimcore/workflows-collection-public/.github/workflows/reusable-codeception-tests-centralized.yaml@main + with: + APP_ENV: test + PIMCORE_TEST: 1 + PRIVATE_REPO: ${{ needs.setup-matrix.outputs.private_repo}} + PHP_VERSION: ${{ matrix.matrix.php-version }} + DATABASE: ${{ matrix.matrix.database }} + SERVER_VERSION: ${{ matrix.matrix.server_version }} + DEPENDENCIES: ${{ matrix.matrix.dependencies }} + EXPERIMENTAL: ${{ matrix.matrix.experimental }} + PIMCORE_VERSION: ${{ matrix.matrix.pimcore_version }} + secrets: + SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER: ${{ secrets.SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER }} + COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN: ${{ secrets.COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 07ea600..9d4310b 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -1,66 +1,95 @@ -name: "Static Analysis" +name: "Static analysis centralised" on: - schedule: - - cron: '0 3 * * 1,3,5' - pull_request: - branches: - - "[0-9]+.[0-9]+" - - "[0-9]+.x" - - "feature-*" - paths-ignore: - #- 'doc/**' - - 'public/**' - push: - branches: - - "[0-9]+.[0-9]+" - - "[0-9]+.x" - - "*_actions" + schedule: + - cron: '0 3 * * 1,3,5' + workflow_dispatch: + push: + branches: + - "[0-9]+.[0-9]+" + - "[0-9]+.x" + - "feature-*" + pull_request: + types: [ opened, synchronize, reopened ] + + +env: + PIMCORE_PROJECT_ROOT: ${{ github.workspace }} + PRIVATE_REPO: ${{ github.event.repository.private }} jobs: - static-analysis-phpstan: - name: "Static Analysis with PHPStan" - runs-on: "ubuntu-20.04" - strategy: - matrix: - include: - - { php-version: "8.3", dependencies: "lowest", experimental: false } - - { php-version: "8.3", dependencies: "highest", experimental: false } - - { php-version: "8.4", dependencies: "highest", pimcore_version: "12.x-dev as 12.99.9", experimental: true } - steps: - - name: "Checkout code" - uses: actions/checkout@v2 + setup-matrix: + runs-on: ubuntu-latest + outputs: + php_versions: ${{ steps.parse-php-versions.outputs.php_versions }} + matrix: ${{ steps.set-matrix.outputs.matrix }} + private_repo: ${{ env.PRIVATE_REPO }} + 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: "Setup Pimcore environment" - run: | - .github/ci/scripts/setup-pimcore-environment.sh - - name: "Update Pimcore version" - env: - PIMCORE_VERSION: "${{ matrix.pimcore_version }}" - run: | - if [ ! -z "$PIMCORE_VERSION" ]; then - composer require --no-update pimcore/pimcore:"${PIMCORE_VERSION}" - fi - - name: "Install dependencies with Composer" - uses: ramsey/composer-install@v2 - with: - dependency-versions: "${{ matrix.dependencies }}" + - name: Checkout reusable workflow repo + uses: actions/checkout@v4 + with: + repository: pimcore/workflows-collection-public + ref: main + path: reusable-workflows - - name: "Run a static analysis with phpstan/phpstan" - run: vendor/bin/phpstan analyse --memory-limit=-1 + - name: Parse PHP versions from composer.json + id: parse-php-versions + run: | + if [ -f composer.json ]; then + php_versions=$(jq -r '.require.php' composer.json | grep -oP '\d+\.\d+' | tr '\n' ',' | sed 's/,$//') + if [ -z "$php_versions" ]; then + echo "No PHP versions found in composer.json" + echo "Setting default PHP value" + echo "php_versions=default" >> $GITHUB_OUTPUT + else + echo "php_versions=$php_versions" >> $GITHUB_OUTPUT + echo "#### php versions #### : $php_versions" + fi + else + echo "composer.json not found" + exit 1 + fi - - name: "Generate baseline file" - if: ${{ failure() }} - run: vendor/bin/phpstan analyse --memory-limit=-1 --generate-baseline + - name: Set up matrix + id: set-matrix + run: | + php_versions="${{ steps.parse-php-versions.outputs.php_versions }}" + + MATRIX_JSON=$(cat reusable-workflows/phpstan-configuration/matrix-config.json) + + IFS=',' read -ra VERSIONS_ARRAY <<< "$php_versions" + + FILTERED_MATRIX_JSON=$(echo $MATRIX_JSON | jq --arg php_versions "$php_versions" ' + { + matrix: [ + .configs[] | + select(.php_version == $php_versions) | + .matrix[] + ] + }') + + ENCODED_MATRIX_JSON=$(echo $FILTERED_MATRIX_JSON | jq -c .) + + echo "matrix=${ENCODED_MATRIX_JSON}" >> $GITHUB_OUTPUT - - name: "Upload baseline file" - if: ${{ failure() }} - uses: actions/upload-artifact@v4 - with: - name: phpstan-baseline.neon - path: phpstan-baseline.neon + static-analysis: + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + uses: pimcore/workflows-collection-public/.github/workflows/reusable-static-analysis-centralized.yaml@main + with: + APP_ENV: test + PIMCORE_TEST: 1 + PRIVATE_REPO: ${{ needs.setup-matrix.outputs.private_repo}} + PHP_VERSION: ${{ matrix.matrix.php-version }} + SYMFONY: ${{ matrix.matrix.symfony }} + DEPENDENCIES: ${{ matrix.matrix.dependencies }} + EXPERIMENTAL: ${{ matrix.matrix.experimental }} + PIMCORE_VERSION: ${{ matrix.matrix.pimcore_version }} + COMPOSER_OPTIONS: ${{ matrix.matrix.composer_options }} + secrets: + SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER: ${{ secrets.SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER }} + COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN: ${{ secrets.COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN }} \ No newline at end of file diff --git a/composer.json b/composer.json index 204f585..6e42094 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "prefer-stable": true, "minimum-stability": "dev", "require": { + "php": "~8.3.0 || ~8.4.0", "pimcore/pimcore": "12.x-dev", "opensearch-project/opensearch-php": "^2.2.0" }, @@ -25,8 +26,8 @@ "codeception/phpunit-wrapper": "^9", "codeception/module-asserts": "^2", "codeception/module-symfony": "^1.6.0 || ^3.1.1", - "phpstan/phpstan": "^1.10.5", - "phpstan/phpstan-symfony": "^1.2.20", + "phpstan/phpstan": "1.12.15", + "phpstan/phpstan-symfony": "^1.3.5", "phpunit/phpunit": "^9.3 || 10.2.7", "nyholm/psr7": "^1", "symfony/phpunit-bridge": "^6",