Created
January 8, 2014 11:02
-
-
Save nosolopau/8315119 to your computer and use it in GitHub Desktop.
Send email notifications after deploy (with Capistrano and Rails 4). Capistrano variables reference: http://theadmin.org/articles/capistrano-variables/
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
# Add the following lines at the end of config/deploy.rb | |
Dir["config/deploy/extras/*.rb"].each { |file| load file } | |
set :notify_emails, ["[email protected]"] | |
after "deploy", "deploy:notify" |
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
# config/deploy/extras/notifier.rb | |
require 'action_mailer' | |
ActionMailer::Base.delivery_method = :sendmail # You can also use :smtp... | |
ActionMailer::Base.raise_delivery_errors = true | |
class Notifier < ActionMailer::Base | |
default from: '"notifier" <[email protected]>' | |
def deploy_notification(cap_vars) | |
application_name = cap_vars.application.split('_')[0] | |
mail(:to => cap_vars.notify_emails, :subject => "Application #{application_name} has been deployed in #{cap_vars.stage}") do |format| | |
format.text do | |
render :text => "Hi,\n\nThe application #{application_name} has been deployed in the #{cap_vars.stage} platform.\n\n#{cap_vars.release_notes}" | |
end | |
end | |
end | |
end | |
namespace :deploy do | |
desc "Email notifier" | |
task :notify, :roles => :app, :except => { :no_release => true } do | |
git_commits_range = "#{previous_revision.strip}..#{current_revision.strip}" | |
git_log = `git log --pretty=oneline --abbrev-commit #{git_commits_range}` | |
set :release_notes, git_log.blank? ? "No changes since last deploy." : "Last changes:\n" + git_log | |
Notifier.deploy_notification(self).deliver | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment