-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1024 from hydephp/update-monorepo-scripts
Internal: Update monorepo scripts
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
define('TIME_START', microtime(true)); | ||
|
||
/** | ||
* @internal This script is used to ping the CI server with the type coverage results. | ||
* | ||
* @example php __FILE__ ${{ secrets.CI_SERVER_TOKEN }} ${{ github.event.pull_request.head.sha }} ${{ github.head_ref }} | ||
* | ||
* @uses vendor/bin/psalm > psalmout.txt | ||
*/ | ||
echo "Pinging CI server\n"; | ||
|
||
$token = $argv[1] ?? exit(400); | ||
$commit = $argv[2] ?? exit(400); | ||
$branch = $argv[3] ?? 'master'; | ||
|
||
// Very inefficient, but it works fine for our purposes. | ||
function getCoverage(string $contents): float | ||
{ | ||
$lines = explode(PHP_EOL, $contents); | ||
foreach ($lines as $line) { | ||
if (str_starts_with($line, 'Psalm was able to infer types for ') && str_ends_with($line, '% of the codebase')) { | ||
return (float) substr($line, 34, -16); | ||
} | ||
} | ||
throw new \Exception('Could not find coverage in Psalm output'); | ||
} | ||
|
||
$data = [ | ||
'commit' => $commit, | ||
'coverage' => getCoverage(file_get_contents('psalmout.txt')), | ||
'time_ms' => (microtime(true) - TIME_START) * 1000, | ||
]; | ||
|
||
$url = 'https://ci.hydephp.se/api/github/actions/type-coverage'; | ||
|
||
$curl = curl_init($url); | ||
curl_setopt($curl, CURLOPT_URL, $url); | ||
curl_setopt($curl, CURLOPT_POST, true); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
|
||
$headers = [ | ||
'Accept: application/json', | ||
"Authorization: Bearer $token", | ||
'Content-Type: application/json', | ||
]; | ||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | ||
|
||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); | ||
|
||
$resp = curl_exec($curl); | ||
curl_close($curl); | ||
var_dump($resp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* @internal This script is used to ping the OpenAnalytics server with the test results. | ||
* | ||
* @example php ping.php 'Monorepo Smoke Tests' ${{ secrets.OPENANALYTICS_TOKEN }} | ||
* | ||
* @uses vendor/bin/pest --stop-on-failure --testdox-text testdox.txt | ||
*/ | ||
echo "Pinging statistics server\n"; | ||
|
||
$runner = $argv[1] ?? exit(400); | ||
$token = $argv[2] ?? exit(400); | ||
|
||
$url = 'https://analytics.hydephp.se/api/test_runs'; | ||
|
||
$curl = curl_init($url); | ||
curl_setopt($curl, CURLOPT_URL, $url); | ||
curl_setopt($curl, CURLOPT_POST, true); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
|
||
$headers = [ | ||
'Accept: application/json', | ||
"Authorization: Bearer $token", | ||
'Content-Type: application/json', | ||
]; | ||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | ||
|
||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([ | ||
'runner' => json_encode($runner), | ||
'tests' => substr_count(file_get_contents('testdox.txt') ?: exit(404), '[x]'), | ||
])); | ||
|
||
$resp = curl_exec($curl); | ||
curl_close($curl); | ||
var_dump($resp); |