Skip to content
Draft
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
2 changes: 1 addition & 1 deletion config/nightwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [
'enabled' => env('NIGHTWATCH_ENABLED', true),
'token' => env('NIGHTWATCH_TOKEN'),
'deployment' => env('NIGHTWATCH_DEPLOY'),
'deployment' => env('NIGHTWATCH_DEPLOY', rescue(static fn () => trim((string) shell_exec('git describe --tags --always 2>/dev/null')), '', false)),
Copy link
Member

@timacdonald timacdonald Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should look at environment variables in the first instance and only fallback to exec if there is nothing else.

  • Forge: FORGE_DEPLOY_COMMIT
  • Vapor?
  • Cloud?
  • Any other common environment variable used 3rd-party platforms? We've usually opted not to support these, but I wonder if we should. GITHUB_SHA, for example.

If you don't have config cached, we will run this on every request. Do we care about that? I'm sure there are plenty of apps out there that don't cache config, routes, etc.

'server' => env('NIGHTWATCH_SERVER', (string) gethostname()),
'capture_exception_source_code' => env('NIGHTWATCH_CAPTURE_EXCEPTION_SOURCE_CODE', true),
'redact_headers' => explode(',', env('NIGHTWATCH_REDACT_HEADERS', 'Authorization,Cookie,Proxy-Authorization,X-XSRF-TOKEN')),
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Laravel\Nightwatch\ExecutionStage;
use Laravel\Nightwatch\Facades\Nightwatch;
use Orchestra\Testbench\Attributes\WithEnv;
Expand All @@ -15,6 +16,7 @@

use function dirname;
use function hash;
use function trim;

class CoreTest extends TestCase
{
Expand Down Expand Up @@ -89,4 +91,18 @@ public function test_it_ingests_fatal_errors_immediately(): void
],
]);
}

#[WithEnv('NIGHTWATCH_FORCE_REQUEST', '1')]
public function test_it_uses_git_refs_for_deployments_by_default(): void
{
$ingest = $this->fakeIngest();
Route::get('/test', function () {
return 'OK';
});

$this->get('/test')->assertOk();

$ingest->assertWrittenTimes(1);
$ingest->assertLatestWrite('request:0.deploy', trim(`git describe --tags --always`));
}
}