Created
June 3, 2014 01:41
-
-
Save chsh/320e2afff7417ddd5f99 to your computer and use it in GitHub Desktop.
Capistrano deployment notification using Hall.
This file contains hidden or 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
| require 'hall' | |
| namespace :hall_notify do | |
| task :environment do | |
| set :capistrano_thumb_url, | |
| 'https://raw.github.com/smashingboxes/capistrano-haller/master/resources/capistrano-logo.png' | |
| end | |
| def send_hall_notification(action) | |
| hall_room_key = fetch(:hall_room_key) | |
| if hall_room_key.empty? | |
| logger.important("You must set hall_room_key for hall notifications to work!") | |
| else | |
| begin | |
| hall = Hall::Client.new(hall_room_key, 'Capistrano', fetch(:capistrano_thumb_url)) | |
| message = message_by_action action | |
| hall.post_message message | |
| rescue | |
| logger.important("Could not contact hall API for deployment notification.") | |
| end | |
| end | |
| end | |
| def message_by_action(action) | |
| case action | |
| when :deploy_starting | |
| "Branch <strong>#{fetch(:branch)}</strong> is starting to deploy to <strong>#{fetch(:stage)}</strong> as #{fetch(:rails_env)}." | |
| when :deploy_finishing | |
| "Branch <strong>#{fetch(:branch)}</strong> was successfully deployed to <strong>#{fetch(:stage)}</strong> as #{fetch(:rails_env)}." | |
| when :deploy_finishing_rollback | |
| "Branch <strong>#{fetch(:branch)}</strong> was NOT deployed to <strong>#{fetch(:stage)}</strong> as #{fetch(:rails_env)}." | |
| end | |
| end | |
| desc "Notify a hall channel of deployment starting" | |
| task deploy_starting: :environment do | |
| on roles(:app) do | |
| send_hall_notification :deploy_starting | |
| end | |
| end | |
| desc "Notify a hall channel of deployment finishing" | |
| task deploy_finishing: :environment do | |
| on roles(:app) do | |
| send_hall_notification :deploy_finishing | |
| end | |
| end | |
| desc "Notify a hall channel of deployment rollback" | |
| task deploy_finishing_rollback: :environment do | |
| on roles(:app) do | |
| send_hall_notification :deploy_finishing_rollback | |
| end | |
| end | |
| desc 'Notify test' | |
| task test: :environment do | |
| on roles(:app) do | |
| send_hall_notification :deploy_starting | |
| send_hall_notification :deploy_finishing | |
| send_hall_notification :deploy_finishing_rollback | |
| end | |
| end | |
| end | |
| namespace :deploy do | |
| before :starting, 'hall_notify:deploy_starting' | |
| after :finishing, 'hall_notify:deploy_finishing' | |
| after :finishing_rollback, 'hall_notify:deploy_finishing_rollback' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment