Skip to content
Open
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ All notable changes to the packages are documented here. The format follows [Kee
### Added

- `witify/devops`: runs on Laravel 13. The `illuminate/*` constraints accept `^13.0`, the test suite runs on Testbench 11 and PHPUnit 12, and CI adds the PHP 8.4 + Laravel 13 pair.
- `witify/devops`: the version of the application is its latest GitHub release. The portal sends it in the `X-Release-Version` header of the health request, the package keeps it in the cache and shows it in the developer console.

### Changed

- `witify/devops`: the developer console hides the version when none is known, instead of showing it as unknown.

### Removed

- `witify/devops`: `APP_VERSION` and the `devops.version` config key are no longer read. Remove both from the application.

## [1.4.1] - 2026-09-24

Expand Down
18 changes: 12 additions & 6 deletions packages/devops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ composer require witify/devops

The service provider is discovered automatically.

Add the two variables to `.env` (and empty placeholders to `.env.example`):
Add the variable to `.env` (and an empty placeholder to `.env.example`):

```dotenv
PORTAL_HEALTH_TOKEN=
APP_VERSION=1.0.0
```

`PORTAL_HEALTH_TOKEN` is the secret the portal sends. Generate a random one per application. The endpoint answers `404` while the token is empty, so nothing is exposed before you configure it.

`APP_VERSION` is reported to the portal. Leave it out if the application has no version.
The version of the application needs no configuration: it is the latest GitHub release, which the portal sends with each health request (see [Release version](#release-version)).

### 1. Configure laravel-health

Expand Down Expand Up @@ -178,13 +177,21 @@ Then add the application in the portal with the same token.

- `checked_at` is `null` and `checks` is empty until `health:check` has stored results.
- `label_client` and a bilingual `message` are present for `ClientFacingCheck` subclasses. Other checks report the message laravel-health stored, in both languages.
- `sprintify_version` carries `APP_VERSION`. The key name is the one the portal reads, whatever the application is.
- `sprintify_version` carries the [release version](#release-version) the portal sent, `null` when it sent none. The key name is part of the contract with the portal, whatever the application is.
- `sentry_project_id` comes from `SENTRY_LARAVEL_DSN` or `SENTRY_DSN`.
- `github_repository` is read from `.git/config` of the deployed checkout and cached for seven days.
- `backup` reports the `bucket` of the backup disk and the backup name of spatie/laravel-backup. Both are `null` when absent.

The response is sent with `Cache-Control: no-store, private`.

### Release version

The repositories are private, so an application cannot read its GitHub releases without a GitHub token. The portal reads them and sends the tag of the latest one in the `X-Release-Version` header of its health request. The package keeps it in the default cache store.

- Only `1.2.3` and `v1.2.3` are accepted. Any other value is ignored.
- A version the portal stopped sending disappears after seven days.
- An application the portal does not call has no version: the developer console hides the line.

## Client-facing checks

A `ClientFacingCheck` describes a business process the client understands. Its label and message exist in French and English, resolved on the application so the portal never translates.
Expand Down Expand Up @@ -252,7 +259,7 @@ The package serves a developer console at `/devops` and the results page of lara
| Laravel Telescope | `laravel/telescope` is installed | `config('telescope.path')` |
| Logs | `opcodesio/log-viewer` or `arcanedev/log-viewer` is installed | the route path of the installed package |

Below the tools, the page shows a summary of the latest health run, the application information (environment, `APP_VERSION`, PHP and Laravel versions, debug and maintenance modes, cached configuration and routes, GitHub repository, Sentry project) and, when `sentry/sentry-laravel` is installed, a button that sends a test exception.
Below the tools, the page shows a summary of the latest health run, the application information (environment, [release version](#release-version), PHP and Laravel versions, debug and maintenance modes, cached configuration and routes, GitHub repository, Sentry project) and, when `sentry/sentry-laravel` is installed, a button that sends a test exception.

### Echo test

Expand Down Expand Up @@ -314,7 +321,6 @@ php artisan vendor:publish --tag="devops-config"
| Key | Default | Purpose |
|---|---|---|
| `token` | `env('PORTAL_HEALTH_TOKEN')` | bearer token expected by the endpoint |
| `version` | `env('APP_VERSION')` | version reported to the portal |
| `route.prefix` | `api/devops` | URL prefix of the endpoint |
| `route.middleware` | `['api']` | middleware groups applied before the token check |
| `sentry_dsn` | `env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN'))` | DSN parsed for the Sentry project id |
Expand Down
5 changes: 0 additions & 5 deletions packages/devops/config/devops.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
*/
'token' => env('PORTAL_HEALTH_TOKEN'),

/*
* Version of the application, reported to the portal.
*/
'version' => env('APP_VERSION'),

'route' => [
'prefix' => 'api/devops',
'middleware' => ['api'],
Expand Down
4 changes: 3 additions & 1 deletion packages/devops/resources/views/console.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
<h2>{{ __('devops::console.application.title') }}</h2>
<table>
<tr><th>{{ __('devops::console.application.environment') }}</th><td>{{ $application->environment }}</td></tr>
<tr><th>{{ __('devops::console.application.version') }}</th><td>{{ $application->version ?? __('devops::console.application.unknown') }}</td></tr>
@if ($application->version)
<tr><th>{{ __('devops::console.application.version') }}</th><td>{{ $application->version }}</td></tr>
@endif
<tr><th>{{ __('devops::console.application.php') }}</th><td>{{ $application->phpVersion }}</td></tr>
<tr><th>{{ __('devops::console.application.laravel') }}</th><td>{{ $application->laravelVersion }}</td></tr>
<tr><th>{{ __('devops::console.application.debug') }}</th><td>{{ $onOff($application->debug) }}</td></tr>
Expand Down
13 changes: 9 additions & 4 deletions packages/devops/src/Actions/GetApplicationInfoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ class GetApplicationInfoAction

private GetGitHubRepositoryAction $getGitHubRepositoryAction;

public function __construct(Application $application, GetGitHubRepositoryAction $getGitHubRepositoryAction)
{
private GetReleaseVersionAction $getReleaseVersionAction;

public function __construct(
Application $application,
GetGitHubRepositoryAction $getGitHubRepositoryAction,
GetReleaseVersionAction $getReleaseVersionAction
) {
$this->application = $application;
$this->getGitHubRepositoryAction = $getGitHubRepositoryAction;
$this->getReleaseVersionAction = $getReleaseVersionAction;
}

public function handle(): ApplicationInfoData
{
$version = config('devops.version');
$sentryDsn = config('devops.sentry_dsn');

return new ApplicationInfoData(
(string) config('app.name'),
(string) config('app.env'),
is_string($version) && $version !== '' ? $version : null,
$this->getReleaseVersionAction->handle(),
PHP_VERSION,
$this->application->version(),
(bool) config('app.debug'),
Expand Down
8 changes: 6 additions & 2 deletions packages/devops/src/Actions/GetPortalHealthAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ class GetPortalHealthAction

private GetGitHubRepositoryAction $getGitHubRepositoryAction;

private GetReleaseVersionAction $getReleaseVersionAction;

public function __construct(
ResultStore $resultStore,
Health $health,
GetGitHubRepositoryAction $getGitHubRepositoryAction
GetGitHubRepositoryAction $getGitHubRepositoryAction,
GetReleaseVersionAction $getReleaseVersionAction
) {
$this->resultStore = $resultStore;
$this->health = $health;
$this->getGitHubRepositoryAction = $getGitHubRepositoryAction;
$this->getReleaseVersionAction = $getReleaseVersionAction;
}

public function handle(): PortalHealthData
Expand Down Expand Up @@ -72,7 +76,7 @@ public function handle(): PortalHealthData
$checks,
new PortalHealthMetadataData(
(string) config('app.env'),
$this->nullableString(config('devops.version')),
$this->getReleaseVersionAction->handle(),
(new ParseSentryProjectIdAction($this->nullableString(config('devops.sentry_dsn'))))->handle(),
$this->getGitHubRepositoryAction->handle(),
new PortalHealthBackupData(
Expand Down
17 changes: 17 additions & 0 deletions packages/devops/src/Actions/GetReleaseVersionAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Witify\Devops\Actions;

use Illuminate\Support\Facades\Cache;

class GetReleaseVersionAction
{
public const CACHE_KEY = 'devops.release_version';

public function handle(): ?string
{
$version = Cache::get(self::CACHE_KEY);

return is_string($version) ? $version : null;
}
}
24 changes: 24 additions & 0 deletions packages/devops/src/Actions/StoreReleaseVersionAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Witify\Devops\Actions;

use Illuminate\Support\Facades\Cache;

class StoreReleaseVersionAction
{
public const HEADER = 'X-Release-Version';

private const VERSION_PATTERN = '/\Av?\d{1,9}\.\d{1,9}\.\d{1,9}\z/';

/** The portal sends the version again every few minutes: one it stopped sending expires. */
private const CACHE_TTL_SECONDS = 7 * 24 * 60 * 60;

public function handle(?string $version): void
{
if ($version === null || preg_match(self::VERSION_PATTERN, $version) !== 1) {
return;
}

Cache::put(GetReleaseVersionAction::CACHE_KEY, $version, self::CACHE_TTL_SECONDS);
}
}
11 changes: 9 additions & 2 deletions packages/devops/src/Http/Controllers/PortalHealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
namespace Witify\Devops\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Witify\Devops\Actions\GetPortalHealthAction;
use Witify\Devops\Actions\StoreReleaseVersionAction;

class PortalHealthController
{
public function __invoke(GetPortalHealthAction $getPortalHealthAction): JsonResponse
{
public function __invoke(
Request $request,
StoreReleaseVersionAction $storeReleaseVersionAction,
GetPortalHealthAction $getPortalHealthAction
): JsonResponse {
$storeReleaseVersionAction->handle($request->header(StoreReleaseVersionAction::HEADER));

return response()
->json($getPortalHealthAction->handle()->toArray())
->header('Cache-Control', 'no-store, private');
Expand Down
16 changes: 14 additions & 2 deletions packages/devops/tests/DeveloperConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Spatie\Health\Commands\RunHealthChecksCommand;
use Spatie\Health\Facades\Health;
use Witify\Devops\Actions\GetGitHubRepositoryAction;
use Witify\Devops\Actions\GetReleaseVersionAction;
use Witify\Devops\Tests\Fixtures\TechnicalCheck;

class DeveloperConsoleTest extends TestCase
Expand All @@ -23,7 +24,6 @@ protected function setUp(): void
config()->set([
'app.name' => 'Client Example',
'app.debug' => false,
'devops.version' => '2.4.0',
'devops.sentry_dsn' => 'https://public-key@organization.ingest.sentry.io/123456',
]);
}
Expand Down Expand Up @@ -58,16 +58,28 @@ public function test_it_lists_the_detected_tools_and_the_configured_links(): voi

public function test_it_shows_the_application_information(): void
{
Cache::forever(GetReleaseVersionAction::CACHE_KEY, 'v2.4.0');

$this->get('/devops')
->assertOk()
->assertSee('Client Example')
->assertSee('2.4.0')
->assertSee('<th>Version</th><td>v2.4.0</td>', false)
->assertSee(PHP_VERSION)
->assertSee(app()->version())
->assertSee('href="https://github.com/witify/sprintify"', false)
->assertSee('123456');
}

public function test_it_hides_the_version_until_the_portal_sends_one(): void
{
config()->set('devops.version', '9.9.9');

$this->get('/devops')
->assertOk()
->assertDontSee('<th>Version</th>', false)
->assertDontSee('9.9.9');
}

public function test_it_tells_when_no_health_results_exist_yet(): void
{
$this->get('/devops')
Expand Down
61 changes: 57 additions & 4 deletions packages/devops/tests/PortalHealthControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Spatie\Health\Commands\RunHealthChecksCommand;
use Spatie\Health\Facades\Health;
use Witify\Devops\Actions\GetGitHubRepositoryAction;
use Witify\Devops\Actions\GetReleaseVersionAction;
use Witify\Devops\Checks\FailedJobsCheck;
use Witify\Devops\Models\FailedJob;
use Witify\Devops\Tests\Fixtures\TechnicalCheck;
Expand All @@ -23,6 +24,7 @@ protected function setUp(): void

TechnicalCheck::$runCount = 0;
Cache::forget(GetGitHubRepositoryAction::CACHE_KEY);
Cache::forget(GetReleaseVersionAction::CACHE_KEY);

Schema::create('failed_jobs', function (Blueprint $table): void {
$table->id();
Expand All @@ -38,7 +40,6 @@ protected function setUp(): void
'app.name' => 'Client Example',
'app.env' => 'production',
'devops.token' => 'expected-health-token',
'devops.version' => '1.0.0',
'devops.sentry_dsn' => 'https://public-key@organization.ingest.sentry.io/123456',
'filesystems.disks.backup.bucket' => 'client-backups',
'backup.backup.name' => 'https---client-example-test',
Expand Down Expand Up @@ -95,7 +96,7 @@ public function test_it_returns_the_latest_stored_health_results_and_project_met
$this->assertSame(1, TechnicalCheck::$runCount);

$response = $this->withToken('expected-health-token')
->getJson('/api/devops/health')
->getJson('/api/devops/health', ['X-Release-Version' => 'v1.0.0'])
->assertOk()
->assertExactJson([
'app' => 'Client Example',
Expand Down Expand Up @@ -127,7 +128,7 @@ public function test_it_returns_the_latest_stored_health_results_and_project_met
],
'meta' => [
'environment' => 'production',
'sprintify_version' => '1.0.0',
'sprintify_version' => 'v1.0.0',
'sentry_project_id' => 123456,
'github_repository' => 'witify/sprintify',
'backup' => [
Expand Down Expand Up @@ -167,7 +168,6 @@ public function test_it_returns_an_empty_snapshot_when_no_results_have_been_stor
public function test_it_reports_null_metadata_when_the_host_has_no_version_sentry_or_backup(): void
{
config()->set([
'devops.version' => null,
'devops.sentry_dsn' => null,
'filesystems.disks.backup.bucket' => null,
'backup.backup.name' => null,
Expand All @@ -184,6 +184,59 @@ public function test_it_reports_null_metadata_when_the_host_has_no_version_sentr
->assertJsonPath('meta.backup.prefix', null);
}

public function test_it_keeps_the_release_version_sent_by_the_portal(): void
{
Carbon::setTestNow(Carbon::parse('2026-08-06 14:00:00', 'UTC'));

$this->assertReportedVersion(null, []);
$this->assertReportedVersion('v1.0.0', ['X-Release-Version' => 'v1.0.0']);
$this->assertReportedVersion('v1.0.0', []);
$this->assertReportedVersion('2.10.3', ['X-Release-Version' => '2.10.3']);

Carbon::setTestNow(Carbon::parse('2026-08-13 13:59:00', 'UTC'));
$this->assertReportedVersion('2.10.3', []);

Carbon::setTestNow(Carbon::parse('2026-08-13 14:01:00', 'UTC'));
$this->assertReportedVersion(null, []);
}

public function test_it_ignores_a_release_version_that_is_not_a_version(): void
{
$this->assertReportedVersion('v1.0.0', ['X-Release-Version' => 'v1.0.0']);

foreach (['', 'v1', '1.0', 'latest', 'v2.0.0-beta', '<b>v2.0.0</b>', "v2.0.0\n"] as $version) {
$this->assertReportedVersion('v1.0.0', ['X-Release-Version' => $version]);
}
}

public function test_it_ignores_the_release_version_of_a_request_with_a_wrong_token(): void
{
$this->withToken('incorrect-health-token')
->getJson('/api/devops/health', ['X-Release-Version' => 'v6.6.6'])
->assertForbidden();

$this->assertReportedVersion(null, []);
}

public function test_it_no_longer_reports_the_version_of_the_configuration(): void
{
config()->set('devops.version', '9.9.9');

$this->assertReportedVersion(null, []);
}

/**
* @param array<string, string> $headers
*/
private function assertReportedVersion(?string $version, array $headers): void
{
$this->flushHeaders()
->withToken('expected-health-token')
->getJson('/api/devops/health', $headers)
->assertOk()
->assertJsonPath('meta.sprintify_version', $version);
}

public function test_it_returns_a_null_repository_when_the_git_config_disappears_before_reading(): void
{
File::partialMock();
Expand Down
Loading