Skip to content

Commit bbcc0d6

Browse files
authored
Merge pull request #3606 from nhsuk/add-version-number-footer
Display current version of Mavis in the footer. The version is extracted from the current git ref or branch name used for deployment.
2 parents 764c20c + 7dbadda commit bbcc0d6

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

.github/workflows/build-and-push-image.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
git-sha:
88
description: The git commit sha to build the image from.
99
type: string
10+
git_ref_to_deploy:
11+
required: false
12+
type: string
1013

1114
concurrency:
1215
group: build-and-push-image-${{ inputs.git-sha || github.sha }}
@@ -65,8 +68,10 @@ jobs:
6568
uses: actions/checkout@v4
6669
with:
6770
ref: ${{ inputs.git-sha || github.sha }}
68-
- name: Write build SHA
69-
run: git rev-parse HEAD > public/sha
71+
- name: Write build metadata
72+
run: |
73+
git rev-parse HEAD > public/sha
74+
echo "${{ inputs.git_ref_to_deploy || github.ref_name }}" > public/ref
7075
- name: Build Docker image
7176
run: docker build -t "mavis:latest" .
7277
- name: Save Docker image

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ scratchpad
5858
# Artillery temporarily bundles TypeScript files in this directory
5959
tests/dist
6060

61-
# This file is autogenerated by the deploy GitHub Action
61+
# These files are autogenerated by the deploy GitHub Action
6262
public/sha
63+
public/ref

app/helpers/application_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ def page_title(service_name)
3232

3333
safe_join([title, service_name], " – ")
3434
end
35+
36+
def app_version
37+
return APP_VERSION if defined?(APP_VERSION) && APP_VERSION.present?
38+
39+
if Rails.env.local?
40+
version = `git rev-parse --abbrev-ref HEAD 2>/dev/null`.strip
41+
return nil if version.blank? || version == "HEAD"
42+
return version
43+
end
44+
45+
nil
46+
end
3547
end

app/views/layouts/application.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
<%= link_to "#{t("service.guide.title")} (opens in a new tab)", @service_guide_url, classes: "nhsuk-footer__list-item-link", target: "_blank" %>
6161
</li>
6262
<% end %>
63+
<% if app_version %>
64+
<li class="nhsuk-footer__list-item nhsuk-footer-default__list-item nhsuk-u-secondary-text-color">
65+
<%= app_version %>
66+
</li>
67+
<% end %>
6368
</ul>
6469
<p class="nhsuk-footer__copyright">&copy; NHS England</p>
6570
</div>

config/initializers/version.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
path = Rails.root.join("public/ref")
4+
5+
version = File.read(path).strip if File.exist?(path)
6+
APP_VERSION = version.presence

0 commit comments

Comments
 (0)