-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a GitHub deployment for the batch head
- Loading branch information
1 parent
826e578
commit 99a698d
Showing
11 changed files
with
85 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Shipit | ||
class CreateDeploymentsForTaskJob < BackgroundJob | ||
include BackgroundJob::Unique | ||
|
||
queue_as :default | ||
|
||
def perform(task) | ||
# Create one deployment for the head of the batch | ||
task.commit_deployments.create!(sha: task.until_commit.sha) | ||
|
||
# Create one for each pull request in the batch, to give feedback on the PR timeline | ||
task.commits.select(&:pull_request?).each do |commit| | ||
task.commit_deployments.create!(sha: pull_request_head_for_commit(commit)) | ||
end | ||
|
||
# Immediately update to publish the status to the commit deployments | ||
task.update_commit_deployments | ||
end | ||
|
||
private | ||
|
||
def pull_request_head_for_commit(commit) | ||
pull_request = Shipit.github.api.pull_request(commit.stack.github_repo_name, commit.pull_request_number) | ||
pull_request.head.sha | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddShaToCommitDeployments < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column :commit_deployments, :sha, :string, limit: 40 | ||
add_index :commit_deployments, :sha | ||
add_index :commit_deployments, [:task_id, :sha], unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
shipit_deploy_second: | ||
commit_id: 2 # second | ||
sha: f890fd8b5f2be05d1fedb763a3605ee461c39074 # second | ||
task_id: 1 # shipit | ||
api_url: https://api.github.com/repos/shopify/shipit-engine/deployments/1 | ||
github_id: 1 | ||
|
||
shipit2_deploy_third: | ||
commit_id: 3 # third | ||
sha: 367578b362bf2b4df5903e1c7960929361c39074 # third | ||
task_id: 2 # shipit2 | ||
api_url: https://api.github.com/repos/shopify/shipit-engine/deployments/2 | ||
github_id: 2 | ||
|
||
shipit_pending_third: | ||
commit_id: 3 # third | ||
sha: 367578b362bf2b4df5903e1c7960929361c39074 # third | ||
task_id: 4 # shipit_pending | ||
api_url: https://api.github.com/repos/shopify/shipit-engine/deployments/3 | ||
github_id: 3 | ||
|
||
shipit_pending_fourth: | ||
commit_id: 4 # fourth | ||
sha: 467578b362bf2b4df5903e1c7960929361c3435a # fourth | ||
task_id: 4 # shipit_pending | ||
|
||
shipit_running_fourth: | ||
commit_id: 4 # fourth | ||
sha: 467578b362bf2b4df5903e1c7960929361c3435a # fourth | ||
task_id: 5 # shipit_running | ||
|
||
shipit_complete_fourth: | ||
commit_id: 4 # fourth | ||
sha: 467578b362bf2b4df5903e1c7960929361c3435a # fourth | ||
task_id: 6 # shipit_complete | ||
|
||
shipit_aborted_fourth: | ||
commit_id: 4 # fourth | ||
sha: 467578b362bf2b4df5903e1c7960929361c3435a # fourth | ||
task_id: 7 # shipit_aborted | ||
|
||
shipit_rollback_fourth: | ||
commit_id: 4 # fourth | ||
sha: 467578b362bf2b4df5903e1c7960929361c3435a # fourth | ||
task_id: 8 # shipit_rollback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'test_helper' | ||
|
||
module Shipit | ||
class CreateDeploymentsForTaskJobTest < ActiveSupport::TestCase | ||
setup do | ||
@task = shipit_tasks(:shipit_pending) | ||
@task.commit_deployments.delete_all | ||
end | ||
|
||
test "creates one CommitDeployment and status per commit, and one more for the batch head" do | ||
pull_request_response = stub(head: stub(sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e')) | ||
Shipit.github.api.expects(:pull_request).with('shopify/shipit-engine', 7).returns(pull_request_response) | ||
|
||
expected_delta = @task.commits.select(&:pull_request?).size + 1 | ||
assert_difference -> { CommitDeployment.count }, expected_delta do | ||
assert_difference -> { CommitDeploymentStatus.count }, expected_delta do | ||
CreateDeploymentsForTaskJob.perform_now(@task) | ||
end | ||
end | ||
|
||
refute_nil CommitDeployment.find_by(sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e') | ||
refute_nil CommitDeployment.find_by(sha: @task.until_commit.sha) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters