Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pbharadiya/daa8f98d59055e4650308e57e93bf5ab to your computer and use it in GitHub Desktop.
Save pbharadiya/daa8f98d59055e4650308e57e93bf5ab to your computer and use it in GitHub Desktop.
Capistrano - deployment email with list of git commits
namespace :release do
desc "get current commit in remote server"
task :before do
begin
remote_sha = capture("cd #{current_path}; git rev-parse --verify HEAD")
set :remote_before_commit, remote_sha.strip
# first time deploy can throw exception
rescue
end
end
task :set_release_notes do
after_deploy_sha = capture("cd #{current_path}; git rev-parse --verify HEAD")
if defined?(remote_before_commit) and !remote_before_commit.blank?
git_commits_range = "#{remote_before_commit.strip}..#{after_deploy_sha.strip}"
#supports first release(prints many commits till last one)
else
git_commits_range = after_deploy_sha.strip
end
git_log = `git log #{git_commits_range}` # executes in local shell
set :release_notes, git_log
set :deployed_commit, after_deploy_sha.strip
end
end
before "deploy", "release:before"
# Notify via mail on the deployed commits
after "deploy:update", "release:set_release_notes", "deploy:notify"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment