# App to Pick up application release from Git/Capistrano?

**URL:** <https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407>\
**Category:** Rails\
**Created:** [April 22, 2010, 6:12pm UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407 "2010-04-22T18:12:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [April 22, 2010, 6:12pm UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407/1 "2010-04-22T18:12:44Z")

</div>

My application is going into user testing and I would like to see  
which “release” the user has been testing against by the release  
appearing somewhere on the view. I can then check it on screen prints  
etc.

I am using Git and Capistrano in a multi-stage environment.

I expect I could access the capistrano release name from the  
filesystem directory somehow. Any clever way of doing this in the  
application controller?

Even better would be to somehow get Capistrano to capture the SHA  
(e.g. 1837213156f56b850e9045622d5c2f4a1607ef53) that it is checking  
out and placing that somewhere where I can read. That way I can track  
any errors based on the Git release. Perhaps just displaying the  
first 4 digits would be enough. Has anyone done this somehow?

Any other ideas?

O.

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [April 22, 2010, 7:09pm UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407/2 "2010-04-22T19:09:32Z")

</div>

On 22 Apr 2010, at 18:00, Owain wrote:

> Even better would be to somehow get Capistrano to capture the SHA  
> (e.g. 1837213156f56b850e9045622d5c2f4a1607ef53) that it is checking  
> out and placing that somewhere where I can read. That way I can track  
> any errors based on the Git release. Perhaps just displaying the  
> first 4 digits would be enough. Has anyone done this somehow?

> > p = `cd #{RAILS_ROOT} && git rev-parse HEAD`.strip  
> > =\> “031154343573f846dc4f9d31806e58438bfe783e”
> 
> > q = `cd #{RAILS_ROOT} && git show-ref`.strip  
> > =\> “031154343573f846dc4f9d31806e58438bfe783e refs/heads/master”

Would be best if you store the result in a constant at startup, so the  
IO operation isn’t called on every page.

Hope this helps.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [April 22, 2010, 8:07pm UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407/3 "2010-04-22T20:07:29Z")

</div>

On Apr 22, 2010, at 1:02 PM, Peter De Berdt wrote:

> > filesystem directory somehow. Any clever way of doing this in the  
> > =\> “031154343573f846dc4f9d31806e58438bfe783e”  
> > Peter De Berdt  
> > You can always use the contents of the REVISION file that cap puts in  
> > your Rails.root directory

File.read(File.expand\_path(‘REVISION’, RAILS\_ROOT))

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid  
+1 513-295-4739  
Skype: rob.biedenharn

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [April 23, 2010, 12:40am UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407/4 "2010-04-23T00:40:20Z")

</div>

On 22 Apr 2010, at 20:02, Rob B. wrote:

> > Best regards
> > 
> > Peter De Berdt
> 
> You can always use the contents of the REVISION file that cap puts  
> in your Rails.root directory
> 
> File.read(File.expand\_path(‘REVISION’, RAILS\_ROOT))

Ah indeed, totally forgot about that one.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [April 23, 2010, 9:03am UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407/5 "2010-04-23T09:03:45Z")

</div>

Thanks Peter and Rob.

I think it would still make sense to do this during initialization  
rather than at the application controller since it is during  
initialization is then it will change. I will also add some logic to  
the view just to check REVISION is there, perhaps in future the app  
might not be deployed using Cap. Sounds like a little helper.

O.

---

<div class="post-metadata">

**Author:** ![Owain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@Owain](https://www.ruby-forum.com/u/Owain)\
**Post date:** [April 26, 2010, 11:34am UTC](https://www.ruby-forum.com/t/app-to-pick-up-application-release-from-git-capistrano/187407/6 "2010-04-26T11:34:14Z")

</div>

so here it is my solution;

/app/config/initializers/revision.rb  
filename = File.expand\_path(‘REVISION’, RAILS\_ROOT)  
REVISION = File.exist?(filename) ? File.read(filename) : `cd #{RAILS_ROOT} && git rev-parse HEAD`.strip

/app/views/layout/application.html.erb  
\<%- unless production? %\>

\<%= "#{REVISION[0..3]} #{Time.now.to\_s(:db)} "%\> \<%- end -%\>

/app/helpers/application\_helper.rb  
def production?  
@is\_production ||=(ENV[‘RAILS\_ENV’]==‘production’)  
end

/public/stylesheets/content.css  
#revision {  
color: gray;  
position: absolute;  
z-index: 9;  
top: 10px;  
left: 0px;  
}
