ibanez270dx
3/1/2018 - 7:52 PM

Capistrano Deploy Confirmation

Capistrano Deploy Confirmation

# /lib/capistrano/tasks/confirmation.cap

namespace :deploy do
  task :confirmation do
    color = case fetch(:stage)
    when :production then 31
    when :staging then 33
    else 34
    end

    puts <<~WARN

      \e[1mYou are about to deploy branch \e[#{color}m#{fetch(:branch)}\e[0m\e[1m to \e[#{color}m#{fetch(:stage)}\e[0m

      \e[31mAre you sure you want to continue?\e[0m
    WARN

    ask :value, "Y/n"
    unless %w(Y y).include?(fetch(:value))
      puts "\nDeploy cancelled!"
      exit
    end

    if fetch(:stage) == :production
      puts <<~WARN
        \e[1m\e[41mAre you \e[3mREALLY\e[23m sure you want to continue?\e[22m\e[0m
      WARN

      ask :value, "Y/n"
      unless %w(Y y).include?(fetch(:value))
        puts "\nDeploy cancelled!"
        exit
      end
    end
  end
end

Capistrano::DSL.stages.each do |stage|
  after stage, 'deploy:confirmation'
end