Skip to content

Commit

Permalink
ci: make CI pass
Browse files Browse the repository at this point in the history
- rework phpstan
- check multiple php versions
- fix errors

Signed-off-by: Simon Podlipsky <[email protected]>
  • Loading branch information
simPod committed Jan 30, 2023
1 parent cc0ba6d commit 5cb0571
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 19 deletions.
35 changes: 32 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on: [ push, pull_request ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true

name: Code Checks
steps:
Expand All @@ -29,5 +27,36 @@ jobs:
run: composer install --prefer-dist --no-interaction --no-suggest
- name: Run PHP Code Sniffer
run: ./vendor/bin/phpcs

phpstan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
name: PHPStan on PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-code-checks

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: "cs2pr"

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest
- name: Run PHPStan
run: php vendor/bin/phpstan analyse --autoload-file tests/bootstrap.php
run: "vendor/bin/phpstan analyse --autoload-file tests/bootstrap.php --error-format=checkstyle | cs2pr"
8 changes: 3 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
includes:
- phpstan/include-by-php-version.php

parameters:
level: 8
paths:
- src
- tests
reportUnmatchedIgnoredErrors: false
ignoreErrors:
-
# REDIS stuff only runs with it available
'#Constant REDIS_HOST not found\.#'
15 changes: 15 additions & 0 deletions phpstan/include-by-php-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

$includes = [];

if (PHP_VERSION_ID >= 70400) {
$includes[] = __DIR__ . '/php-74.neon';
}

$config = [];
$config['includes'] = $includes;
$config['parameters']['phpVersion'] = PHP_VERSION_ID;

return $config;
6 changes: 6 additions & 0 deletions phpstan/php-74.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Strict comparison using === between non\\-empty\\-array\\<int, string\\> and false will always evaluate to false\\.$#"
count: 1
path: ../src/Prometheus/Storage/RedisNg.php
1 change: 0 additions & 1 deletion src/Prometheus/RenderTextFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ private function escapeAllLabels(array $labelNames, Sample $sample): array

$labels = array_combine(array_merge($labelNames, $sample->getLabelNames()), $sample->getLabelValues());

/** @phpstan-ignore-next-line */
if ($labels === false) {
throw new RuntimeException('Unable to combine labels.');
}
Expand Down
19 changes: 9 additions & 10 deletions src/Prometheus/Storage/RedisNg.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ public function updateSummary(array $data): void
if (false === $json) {
throw new RuntimeException(json_last_error_msg());
}
$this->redis->setNx($metaKey, $json);
/** @phpstan-ignore-line */
$this->redis->setnx($metaKey, $json);

// store value key
$valueKey = $summaryKey . ':' . $this->valueKey($data);
Expand All @@ -301,8 +300,7 @@ public function updateSummary(array $data): void
if (false === $json) {
throw new RuntimeException(json_last_error_msg());
}
$this->redis->setNx($valueKey, $json);
/** @phpstan-ignore-line */
$this->redis->setnx($valueKey, $json);

// trick to handle uniqid collision
$done = false;
Expand Down Expand Up @@ -528,10 +526,15 @@ private function collectSummaries(): array
}
}
if (count($samples) === 0) {
$this->redis->del($valueKey);
if (isset($valueKey)) {
$this->redis->del($valueKey);
}

continue;
}

assert(isset($decodedLabelValues));

// Compute quantiles
sort($samples);
foreach ($data['quantiles'] as $quantile) {
Expand Down Expand Up @@ -560,11 +563,7 @@ private function collectSummaries(): array
];


if (count($data['samples']) > 0) {
$summaries[] = $data;
} else {
$this->redis->del($metaKey);
}
$summaries[] = $data;
}
return $summaries;
}
Expand Down

0 comments on commit 5cb0571

Please sign in to comment.