diff --git a/CHANGELOG.md b/CHANGELOG.md index d051b8b..4113391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/devops/README.md b/packages/devops/README.md index 0b3e60e..433a968 100644 --- a/packages/devops/README.md +++ b/packages/devops/README.md @@ -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 @@ -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. @@ -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 @@ -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 | diff --git a/packages/devops/config/devops.php b/packages/devops/config/devops.php index 93c2162..caa77dd 100644 --- a/packages/devops/config/devops.php +++ b/packages/devops/config/devops.php @@ -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'], diff --git a/packages/devops/resources/views/console.blade.php b/packages/devops/resources/views/console.blade.php index 247a0da..0e0f90c 100644 --- a/packages/devops/resources/views/console.blade.php +++ b/packages/devops/resources/views/console.blade.php @@ -127,7 +127,9 @@
| {{ __('devops::console.application.environment') }} | {{ $application->environment }} |
|---|---|
| {{ __('devops::console.application.version') }} | {{ $application->version ?? __('devops::console.application.unknown') }} |
| {{ __('devops::console.application.version') }} | {{ $application->version }} |
| {{ __('devops::console.application.php') }} | {{ $application->phpVersion }} |
| {{ __('devops::console.application.laravel') }} | {{ $application->laravelVersion }} |
| {{ __('devops::console.application.debug') }} | {{ $onOff($application->debug) }} | Version | v2.4.0 | ', 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('Version | ', false) + ->assertDontSee('9.9.9'); + } + public function test_it_tells_when_no_health_results_exist_yet(): void { $this->get('/devops') diff --git a/packages/devops/tests/PortalHealthControllerTest.php b/packages/devops/tests/PortalHealthControllerTest.php index 178f2ef..fe6b382 100644 --- a/packages/devops/tests/PortalHealthControllerTest.php +++ b/packages/devops/tests/PortalHealthControllerTest.php @@ -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; @@ -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(); @@ -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', @@ -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', @@ -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' => [ @@ -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, @@ -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', 'v2.0.0', "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