-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (137 loc) · 5.37 KB
/
Copy pathtests.yml
File metadata and controls
169 lines (137 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Tests
on:
push:
branches: [main]
pull_request:
# So a run can be asked for without pushing something to ask for it.
workflow_dispatch:
jobs:
tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: ${{ matrix.php }}
coverage: none
- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
- name: Unit tests
run: vendor/bin/unit-tests
coverage:
name: Coverage
runs-on: ubuntu-latest
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: '8.3'
coverage: none
- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
- name: Unit tests with coverage
run: phpdbg -qrr vendor/bin/unit-tests
# Only where the token is there, so a fork or a repository without it still passes.
- name: SonarCloud
if: env.SONAR_TOKEN != ''
# Reporting, not a gate: a token which has expired should not turn a green suite red.
continue-on-error: true
uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8.2.1
env:
SONAR_HOST_URL: https://sonarcloud.io
benchmark:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: '8.4'
coverage: none
- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
- name: Build a small application to measure
run: |
mkdir -p .benchmark/public
cat > .benchmark/public/index.php <<'PHP'
<?php
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../App.php';
use Quillstack\Framework\App;
use Quillstack\Framework\Interfaces\RouteProviderInterface;
echo json_encode((new App('', [
RouteProviderInterface::class => Benchmark\Routes::class,
]))->run());
PHP
cat > .benchmark/App.php <<'PHP'
<?php
namespace Benchmark;
use Psr\Http\Message\ServerRequestInterface;
use Quillstack\Framework\Interfaces\ControllerInterface;
use Quillstack\Framework\Interfaces\RouteProviderInterface;
use Quillstack\Response\Response;
use Quillstack\Router\Router;
final class HelloResponse extends Response
{
public function send(): array
{
return ['hello' => 'world'];
}
}
final class HelloController implements ControllerInterface
{
public function __construct(private readonly HelloResponse $response)
{
}
public function handle(ServerRequestInterface $request): HelloResponse
{
return $this->response;
}
}
final class Routes implements RouteProviderInterface
{
public function setRoutes(Router $router): void
{
$router->get('/', HelloController::class)->name('home');
$router->get('/users/:id', HelloController::class)->name('users.show');
}
}
PHP
- name: Measure
run: |
php -S 127.0.0.1:8088 -t .benchmark/public >/dev/null 2>&1 &
for i in $(seq 1 40); do curl -sf -o /dev/null http://127.0.0.1:8088/ && break; sleep 0.25; done
curl -sf -o /dev/null http://127.0.0.1:8088/ || { echo "The application did not answer"; exit 1; }
result=$(vendor/bin/benchmark benchmark:http:get http://127.0.0.1:8088/users/42 200 10)
echo "$result"
# A number, or the measurement did not happen — an empty one reads like a fast one.
echo "$result" | grep -qE '[0-9]+\.[0-9]+ requests per second' \
|| { echo "Nothing was measured"; exit 1; }
{
echo '### Benchmark'
echo
echo '```text'
echo "$result"
echo '```'
echo
echo '_Shared CI runners are noisy, so this is a number to read rather than a gate.'
echo 'Compare runs on the same machine before believing a change._'
} >> "$GITHUB_STEP_SUMMARY"
static-analysis:
name: Static analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: '8.3'
coverage: none
- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
- name: PHPStan
run: vendor/bin/phpstan analyse --no-progress