Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: make CI pass #109

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/examples/ export-ignore
/nginx/ export-ignore
/php-fpm/ export-ignore
/phpstan/ export-ignore
/tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
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\.#'
19 changes: 19 additions & 0 deletions phpstan/include-by-php-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

$includes = [];

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

if (PHP_VERSION_ID >= 80000) {
$includes[] = __DIR__ . '/php-80.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
6 changes: 6 additions & 0 deletions phpstan/php-80.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Strict comparison using === between array\\<string, mixed\\> and false will always evaluate to false\\.$#"
count: 1
path: ../src/Prometheus/RenderTextFormat.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