From 23560e32b11ca2e11d420279b2ea774c911aee1a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 27 Aug 2024 09:31:25 +0200 Subject: [PATCH] Update CI (#1909) * Update CI * Fix deprecation warning * Fix types --- .github/workflows/continuous-integration.yml | 33 +++++++------------- .github/workflows/lint.yml | 32 ++++++++++++------- .github/workflows/phpstan.yml | 32 ++++++------------- src/Monolog/Handler/ElasticsearchHandler.php | 1 + src/Monolog/Logger.php | 7 +++-- tests/Monolog/SignalHandlerTest.php | 2 +- 6 files changed, 47 insertions(+), 60 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index da5a5a7d..b97f4fb9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -5,7 +5,7 @@ on: - pull_request permissions: - contents: read # to fetch code (actions/checkout) + contents: read jobs: tests: @@ -43,8 +43,7 @@ jobs: composer-options: "--ignore-platform-req=php+" steps: - - name: "Checkout" - uses: "actions/checkout@v4" + - uses: "actions/checkout@v4" - name: Run CouchDB timeout-minutes: 3 @@ -58,8 +57,7 @@ jobs: with: mongodb-version: 5.0 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "${{ matrix.php-version }}" @@ -75,8 +73,7 @@ jobs: composer require --no-update --no-interaction --dev elasticsearch/elasticsearch:^7 composer config --no-plugins allow-plugins.ocramius/package-versions true - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v2" + - uses: "ramsey/composer-install@v2" with: dependency-versions: "${{ matrix.dependencies }}" composer-options: "${{ matrix.composer-options }}" @@ -132,8 +129,7 @@ jobs: es-version: "7.0.0" steps: - - name: "Checkout" - uses: "actions/checkout@v4" + - uses: "actions/checkout@v4" # required for elasticsearch - name: Configure sysctl limits @@ -149,8 +145,7 @@ jobs: with: stack-version: "${{ matrix.es-version }}" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "${{ matrix.php-version }}" @@ -165,8 +160,7 @@ jobs: if: "matrix.php-version == '7.4' && matrix.dependencies == 'lowest'" run: "composer config allow-plugins.ocramius/package-versions true" - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v2" + - uses: "ramsey/composer-install@v2" with: dependency-versions: "${{ matrix.dependencies }}" @@ -177,9 +171,9 @@ jobs: if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'" run: | composer remove --no-update --dev graylog2/gelf-php ruflin/elastica elasticsearch/elasticsearch rollbar/rollbar - composer require --no-update --no-interaction --dev ruflin/elastica elasticsearch/elasticsearch:^7 + composer require --no-update --no-interaction --dev ruflin/elastica:^7 elasticsearch/elasticsearch:^7 composer require --no-update psr/log:^3 - composer update -W + composer update composer exec phpunit -- --group Elasticsearch,Elastica --verbose tests-es-8: @@ -211,8 +205,7 @@ jobs: - "8.2.0" steps: - - name: "Checkout" - uses: "actions/checkout@v4" + - uses: "actions/checkout@v4" # required for elasticsearch - name: Configure sysctl limits @@ -228,8 +221,7 @@ jobs: with: stack-version: "${{ matrix.es-version }}" - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "${{ matrix.php-version }}" @@ -246,8 +238,7 @@ jobs: if: "matrix.php-version == '7.4' && matrix.dependencies == 'lowest'" run: "composer config allow-plugins.ocramius/package-versions true" - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v2" + - uses: "ramsey/composer-install@v2" with: dependency-versions: "${{ matrix.dependencies }}" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 708e2299..f23abf17 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,11 +1,11 @@ name: "PHP Lint" on: - push: - pull_request: + - push + - pull_request permissions: - contents: read # to fetch code (actions/checkout) + contents: read jobs: tests: @@ -17,19 +17,27 @@ jobs: matrix: php-version: - "7.2" - - "8.3" + - "nightly" steps: - - name: "Checkout" - uses: "actions/checkout@v4" + - uses: actions/checkout@v4 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - uses: shivammathur/setup-php@v2 with: - coverage: "none" - extensions: "intl" - ini-values: "memory_limit=-1" php-version: "${{ matrix.php-version }}" + coverage: none - name: "Lint PHP files" - run: "find src/ -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l -f" + run: | + hasErrors=0 + for f in $(find src/ tests/ -type f -name '*.php' ! -path '*/vendor/*' ! -path '*/Fixtures/*') + do + { error="$(php -derror_reporting=-1 -ddisplay_errors=1 -l -f $f 2>&1 1>&3 3>&-)"; } 3>&1; + if [ "$error" != "" ]; then + while IFS= read -r line; do echo "::error file=$f::$line"; done <<< "$error" + hasErrors=1 + fi + done + if [ $hasErrors -eq 1 ]; then + exit 1 + fi diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 2effa1eb..82a85db7 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -4,11 +4,8 @@ on: - push - pull_request -env: - COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" - permissions: - contents: read # to fetch code (actions/checkout) + contents: read jobs: tests: @@ -22,33 +19,22 @@ jobs: - "8.0" steps: - - name: "Checkout" - uses: "actions/checkout@v4" + - uses: actions/checkout@v4 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - uses: shivammathur/setup-php@v2 with: - coverage: "none" php-version: "${{ matrix.php-version }}" + coverage: none extensions: mongodb, redis, amqp - - name: Get composer cache directory - id: composercache - run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - name: Add require for mongodb/mongodb to make tests runnable run: "composer require ${{ env.COMPOSER_FLAGS }} mongodb/mongodb --dev --no-update" - - name: "Install latest dependencies" - # --ignore-platform-req=php here needed as long as elasticsearch/elasticsearch does not support php 8 - run: "composer update ${{ env.COMPOSER_FLAGS }} --ignore-platform-req=php" + - uses: ramsey/composer-install@v3 + with: + dependency-versions: highest + # --ignore-platform-req=php here needed as long as elasticsearch/elasticsearch does not support php 8 + composer-options: '--ignore-platform-req=php' - name: Run PHPStan run: composer phpstan diff --git a/src/Monolog/Handler/ElasticsearchHandler.php b/src/Monolog/Handler/ElasticsearchHandler.php index e88375c0..264b380d 100644 --- a/src/Monolog/Handler/ElasticsearchHandler.php +++ b/src/Monolog/Handler/ElasticsearchHandler.php @@ -187,6 +187,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler */ protected function createExceptionFromResponses($responses): Throwable { + // @phpstan-ignore offsetAccess.nonOffsetAccessible foreach ($responses['items'] ?? [] as $item) { if (isset($item['index']['error'])) { return $this->createExceptionFromError($item['index']['error']); diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 3c588a70..bf65d3c5 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -169,7 +169,7 @@ class Logger implements LoggerInterface, ResettableInterface private $logDepth = 0; /** - * @var \WeakMap<\Fiber, int>|null Keeps track of depth inside fibers to prevent infinite logging loops + * @var \WeakMap<\Fiber, int> Keeps track of depth inside fibers to prevent infinite logging loops */ private $fiberLogDepth; @@ -197,7 +197,7 @@ class Logger implements LoggerInterface, ResettableInterface if (\PHP_VERSION_ID >= 80100) { // Local variable for phpstan, see https://github.com/phpstan/phpstan/issues/6732#issuecomment-1111118412 - /** @var \WeakMap<\Fiber, int> $fiberLogDepth */ + /** @var \WeakMap<\Fiber, int> $fiberLogDepth */ $fiberLogDepth = new \WeakMap(); $this->fiberLogDepth = $fiberLogDepth; } @@ -345,6 +345,7 @@ class Logger implements LoggerInterface, ResettableInterface if ($this->detectCycles) { if (\PHP_VERSION_ID >= 80100 && $fiber = \Fiber::getCurrent()) { + // @phpstan-ignore offsetAssign.dimType $this->fiberLogDepth[$fiber] = $this->fiberLogDepth[$fiber] ?? 0; $logDepth = ++$this->fiberLogDepth[$fiber]; } else { @@ -753,7 +754,7 @@ class Logger implements LoggerInterface, ResettableInterface if (\PHP_VERSION_ID >= 80100) { // Local variable for phpstan, see https://github.com/phpstan/phpstan/issues/6732#issuecomment-1111118412 - /** @var \WeakMap<\Fiber, int> $fiberLogDepth */ + /** @var \WeakMap<\Fiber, int> $fiberLogDepth */ $fiberLogDepth = new \WeakMap(); $this->fiberLogDepth = $fiberLogDepth; } diff --git a/tests/Monolog/SignalHandlerTest.php b/tests/Monolog/SignalHandlerTest.php index bc511d08..b0cf772b 100644 --- a/tests/Monolog/SignalHandlerTest.php +++ b/tests/Monolog/SignalHandlerTest.php @@ -185,7 +185,7 @@ class SignalHandlerTest extends TestCase $logger = new Logger('test', array($handler = new TestHandler)); $errHandler = new SignalHandler($logger); $previousCalled = 0; - pcntl_signal(SIGURG, function ($signo, array $siginfo = null) use (&$previousCalled) { + pcntl_signal(SIGURG, function ($signo, ?array $siginfo = null) use (&$previousCalled) { ++$previousCalled; }); $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO, $callPrevious, false, false);