Skip to content
Merged
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
9 changes: 7 additions & 2 deletions app/models/shipit/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def trigger_rollback(user = AnonymousUser.new, env: nil, force: false, lock: tru
end

# Rolls the stack back to the most recent **previous** successful deploy
def trigger_revert(force: false, rollback_to: nil)
def trigger_revert(force: false, rollback_to: nil, env: nil)
previous_successful_commit = rollback_to&.until_commit || commit_to_rollback_to

rollback = Rollback.create!(
Expand All @@ -126,6 +126,7 @@ def trigger_revert(force: false, rollback_to: nil)
parent_id: id,
since_commit: until_commit,
until_commit: previous_successful_commit,
env: env || self.env,
allow_concurrency: force
)

Expand Down Expand Up @@ -301,7 +302,11 @@ def trigger_revert_if_required
return unless rollback_once_aborted?
return unless supports_rollback?

trigger_revert(rollback_to: rollback_once_aborted_to)
if rollback_once_aborted_to
rollback_once_aborted_to.trigger_rollback(aborted_by, env:, force: true)
else
trigger_revert(force: true, env:)
end
end

def default_since_commit_id
Expand Down
8 changes: 8 additions & 0 deletions test/models/deploys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,27 +437,35 @@ def setup
@deploy = shipit_deploys(:shipit_running)
@deploy.ping
@deploy.pid = 42
@deploy.env = { 'CUSTOM_VAR' => 'value' }
@deploy.abort!(rollback_once_aborted: true, aborted_by: @user)

assert_difference -> { @stack.rollbacks.count }, 1 do
assert_enqueued_with(job: PerformTaskJob) do
@deploy.aborted!
end
end

rollback = @stack.rollbacks.last
assert_equal({ 'CUSTOM_VAR' => 'value' }, rollback.env)
end

test "transitioning to aborted schedule a rollback to the designated deploy if set" do
@rollback_to = shipit_deploys(:shipit_pending)
@deploy = shipit_deploys(:shipit_running)
@deploy.ping
@deploy.pid = 42
@deploy.env = { 'CUSTOM_VAR' => 'value' }
@deploy.abort!(rollback_once_aborted: true, rollback_once_aborted_to: @rollback_to, aborted_by: @user)

assert_difference -> { @stack.rollbacks.count }, 1 do
assert_enqueued_with(job: PerformTaskJob) do
@deploy.aborted!
end
end

rollback = @stack.rollbacks.last
assert_equal({ 'CUSTOM_VAR' => 'value' }, rollback.env)
end

test "transitioning to aborted locks the stack if a rollback is scheduled" do
Expand Down
4 changes: 2 additions & 2 deletions test/models/shipit/deploy_spec/file_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(true).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit_1.yml').at_least_once
deploy_spec.expects(:config_file_path).returns(Pathname.new("#{Dir.tmpdir}/shipit_1.yml")).at_least_once
deploy_spec.expects(:read_config).returns(SafeYAML.load(deploy_spec_inherit_from_yaml), SafeYAML.load(deploy_spec_yaml)).at_least_once
Pathname.any_instance.stubs(:exist?).returns(true)
loaded_config = deploy_spec.send(:load_config)
Expand All @@ -83,7 +83,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(true).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit_1.yml').at_least_once
deploy_spec.expects(:config_file_path).returns(Pathname.new("#{Dir.tmpdir}/shipit_1.yml")).at_least_once
deploy_spec.expects(:read_config).returns(SafeYAML.load(deploy_spec_inherit_from_yaml)).at_least_once
Pathname.any_instance.stubs(:exist?).returns(false)
loaded_config = deploy_spec.send(:load_config)
Expand Down