mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
Queueing a deployment now honors git_commit_sha when set (non‑PR, non‑rollback). The deployment job keeps the pinned SHA as the resolved commit and avoids overwriting it with branch head. A hidden log entry records the actual checked‑out HEAD for verification. Added tests to ensure pinned commits are persisted and unpinned commits still resolve normally.
117 lines
4.2 KiB
PHP
117 lines
4.2 KiB
PHP
<?php
|
|
|
|
use App\Jobs\ApplicationDeploymentJob;
|
|
use App\Models\Application;
|
|
use App\Models\ApplicationDeploymentQueue;
|
|
use App\Models\ApplicationSetting;
|
|
|
|
function setJobProperty(object $job, string $property, mixed $value): void
|
|
{
|
|
$reflection = new ReflectionClass($job);
|
|
$prop = $reflection->getProperty($property);
|
|
$prop->setAccessible(true);
|
|
$prop->setValue($job, $value);
|
|
}
|
|
|
|
function getJobProperty(object $job, string $property): mixed
|
|
{
|
|
$reflection = new ReflectionClass($job);
|
|
$prop = $reflection->getProperty($property);
|
|
$prop->setAccessible(true);
|
|
|
|
return $prop->getValue($job);
|
|
}
|
|
|
|
it('keeps pinned commit when resolving git commit sha', function () {
|
|
$pinnedCommit = str_repeat('a', 40);
|
|
$remoteCommit = str_repeat('b', 40);
|
|
$lsRemoteOutput = $remoteCommit."\trefs/heads/main";
|
|
|
|
$settings = new ApplicationSetting([
|
|
'include_source_commit_in_build' => false,
|
|
'use_build_secrets' => false,
|
|
'is_git_submodules_enabled' => false,
|
|
'is_git_lfs_enabled' => false,
|
|
'is_git_shallow_clone_enabled' => false,
|
|
]);
|
|
$application = Application::factory()->make([
|
|
'git_repository' => 'https://example.com/acme/repo.git',
|
|
'git_branch' => 'main',
|
|
'git_commit_sha' => $pinnedCommit,
|
|
'build_pack' => 'nixpacks',
|
|
'ports_exposes' => '3000',
|
|
]);
|
|
$application->setRelation('settings', $settings);
|
|
|
|
$queue = Mockery::mock(ApplicationDeploymentQueue::class)->makePartial();
|
|
$queue->commit = $pinnedCommit;
|
|
$queue->shouldReceive('save')->never();
|
|
|
|
$job = Mockery::mock(ApplicationDeploymentJob::class)->makePartial();
|
|
$job->shouldReceive('execute_remote_command')->andReturnNull();
|
|
|
|
setJobProperty($job, 'application', $application);
|
|
setJobProperty($job, 'application_deployment_queue', $queue);
|
|
setJobProperty($job, 'deployment_uuid', 'deployment-uuid');
|
|
setJobProperty($job, 'pull_request_id', 0);
|
|
setJobProperty($job, 'commit', 'HEAD');
|
|
setJobProperty($job, 'rollback', false);
|
|
setJobProperty($job, 'git_type', null);
|
|
setJobProperty($job, 'saved_outputs', collect([
|
|
'git_commit_sha' => str($lsRemoteOutput),
|
|
]));
|
|
setJobProperty($job, 'source', 'other');
|
|
|
|
$method = new ReflectionMethod(ApplicationDeploymentJob::class, 'check_git_if_build_needed');
|
|
$method->setAccessible(true);
|
|
$method->invoke($job);
|
|
|
|
expect(getJobProperty($job, 'commit'))->toBe($pinnedCommit);
|
|
});
|
|
|
|
it('updates commit from ls-remote when no pinned commit is set', function () {
|
|
$remoteCommit = str_repeat('c', 40);
|
|
$lsRemoteOutput = $remoteCommit."\trefs/heads/main";
|
|
|
|
$settings = new ApplicationSetting([
|
|
'include_source_commit_in_build' => false,
|
|
'use_build_secrets' => false,
|
|
'is_git_submodules_enabled' => false,
|
|
'is_git_lfs_enabled' => false,
|
|
'is_git_shallow_clone_enabled' => false,
|
|
]);
|
|
$application = Application::factory()->make([
|
|
'git_repository' => 'https://example.com/acme/repo.git',
|
|
'git_branch' => 'main',
|
|
'git_commit_sha' => 'HEAD',
|
|
'build_pack' => 'nixpacks',
|
|
'ports_exposes' => '3000',
|
|
]);
|
|
$application->setRelation('settings', $settings);
|
|
|
|
$queue = Mockery::mock(ApplicationDeploymentQueue::class)->makePartial();
|
|
$queue->commit = 'HEAD';
|
|
$queue->shouldReceive('save')->once();
|
|
|
|
$job = Mockery::mock(ApplicationDeploymentJob::class)->makePartial();
|
|
$job->shouldReceive('execute_remote_command')->andReturnNull();
|
|
|
|
setJobProperty($job, 'application', $application);
|
|
setJobProperty($job, 'application_deployment_queue', $queue);
|
|
setJobProperty($job, 'deployment_uuid', 'deployment-uuid');
|
|
setJobProperty($job, 'pull_request_id', 0);
|
|
setJobProperty($job, 'commit', 'HEAD');
|
|
setJobProperty($job, 'rollback', false);
|
|
setJobProperty($job, 'git_type', null);
|
|
setJobProperty($job, 'saved_outputs', collect([
|
|
'git_commit_sha' => str($lsRemoteOutput),
|
|
]));
|
|
setJobProperty($job, 'source', 'other');
|
|
|
|
$method = new ReflectionMethod(ApplicationDeploymentJob::class, 'check_git_if_build_needed');
|
|
$method->setAccessible(true);
|
|
$method->invoke($job);
|
|
|
|
expect(getJobProperty($job, 'commit'))->toBe($remoteCommit);
|
|
expect($queue->commit)->toBe($remoteCommit);
|
|
});
|