Add endpoint for triggering site deployment (#563)

* feat(api): Add endpoint for triggering site deployment

- Add POST /api/projects/{project}/servers/{server}/sites/{site}/deploy endpoint
- Add feature tests

* fix merge issue and generate api docs

* fix merge

---------

Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
Dimitar Yanakiev
2025-04-05 20:41:52 +03:00
committed by GitHub
parent f483f7fdca
commit 2a670146d8
33 changed files with 1941 additions and 1450 deletions

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\API;
use App\Enums\DeploymentStatus;
use App\Enums\LoadBalancerMethod;
use App\Enums\SourceControl;
use App\Facades\SSH;
@ -190,6 +191,54 @@ public function test_update_load_balancer(): void
]);
}
public function test_deploy_site(): void
{
SSH::fake();
Http::fake([
'https://api.github.com/repos/*' => Http::response([
'commit' => [
'sha' => 'abc123',
'commit' => [
'message' => 'Test commit',
'author' => [
'name' => 'Test Author',
'email' => 'test@example.com',
'date' => now()->toIso8601String(),
],
],
],
], 200),
]);
Sanctum::actingAs($this->user, ['read', 'write']);
/** @var Site $site */
$site = Site::factory()->create([
'server_id' => $this->server->id,
]);
$script = $site->deploymentScript;
$script->content = 'git pull';
$script->save();
$this->json('POST', route('api.projects.servers.sites.deploy', [
'project' => $this->server->project,
'server' => $this->server,
'site' => $site,
]))
->assertSuccessful()
->assertJsonStructure([
'id',
'status',
]);
$this->assertDatabaseHas('deployments', [
'site_id' => $site->id,
'status' => DeploymentStatus::FINISHED,
]);
}
public function test_update_deployment_script(): void
{
SSH::fake();