Skip to content

Commit 4f58fd4

Browse files
authored
Merge pull request #1024 from hydephp/update-monorepo-scripts
Internal: Update monorepo scripts
2 parents 0881bbe + 7440aba commit 4f58fd4

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

.github/workflows/static-analysis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ jobs:
2121

2222
- name: Run Psalm
2323
id: analysis
24-
run: vendor/bin/psalm || echo EXIT_CODE=$? >> $GITHUB_OUTPUT || exit 0
24+
run: vendor/bin/psalm > psalmout.txt || echo EXIT_CODE=$? >> $GITHUB_OUTPUT || exit 0
25+
26+
- name: Ping CI server with coverage results
27+
run: php monorepo/scripts/ping-ci-server-with-type-coverage.php ${{ secrets.CI_SERVER_TOKEN }} ${{ github.event.pull_request.head.sha }} ${{ github.head_ref }}
2528

2629

2730
# Since GitHub Actions for some reason doesn't support exiting with warnings, we work around this by
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
define('TIME_START', microtime(true));
4+
5+
/**
6+
* @internal This script is used to ping the CI server with the type coverage results.
7+
*
8+
* @example php __FILE__ ${{ secrets.CI_SERVER_TOKEN }} ${{ github.event.pull_request.head.sha }} ${{ github.head_ref }}
9+
*
10+
* @uses vendor/bin/psalm > psalmout.txt
11+
*/
12+
echo "Pinging CI server\n";
13+
14+
$token = $argv[1] ?? exit(400);
15+
$commit = $argv[2] ?? exit(400);
16+
$branch = $argv[3] ?? 'master';
17+
18+
// Very inefficient, but it works fine for our purposes.
19+
function getCoverage(string $contents): float
20+
{
21+
$lines = explode(PHP_EOL, $contents);
22+
foreach ($lines as $line) {
23+
if (str_starts_with($line, 'Psalm was able to infer types for ') && str_ends_with($line, '% of the codebase')) {
24+
return (float) substr($line, 34, -16);
25+
}
26+
}
27+
throw new \Exception('Could not find coverage in Psalm output');
28+
}
29+
30+
$data = [
31+
'commit' => $commit,
32+
'coverage' => getCoverage(file_get_contents('psalmout.txt')),
33+
'time_ms' => (microtime(true) - TIME_START) * 1000,
34+
];
35+
36+
$url = 'https://ci.hydephp.se/api/github/actions/type-coverage';
37+
38+
$curl = curl_init($url);
39+
curl_setopt($curl, CURLOPT_URL, $url);
40+
curl_setopt($curl, CURLOPT_POST, true);
41+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
42+
43+
$headers = [
44+
'Accept: application/json',
45+
"Authorization: Bearer $token",
46+
'Content-Type: application/json',
47+
];
48+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
49+
50+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
51+
52+
$resp = curl_exec($curl);
53+
curl_close($curl);
54+
var_dump($resp);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* @internal This script is used to ping the OpenAnalytics server with the test results.
5+
*
6+
* @example php ping.php 'Monorepo Smoke Tests' ${{ secrets.OPENANALYTICS_TOKEN }}
7+
*
8+
* @uses vendor/bin/pest --stop-on-failure --testdox-text testdox.txt
9+
*/
10+
echo "Pinging statistics server\n";
11+
12+
$runner = $argv[1] ?? exit(400);
13+
$token = $argv[2] ?? exit(400);
14+
15+
$url = 'https://analytics.hydephp.se/api/test_runs';
16+
17+
$curl = curl_init($url);
18+
curl_setopt($curl, CURLOPT_URL, $url);
19+
curl_setopt($curl, CURLOPT_POST, true);
20+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
21+
22+
$headers = [
23+
'Accept: application/json',
24+
"Authorization: Bearer $token",
25+
'Content-Type: application/json',
26+
];
27+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
28+
29+
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([
30+
'runner' => json_encode($runner),
31+
'tests' => substr_count(file_get_contents('testdox.txt') ?: exit(404), '[x]'),
32+
]));
33+
34+
$resp = curl_exec($curl);
35+
curl_close($curl);
36+
var_dump($resp);

0 commit comments

Comments
 (0)