Skip to content

Commit c5a2183

Browse files
Updated readme
1 parent b029d7d commit c5a2183

2 files changed

Lines changed: 70 additions & 14 deletions

File tree

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,62 @@
88
![Packagist Downloads](https://img.shields.io/packagist/dt/codenamephp/deploymentchecks.base)
99
![GitHub](https://img.shields.io/github/license/codenamephp/deploymentchecks.base)
1010

11+
This package is the base building block for deployment checks. It provides the interfaces and basic execution logic needed to run checks.
12+
The checks itself will be provided by other specialized packages.
13+
14+
## What are deployment checks?
15+
16+
Deployment checks or Post-Deploy Verification or Post-Release Tests (whatever you want to call them, they are more or less the same concept) are used
17+
to verify that a deployment was successful and the application is running is expected.
18+
19+
These steps are usually performed as part of the CI/CD pipeline and are an important step when automating the deployment/release cycle.
20+
21+
They can either be run on the server itself or on a build/deployment "server" like Github Workflows either before the final rollout or after on the production
22+
resources.
23+
Depending on the outcome you can stop the rollout, perform a rollback ... or just be notified that something may be wrong.
24+
1125
## Installation
1226

1327
Easiest way is via composer. Just run `composer require codenamephp/deploymentchecks.base` in your cli which should
1428
install the latest version for you.
1529

16-
## Usage
30+
## Usage
31+
32+
### The very basics
33+
34+
The simplest case ist just PHP script that includes the autoloader, builds some checks, executes them and ends the script with an exit
35+
code and leaves the rest to the build system that was running the checks:
36+
37+
```php
38+
<?php declare(strict_types=1);
39+
40+
use de\codenamephp\deploymentchecks\async\Collection\AsyncCheckCollection;
41+
use de\codenamephp\deploymentchecks\base\Check\Result\WithExitCodeInterface;
42+
use de\codenamephp\deploymentchecks\base\ExitCode\DefaultExitCodes;
43+
use de\codenamephp\deploymentchecks\http\Check\HttpCheck;
44+
use de\codenamephp\deploymentchecks\http\Check\Test\StatusCode;
45+
use GuzzleHttp\Psr7\Request;
46+
47+
require_once __DIR__ . '/../vendor/autoload.php';
48+
49+
$result = (new AsyncCheckCollection(new \Spatie\Async\Pool(),
50+
new HttpCheck(
51+
new Request('GET', 'https://localhost'),
52+
'Frontpage should be available',
53+
new StatusCode(200),
54+
),
55+
new HttpCheck(
56+
new Request('GET', 'https://localhost/admin'),
57+
'Admin login page should be available',
58+
new StatusCode(401),
59+
)
60+
))->run();
61+
62+
exit($result instanceof WithExitCodeInterface ? $result->exitCode() : ($result->successful() ? DefaultExitCodes::SUCCESSFUL->value : DefaultExitCodes::ERROR->value));
63+
```
64+
65+
This example uses the http package to perform http requests and run tests on them together with the async package to the requests are tested in parallel.
66+
At the end the result is checked. If it is a result with an exit code, the exit code is used. If not, the result is checked for success and
67+
the default exit codes are used.
68+
69+
Since most CI/CD systems will run the script and check the exit code, this should already be enough to get the system to fail if one of the checks fail.

packages/test/src/test.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717
*/
1818

1919
use de\codenamephp\deploymentchecks\async\Collection\AsyncCheckCollection;
20+
use de\codenamephp\deploymentchecks\base\Check\Result\WithExitCodeInterface;
21+
use de\codenamephp\deploymentchecks\base\ExitCode\DefaultExitCodes;
2022
use de\codenamephp\deploymentchecks\http\Check\HttpCheck;
2123
use de\codenamephp\deploymentchecks\http\Check\Test\StatusCode;
2224
use GuzzleHttp\Psr7\Request;
2325

2426
require_once __DIR__ . '/../vendor/autoload.php';
2527

26-
$check1 = new HttpCheck(
27-
new Request('GET', 'https://www.google.com'),
28-
'Should be successful',
29-
new StatusCode(200),
30-
);
31-
$check2 = new HttpCheck(
32-
new Request('GET', 'https://www.google.com'),
33-
'Should fail',
34-
new StatusCode(200),
35-
);
36-
$result = (new AsyncCheckCollection(new \Spatie\Async\Pool(), $check1, $check2))->run();
37-
$successful = $result->successful();
38-
var_dump($successful, $result);
28+
$result = (new AsyncCheckCollection(new \Spatie\Async\Pool(),
29+
new HttpCheck(
30+
new Request('GET', 'https://localhost'),
31+
'Frontpage should be available',
32+
new StatusCode(200),
33+
),
34+
new HttpCheck(
35+
new Request('GET', 'https://localhost/admin'),
36+
'Admin login page should be available',
37+
new StatusCode(401),
38+
)
39+
))->run();
40+
41+
exit($result instanceof WithExitCodeInterface ? $result->exitCode() : ($result->successful() ? DefaultExitCodes::SUCCESSFUL->value : DefaultExitCodes::ERROR->value));

0 commit comments

Comments
 (0)