Last active
August 29, 2015 13:57
-
-
Save castlese/9780118 to your computer and use it in GitHub Desktop.
Display current github branch name in your rails app when working with Capistrano
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
<!-- app/views/layout/application.html.erb --> | |
<% if !Rails.env.production? %> | |
<%= branch_info %> | |
<% end %> |
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
# app/helpers/application_helper.rb | |
module ApplicationHelper | |
def branch_info | |
if Rails.env.staging? | |
#this will be changed after code is deployed to staging server | |
branch_name = 'BranchName' | |
else | |
#this works in local | |
branch_name = `git rev-parse --abbrev-ref HEAD` | |
end | |
content_tag :span, branch_name, :class => "label label-warning" | |
end | |
end |
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.rb | |
#set the branch name variable | |
set :branch_name, `git rev-parse --abbrev-ref HEAD` | |
#after the new version of app code has been uploaded to the server, edit the view file to update "BranchName" with the current branch variable as set above | |
#server restart is required due to caching | |
after "deploy:update_code" do | |
run "cd #{current_release}; sed -i 's/BranchName/#{branch_name}/g' app/helpers/application_helper.rb" | |
run "cd #{current_release}; touch tmp/restart.txt" | |
end |
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/staging.rb | |
#this file isn't necessary for the github labelling but it's useful all the same | |
#set capistrano to deploy from your current branch | |
set :branch_name, `git rev-parse --abbrev-ref HEAD` | |
set :branch, "#{branch_name}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment