-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(deployment): respect pinned commit SHA for deployments #9292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,15 @@ function queue_application_deployment(Application $application, string $deployme | |||||||||||||||||||||||
| $destination_id = $destination->id; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Use the application's pinned commit SHA when no specific commit was requested | ||||||||||||||||||||||||
| // and this is not a PR or rollback deployment | ||||||||||||||||||||||||
| if ($pull_request_id === 0 && ! $rollback) { | ||||||||||||||||||||||||
| $pinnedCommit = str($application->git_commit_sha ?? '')->trim()->value(); | ||||||||||||||||||||||||
| if ($pinnedCommit !== '' && $pinnedCommit !== 'HEAD') { | ||||||||||||||||||||||||
| $commit = $pinnedCommit; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+34
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pinned SHA override is terminating explicit commit inputs (wrong revision risk). At Line 34, pinned SHA is applied unconditionally for non-PR/non-rollback flows, even when a real commit was explicitly passed (webhook/API/manual). That makes deployments ignore the requested commit and can queue the wrong target commit. 💡 Suggested fix- if ($pull_request_id === 0 && ! $rollback) {
+ if ($pull_request_id === 0 && ! $rollback && ($commit === 'HEAD' || blank($commit))) {
$pinnedCommit = str($application->git_commit_sha ?? '')->trim()->value();
- if ($pinnedCommit !== '' && $pinnedCommit !== 'HEAD') {
+ if ($pinnedCommit !== '' && strcasecmp($pinnedCommit, 'HEAD') !== 0) {
$commit = $pinnedCommit;
}
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 PHPMD (2.15.0)[error] 34-34: The variable $pull_request_id is not named in camelCase. (undefined) (CamelCaseVariableName) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Check if the deployment queue is full for this server | ||||||||||||||||||||||||
| $serverForQueueCheck = $server ?? Server::find($server_id); | ||||||||||||||||||||||||
| $queue_limit = $serverForQueueCheck->settings->deployment_queue_limit ?? 25; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?php | ||
|
|
||
| use App\Models\Application; | ||
| use App\Models\ApplicationSetting; | ||
|
|
||
| describe('Pinned commit propagation', function () { | ||
| beforeEach(function () { | ||
| $this->application = new Application; | ||
| $this->application->forceFill([ | ||
| 'uuid' => 'test-app-uuid', | ||
| 'git_commit_sha' => 'HEAD', | ||
| ]); | ||
|
|
||
| $settings = new ApplicationSetting; | ||
| $settings->is_git_shallow_clone_enabled = false; | ||
| $settings->is_git_submodules_enabled = false; | ||
| $settings->is_git_lfs_enabled = false; | ||
| $this->application->setRelation('settings', $settings); | ||
| }); | ||
|
|
||
| test('setGitImportSettings uses pinned commit when no explicit commit is passed', function () { | ||
| $pinnedSha = str_repeat('a', 40); | ||
| $this->application->git_commit_sha = $pinnedSha; | ||
|
|
||
| $result = $this->application->setGitImportSettings( | ||
| deployment_uuid: 'test-uuid', | ||
| git_clone_command: 'git clone', | ||
| public: true, | ||
| ); | ||
|
|
||
| expect($result)->toContain($pinnedSha); | ||
| }); | ||
|
|
||
| test('setGitImportSettings prefers explicit commit over pinned commit', function () { | ||
| $pinnedSha = str_repeat('a', 40); | ||
| $explicitSha = str_repeat('b', 40); | ||
| $this->application->git_commit_sha = $pinnedSha; | ||
|
|
||
| $result = $this->application->setGitImportSettings( | ||
| deployment_uuid: 'test-uuid', | ||
| git_clone_command: 'git clone', | ||
| public: true, | ||
| commit: $explicitSha, | ||
| ); | ||
|
|
||
| expect($result) | ||
| ->toContain($explicitSha) | ||
| ->not->toContain($pinnedSha); | ||
| }); | ||
|
|
||
| test('setGitImportSettings does not checkout when git_commit_sha is HEAD', function () { | ||
| $this->application->git_commit_sha = 'HEAD'; | ||
|
|
||
| $result = $this->application->setGitImportSettings( | ||
| deployment_uuid: 'test-uuid', | ||
| git_clone_command: 'git clone', | ||
| public: true, | ||
| ); | ||
|
|
||
| expect($result)->not->toContain('advice.detachedHead=false checkout'); | ||
| }); | ||
|
Comment on lines
+21
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverage gap: changed queue/job commit precedence paths are not asserted. These tests validate I can draft two focused tests:
Based on learnings: "Every code change must be programmatically tested; write a new test or update an existing test, then run affected tests to ensure they pass." 🤖 Prompt for AI Agents |
||
|
|
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Job-level pinned commit logic also overrides explicit queued commits.
Line 2194 currently applies pinned SHA without checking whether
$this->commitwas intentionally set upstream. This can still deploy the wrong revision even after queue-time fixes. Skynet behavior detected. 😄💡 Suggested fix
🤖 Prompt for AI Agents