Skip to content
This repository was archived by the owner on Nov 30, 2026. It is now read-only.
Merged
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
7 changes: 7 additions & 0 deletions app/Client/Requests/UpdateEnvironmentRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
public readonly ?string $buildCommand = null,
public readonly ?string $nodeVersion = null,
public readonly ?string $deployCommand = null,
public readonly ?string $postDeployCommand = null,
/** @var string|null '' clears it */
public readonly ?string $startCommand = null,
public readonly ?bool $usesVanityDomain = null,
Expand Down Expand Up @@ -46,6 +47,9 @@ public function __construct(
public readonly ?bool $firewallBrowserIntegrityCheck = null,
/** @var array{mode: 'process', root: string|null}|null */
public readonly ?array $serving = null,
public readonly ?bool $usesHttpBasicAuth = null,
#[SensitiveParameter]
public readonly ?string $httpBasicAuthPassword = null,
) {
//
}
Expand All @@ -64,6 +68,7 @@ public function toRequestData(): array
'build_command' => $this->buildCommand,
'node_version' => $this->nodeVersion,
'deploy_command' => $this->deployCommand,
'post_deploy_command' => $this->postDeployCommand,
'start_command' => $this->startCommand,
'uses_vanity_domain' => $this->usesVanityDomain,
'database_schema_id' => $this->databaseSchemaId,
Expand All @@ -84,6 +89,8 @@ public function toRequestData(): array
'firewall_block_path' => $this->firewallBlockPath,
'firewall_browser_integrity_check' => $this->firewallBrowserIntegrityCheck,
'serving' => $this->serving,
'uses_http_basic_auth' => $this->usesHttpBasicAuth,
'http_basic_auth_password' => $this->httpBasicAuthPassword,
]);

// filter() drops nulls, so the CLI's '' stands in for the explicit null the API needs to clear these.
Expand Down
28 changes: 28 additions & 0 deletions app/Commands/EnvironmentUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ class EnvironmentUpdate extends BaseCommand
{--branch= : Git branch}
{--build-command= : Build command}
{--deploy-command= : Deploy command}
{--post-deploy-command= : Commands run after the deployment goes live}
{--start-command= : Start command for non-PHP dynamic apps (empty string to clear)}
{--php-version= : PHP version (8.2:1, 8.3:1, 8.4:1, 8.5:1)}
{--node-version= : Node version (20, 22, 24, 26)}
{--uses-push-to-deploy= : Deploy on push}
{--uses-deploy-hook= : Enable the deploy hook}
{--uses-vanity-domain= : Serve the Laravel Cloud domain}
{--uses-octane= : Uses Octane}
{--http-basic-auth-password= : Require visitors to sign in as `admin` with this password; pass an empty value to turn basic auth off}
{--uses-purge-edge-cache-on-deploy= : Purge the edge cache on deploy}
{--timeout= : Request timeout in seconds (5-60)}
{--shutdown-timeout= : Seconds to keep the previous deployment running (1-600)}
Expand Down Expand Up @@ -95,6 +97,9 @@ public function handle()

protected function updateEnvironment(Environment $environment): Environment
{
// The API turns basic auth on only alongside a password, so one option covers both: a password turns it on, empty turns it off.
$httpBasicAuthPassword = $this->form()->get('http_basic_auth_password');

spin(
fn () => $this->client->environments()->update(
new UpdateEnvironmentRequestData(
Expand All @@ -110,6 +115,7 @@ protected function updateEnvironment(Environment $environment): Environment
buildCommand: $this->form()->get('build_command'),
nodeVersion: $this->form()->get('node_version'),
deployCommand: $this->form()->get('deploy_command'),
postDeployCommand: $this->form()->get('post_deploy_command'),
startCommand: $this->form()->get('start_command'),
usesVanityDomain: $this->form()->boolean('uses_vanity_domain'),
databaseSchemaId: $this->form()->get('database_id'),
Expand All @@ -128,6 +134,8 @@ protected function updateEnvironment(Environment $environment): Environment
responseHeadersHsts: $this->hsts($environment),
firewallBlockPath: $this->form()->boolean('firewall_block_path'),
firewallBrowserIntegrityCheck: $this->form()->boolean('firewall_browser_integrity_check'),
usesHttpBasicAuth: $httpBasicAuthPassword === null ? null : filled($httpBasicAuthPassword),
httpBasicAuthPassword: filled($httpBasicAuthPassword) ? $httpBasicAuthPassword : null,
),
),
'Updating environment...',
Expand Down Expand Up @@ -227,6 +235,17 @@ protected function defineFields(Environment $environment): void
'deploy-command',
)->setPreviousValue($environment->deployCommand ?? '');

$this->form()->define(
'post_deploy_command',
fn ($resolver) => $resolver->fromInput(
fn ($value) => textarea(
label: 'Post-deploy command',
default: $value ?? $environment->postDeployCommand ?? '',
),
),
'post-deploy-command',
)->setPreviousValue($environment->postDeployCommand ?? '');

$this->form()->define(
'start_command',
fn ($resolver) => $resolver->fromInput(
Expand Down Expand Up @@ -256,6 +275,15 @@ protected function defineFields(Environment $environment): void
$this->defineBoolean('uses_deploy_hook', 'Deploy hook', $environment->usesDeployHook);
$this->defineBoolean('uses_vanity_domain', 'Vanity domain', null);
$this->defineBoolean('uses_octane', 'Octane', $environment->usesOctane);
$this->form()->define(
'http_basic_auth_password',
fn ($resolver) => $resolver->fromInput(
fn ($value) => confirm(label: 'HTTP basic auth?', default: $environment->usesHttpBasicAuth)
? password(label: 'HTTP basic auth password', required: true, hint: 'Visitors sign in as `admin`')
: '',
),
)->setPreviousValue(var_export($environment->usesHttpBasicAuth, true))->setLabel('HTTP basic auth');

$this->defineBoolean('uses_purge_edge_cache_on_deploy', 'Purge edge cache on deploy', null);

$this->defineNumber('timeout', 'Timeout (seconds)', 5, 60, $environment->timeout);
Expand Down
9 changes: 5 additions & 4 deletions app/Concerns/RendersMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ protected function seriesListRows(string $label, array $series, Closure $format,
*/
protected function seriesLines(MetricSeries $series, Closure $format, array $stats = []): array
{
if (! $series->hasData()) {
$values = $series->values();
$sampled = array_values(array_filter($values, fn (?float $value) => $value !== null));

if ($sampled === []) {
return [['No data']];
}

Expand All @@ -74,13 +77,11 @@ protected function seriesLines(MetricSeries $series, Closure $format, array $sta
->map(fn (string $label, string $stat) => $format($series->{$stat}).' '.$label)
->values();

$values = $series->values();

return array_values(array_filter([
$summary->isEmpty() ? null : [$summary->first(), $summary->slice(1)->implode(' · ') ?: null],
[
Sparkline::make($values, $this->sparklineWidth()),
$format($values[0]).' → '.$format($values[count($values) - 1]),
$format($sampled[0]).' → '.$format($sampled[count($sampled) - 1]),
],
]));
}
Expand Down
6 changes: 6 additions & 0 deletions app/Dto/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function __construct(
public readonly ?int $hibernationWakeUpInterval = null,
public readonly ?int $timeout = null,
public readonly ?int $shutdownTimeout = null,
public readonly ?string $postDeployCommand = null,
public readonly bool $usesHttpBasicAuth = false,
public readonly ?EnvironmentInternalNetworking $internalNetworking = null,
) {
//
}
Expand Down Expand Up @@ -103,6 +106,9 @@ public static function createFromResponse(array $response): self
'hibernationWakeUpInterval' => $attributes['hibernation_wake_up_interval'] ?? null,
'timeout' => $attributes['timeout'] ?? null,
'shutdownTimeout' => $attributes['shutdown_timeout'] ?? null,
'postDeployCommand' => $attributes['post_deploy_command'] ?? null,
'usesHttpBasicAuth' => $attributes['uses_http_basic_auth'] ?? false,
'internalNetworking' => isset($attributes['internal_networking']) ? EnvironmentInternalNetworking::createFromResponse($attributes['internal_networking']) : null,
'resend' => isset($attributes['resend']) ? EnvironmentResend::createFromResponse($attributes['resend']) : null,
];

Expand Down
28 changes: 28 additions & 0 deletions app/Dto/EnvironmentInternalNetworking.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Dto;

use Spatie\LaravelData\Data;

class EnvironmentInternalNetworking extends Data
{
public function __construct(
public readonly bool $enabled,
public readonly ?string $hostname = null,
public readonly ?string $accessLevel = null,
/** @var list<string> */
public readonly array $environmentIds = [],
) {
//
}

public static function createFromResponse(array $internalNetworking): self
{
return new self(
enabled: (bool) ($internalNetworking['enabled'] ?? false),
hostname: $internalNetworking['hostname'] ?? null,
accessLevel: $internalNetworking['access_level'] ?? null,
environmentIds: $internalNetworking['environment_ids'] ?? [],
);
}
}
5 changes: 3 additions & 2 deletions app/Dto/MetricPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class MetricPoint extends Data
public function __construct(
#[WithCast(DateTimeInterfaceCast::class, type: CarbonImmutable::class)]
public readonly ?CarbonImmutable $at,
public readonly float $value,
/** Null when the instance reported no sample for the interval, which is not zero usage. */
public readonly ?float $value,
) {
//
}
Expand All @@ -27,7 +28,7 @@ public static function fromApiResponse(array $point, int $index = 0): self

return new self(
at: isset($point['x']) ? CarbonImmutable::parse($point['x']) : null,
value: (float) $value,
value: is_numeric($value) ? (float) $value : null,
);
}
}
2 changes: 1 addition & 1 deletion app/Dto/MetricSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function listFromApiResponse(mixed $series): array
}

/**
* @return list<float>
* @return list<float|null>
*/
public function values(): array
{
Expand Down
82 changes: 82 additions & 0 deletions tests/Feature/EnvironmentUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use App\Client\Resources\Meta\GetOrganizationRequest;
use App\ConfigRepository;
use Illuminate\Support\Facades\Artisan;
use Laravel\Prompts\Key;
use Laravel\Prompts\Prompt;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
use Saloon\Http\PendingRequest;
use Tests\Fixtures\InteractiveEnvironmentUpdateCommand;

beforeEach(function () {
$this->mockConfig = Mockery::mock(ConfigRepository::class);
Expand All @@ -27,6 +30,14 @@
'hibernation_wake_up_interval' => 60,
'timeout' => 30,
'shutdown_timeout' => 45,
'post_deploy_command' => 'php artisan cache:clear',
'uses_http_basic_auth' => true,
'internal_networking' => [
'enabled' => true,
'hostname' => 'production.internal',
'access_level' => 'specific',
'environment_ids' => ['env-2'],
],
'network_settings' => [
'response_headers' => [
'frame' => 'deny',
Expand Down Expand Up @@ -194,3 +205,74 @@ function updateEnvironment(array $options): void
'shutdownTimeout' => 45,
]);
});

it('sends the post-deploy command', function () {
updateEnvironment(['--post-deploy-command' => 'php artisan queue:restart']);

expect($this->sent->body)->toBe(['post_deploy_command' => 'php artisan queue:restart']);
});

it('turns HTTP basic auth on with a password', function () {
updateEnvironment(['--http-basic-auth-password' => 'hunter2']);

expect($this->sent->body)->toBe([
'uses_http_basic_auth' => true,
'http_basic_auth_password' => 'hunter2',
]);
});

it('turns HTTP basic auth off with an empty password', function () {
updateEnvironment(['--http-basic-auth-password' => '']);

expect($this->sent->body)->toBe(['uses_http_basic_auth' => false]);
});

it('asks for a password when HTTP basic auth is turned on interactively', function () {
Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand);

Prompt::fake([
...array_fill(0, 14, Key::DOWN), Key::SPACE, Key::ENTER,
Key::ENTER,
'h', 'u', 'n', 't', 'e', 'r', '2', Key::ENTER,
]);

$this->artisan('test:interactive-environment-update', ['environment' => 'env-1'])->assertSuccessful();

expect($this->sent->body)->toBe([
'uses_http_basic_auth' => true,
'http_basic_auth_password' => 'hunter2',
]);
});

it('turns HTTP basic auth off interactively without asking for a password', function () {
Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand);

Prompt::fake([
...array_fill(0, 14, Key::DOWN), Key::SPACE, Key::ENTER,
'n', Key::ENTER,
]);

$this->artisan('test:interactive-environment-update', ['environment' => 'env-1'])->assertSuccessful();

expect($this->sent->body)->toBe(['uses_http_basic_auth' => false]);
});

it('exposes the post-deploy command, HTTP basic auth and internal networking', function () {
Artisan::call('environment:get', [
'environment' => 'env-1',
'--json' => true,
'--fields' => 'postDeployCommand,usesHttpBasicAuth,internalNetworking',
'--no-interaction' => true,
]);

expect(json_decode(Artisan::output(), true))->toBe([
'postDeployCommand' => 'php artisan cache:clear',
'usesHttpBasicAuth' => true,
'internalNetworking' => [
'enabled' => true,
'hostname' => 'production.internal',
'accessLevel' => 'specific',
'environmentIds' => ['env-2'],
],
]);
});
32 changes: 32 additions & 0 deletions tests/Fixtures/InteractiveEnvironmentUpdateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Tests\Fixtures;

use App\Commands\EnvironmentUpdate;
use Laravel\Prompts\Prompt;
use Symfony\Component\Console\Input\InputInterface;

/**
* STDIN is not a TTY under the test runner, so this forces the interactive path of environment:update.
*/
class InteractiveEnvironmentUpdateCommand extends EnvironmentUpdate
{
public function __construct()
{
$this->signature = str_replace('environment:update', 'test:interactive-environment-update', $this->signature);

parent::__construct();
}

protected function isInteractive(): bool
{
return true;
}

protected function configurePrompts(InputInterface $input): void
{
parent::configurePrompts($input);

Prompt::interactive(true);
}
}
15 changes: 15 additions & 0 deletions tests/Unit/MetricSeriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@
expect(MetricSeries::listFromApiResponse(null))->toBe([]);
expect(MetricSeries::listFromApiResponse(['error' => true]))->toBe([]);
});

it('keeps an interval with no sample as null rather than zero', function () {
$series = MetricSeries::listFromApiResponse([
'labels' => ['App', 'Worker'],
'average' => [0.5, null],
'data' => [
['x' => '2026-08-14T12:00:00.000000Z', 'y' => [0.5, null]],
['x' => '2026-08-14T12:05:00.000000Z', 'y' => [null, null]],
],
]);

expect($series[0]->values())->toBe([0.5, null]);
expect($series[1]->values())->toBe([null, null]);
expect($series[1]->average)->toBeNull();
});
Loading