Skip to content

Commit

Permalink
Display the deployed version in the application footer (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
bess authored Sep 27, 2021
1 parent 844cead commit 3689b32
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ td.nowrap {
td.no-edit, span.no-edit {
background-color: rgba(230,191,153,0.5);
}

.deployment-version {
color: gray;
float: right;
}
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
<%= render partial: "shared/flash_messages", flash: flash %>
<%= yield %>
</div>
<div class="deployment-version">
Version <span title="<%= GIT_SHA %>"><%= BRANCH %> last updated <%= LAST_DEPLOYED %>.</span>
</div>
</body>
</html>
29 changes: 29 additions & 0 deletions config/initializers/git_sha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

revisions_logfile = Rails.root.join("..", "..", "revisions.log")

GIT_SHA =
if File.exist?(revisions_logfile)
`tail -1 #{revisions_logfile}`.chomp.split(" ")[3].gsub(/\)$/, "")
elsif Rails.env.development? || Rails.env.test?
`git rev-parse HEAD`.chomp
else
"Unknown SHA"
end

BRANCH =
if File.exist?(revisions_logfile)
`tail -1 #{revisions_logfile}`.chomp.split(" ")[1]
elsif Rails.env.development? || Rails.env.test?
`git rev-parse --abbrev-ref HEAD`.chomp
else
"Unknown branch"
end

LAST_DEPLOYED =
if File.exist?(revisions_logfile)
deployed = `tail -1 #{revisions_logfile}`.chomp.split(" ")[7]
Date.parse(deployed).strftime("%d %B %Y")
else
"Not in deployed environment"
end

0 comments on commit 3689b32

Please sign in to comment.