Skip to content

chore: fix release chain for php cs fixer #109

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

Merged
merged 1 commit into from
Sep 4, 2024
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
56 changes: 29 additions & 27 deletions generate_coverage_report.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
<?php

# This script generates JSON report for coverage badge github action and generates markdown report for coverage-diff github action
// This script generates JSON report for coverage badge github action and generates markdown report for coverage-diff github action

$outputPath = __DIR__ . "/cov/json/";
$markdownPath = __DIR__ . "/cov/markdown/";
$outputPath = __DIR__.'/cov/json/';
$markdownPath = __DIR__.'/cov/markdown/';

$contents = file_get_contents(__DIR__ . "/cov/xml/clover.xml");
$contents = file_get_contents(__DIR__.'/cov/xml/clover.xml');
$xml = simplexml_load_string($contents);
$arr = json_decode(json_encode($xml), true);

$metrics = $arr["project"]["metrics"]["@attributes"];
$metrics = $arr['project']['metrics']['@attributes'];

// Calculate coverage metrics
$statementsCovered = (int)$metrics["coveredstatements"];
$statementsTotal = (int)$metrics["statements"];
$statementsCovered = (int) $metrics['coveredstatements'];
$statementsTotal = (int) $metrics['statements'];
$statementsPct = $statementsTotal > 0 ? ($statementsCovered / $statementsTotal) * 100 : 0;

$functionsCovered = (int)$metrics["coveredmethods"];
$functionsTotal = (int)$metrics["methods"];
$functionsCovered = (int) $metrics['coveredmethods'];
$functionsTotal = (int) $metrics['methods'];
$functionsPct = $functionsTotal > 0 ? ($functionsCovered / $functionsTotal) * 100 : 0;

// Function to return color based on percentage
function getCoverageStatus($percentage) {
function getCoverageStatus($percentage)
{
if ($percentage >= 80) {
return ":green_circle:";
} elseif ($percentage >= 50) {
return ":yellow_circle:";
} else {
return ":red_circle:";
return ':green_circle:';
}
if ($percentage >= 50) {
return ':yellow_circle:';
}

return ':red_circle:';
}

// Generate JSON report
$map = [
"total" => [
"statements" => ["pct" => number_format($statementsPct, 2)],
]
'total' => [
'statements' => ['pct' => number_format($statementsPct, 2)],
],
];
file_put_contents($outputPath . "index.json", json_encode($map));
file_put_contents($outputPath.'index.json', json_encode($map));

// Generate Markdown report
$markdown = "# Code Coverage Report\n\n";
Expand All @@ -64,15 +66,15 @@ function getCoverageStatus($percentage) {
$markdown .= "| St. | File | Methods | Statements | Total Coverage |\n";
$markdown .= "|-----|------|---------|------------|----------------|\n";

foreach ($arr["project"]["file"] as $file) {
$filePath = 'src/' . explode('src/', $file["@attributes"]['name'])[1];
$fileMetrics = $file["metrics"]["@attributes"];
foreach ($arr['project']['file'] as $file) {
$filePath = 'src/'.explode('src/', $file['@attributes']['name'])[1];
$fileMetrics = $file['metrics']['@attributes'];

$methodsPct = $fileMetrics["methods"] > 0 ? ($fileMetrics["coveredmethods"] / $fileMetrics["methods"]) * 100 : 0;
$statementsPct = $fileMetrics["statements"] > 0 ? ($fileMetrics["coveredstatements"] / $fileMetrics["statements"]) * 100 : 0;
$methodsPct = $fileMetrics['methods'] > 0 ? ($fileMetrics['coveredmethods'] / $fileMetrics['methods']) * 100 : 0;
$statementsPct = $fileMetrics['statements'] > 0 ? ($fileMetrics['coveredstatements'] / $fileMetrics['statements']) * 100 : 0;

$fileElements = (int)$fileMetrics["elements"];
$fileCoveredElements = (int)$fileMetrics["coveredelements"];
$fileElements = (int) $fileMetrics['elements'];
$fileCoveredElements = (int) $fileMetrics['coveredelements'];
$totalCoveragePct = $fileElements > 0 ? ($fileCoveredElements / $fileElements) * 100 : 0;

$markdown .= sprintf(
Expand All @@ -87,4 +89,4 @@ function getCoverageStatus($percentage) {

$markdown .= "\n</details>\n";

file_put_contents($markdownPath . "coverage_report.md", $markdown);
file_put_contents($markdownPath.'coverage_report.md', $markdown);
47 changes: 26 additions & 21 deletions run_checks.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<?php

require_once(__DIR__ . '/vendor/autoload.php');
require_once __DIR__.'/vendor/autoload.php';

$host = getenv('FP_API_HOST');
$api_key = getenv('FP_PRIVATE_API_KEY');

use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use GuzzleHttp\Client;
use Fingerprint\ServerAPI\Webhook\WebhookVerifier;
use GuzzleHttp\Client;

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);

$dotenv->safeLoad();


$api_key = $_ENV['FP_PRIVATE_API_KEY'] ?? getenv('FP_PRIVATE_API_KEY') ?? "Private API Key not defined";
$visitor_id = $_ENV['FP_VISITOR_ID'] ?? getenv('FP_VISITOR_ID') ?? "Visitor ID not defined";
$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? "Request ID not defined";
$region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? "us";
$api_key = $_ENV['FP_PRIVATE_API_KEY'] ?? getenv('FP_PRIVATE_API_KEY') ?? 'Private API Key not defined';
$visitor_id = $_ENV['FP_VISITOR_ID'] ?? getenv('FP_VISITOR_ID') ?? 'Visitor ID not defined';
$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? 'Request ID not defined';
$region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? 'us';

$region = Configuration::REGION_GLOBAL;
if ($region_env === 'eu') {
if ('eu' === $region_env) {
$region = Configuration::REGION_EUROPE;
} else if ($region_env === 'ap') {
} elseif ('ap' === $region_env) {
$region = Configuration::REGION_ASIA;
}

Expand All @@ -44,64 +43,70 @@

try {
list($result, $response) = $client->getVisits($visitor_id);
if($result->getVisitorId() !== $visitor_id) {
if ($result->getVisitorId() !== $visitor_id) {
throw new Exception('Argument visitorId is not equal to deserialized getVisitorId');
}
fwrite(STDOUT, sprintf("Got visits: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));

exit(1);
}

try {
/** @var $result \Fingerprint\ServerAPI\Model\EventResponse */
/** @var \Fingerprint\ServerAPI\Model\EventResponse $result */
list($result, $response) = $client->getEvent($request_id);
if($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
if ($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
throw new Exception('Argument requestId is not equal to deserialized getRequestId');
}
fwrite(STDOUT, sprintf("\n\nGot event: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));

exit(1);
}

$eventPromise = $client->getEventAsync($request_id);
$eventPromise->then(function ($tuple) use($request_id) {
$eventPromise->then(function ($tuple) use ($request_id) {
list($result, $response) = $tuple;
if($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
if ($result->getProducts()->getIdentification()->getData()->getRequestId() !== $request_id) {
throw new Exception('Argument requestId is not equal to deserialized getRequestId');
}
fwrite(STDOUT, sprintf("\n\nGot async event: %s \n", $response->getBody()->getContents()));
}, function($exception) {
}, function ($exception) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $exception->getMessage()));

exit(1);
})->wait();

$visitsPromise = $client->getVisitsAsync($visitor_id);
$visitsPromise->then(function($tuple) use($visitor_id) {
$visitsPromise->then(function ($tuple) use ($visitor_id) {
list($result, $response) = $tuple;
if($result->getVisitorId() !== $visitor_id) {
if ($result->getVisitorId() !== $visitor_id) {
throw new Exception('Argument visitorId is not equal to deserialized getVisitorId');
}
fwrite(STDOUT, sprintf("\n\nGot async visits: %s \n", $response->getBody()->getContents()));
}, function ($exception) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $exception->getMessage()));

exit(1);
})->wait();

$webhookSecret = "secret";
$webhookData = "data";
$webhookHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db";
$webhookSecret = 'secret';
$webhookData = 'data';
$webhookHeader = 'v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db';
$isValidWebhookSign = WebhookVerifier::IsValidWebhookSignature($webhookHeader, $webhookData, $webhookSecret);
if($isValidWebhookSign) {
if ($isValidWebhookSign) {
fwrite(STDOUT, sprintf("\n\nVerified webhook signature\n"));
} else {
fwrite(STDERR, sprintf("\n\nWebhook signature verification failed\n"));

exit(1);
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

fwrite(STDOUT, "\n\nChecks passed\n");

exit(0);
4 changes: 1 addition & 3 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ rm -f ./src/Model/*

java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/fingerprint-server-api.yaml -o ./ -c config.json

if [ -z "$GITHUB_ACTIONS" ]; then
docker-compose run --rm lint
fi
docker run --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:${FIXER_VERSION:-3-php8.3} fix

# fix invalid code generated for structure with additionalProperties
(
Expand Down
9 changes: 5 additions & 4 deletions sealed_results_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
use Fingerprint\ServerAPI\Sealed\DecryptionKey;
use Fingerprint\ServerAPI\Sealed\Sealed;

require_once(__DIR__ . '/vendor/autoload.php');
require_once __DIR__.'/vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT'] ?? getenv('BASE64_SEALED_RESULT') ?? "");
$sealed_key = base64_decode($_ENV['BASE64_KEY'] ?? getenv('BASE64_KEY') ?? "");

$sealed_result = base64_decode($_ENV['BASE64_SEALED_RESULT'] ?? getenv('BASE64_SEALED_RESULT') ?? '');
$sealed_key = base64_decode($_ENV['BASE64_KEY'] ?? getenv('BASE64_KEY') ?? '');

// Temporarily suppress a million deprecated ArrayAccess return type warnings for readability
// Our SDK generator does not yet support PHP's new attributes system
Expand All @@ -24,11 +23,13 @@
fwrite(STDOUT, sprintf("Unsealed event: %s \n", $data));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when unsealing event: %s\n", $e->getMessage()));

exit(1);
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

fwrite(STDOUT, "Checks passed\n");

exit(0);
Loading
Loading