Skip to content

Commit a2bfe78

Browse files
committed
Display app version in the footer using the git tag
- Added a new Terraform variable `version` and passed it to the Rails app via task_envs to support version number display in deployments. - Updated the GitHub Actions `deploy-infrastructure.yml` workflow to dynamically extract the latest Git tag before running `terraform plan`. If no tag is found, the version defaults to "unknown" with a warning. - Modified the `bin/setup` script to detect the latest Git tag locally and set `APP_VERSION` dynamically for development. - Updated controller logic to only display version if it matches the `vX.Y.Z.x` format. - Added logic to conditionally render the version in the footer only when valid.
1 parent 9cd6f8c commit a2bfe78

6 files changed

Lines changed: 42 additions & 1 deletion

File tree

.github/workflows/deploy-infrastructure.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ jobs:
8787
run: sudo snap install --classic aws-cli
8888
- name: Check if any deployments are running
8989
run: ../scripts/check-for-running-deployments.sh ${{ inputs.environment }}
90+
- name: Set Mavis app version
91+
run: |
92+
APP_VERSION=$(git describe --tags --abbrev=0 2>/dev/null)
93+
if [ -z "$APP_VERSION" ]; then
94+
echo "Warning: No git tags found — defaulting to 'unknown'."
95+
APP_VERSION="unknown"
96+
fi
97+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
9098
- name: Terraform Plan
9199
id: plan
92100
run: |
93101
set -e
94102
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
95-
terraform plan -var="image_digest=$DIGEST" -var-file="env/${{ inputs.environment }}.tfvars" \
103+
terraform plan -var="image_digest=$DIGEST" -var="app_version=$APP_VERSION" -var-file="env/${{ inputs.environment }}.tfvars" \
96104
-out ${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
97105
- name: Validate the changes
98106
run: |

app/controllers/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base
1515
before_action :set_show_navigation
1616
before_action :set_privacy_policy_url
1717
before_action :authenticate_basic
18+
before_action :set_app_version
1819

1920
after_action :verify_policy_scoped, if: -> { Rails.env.local? }
2021

@@ -32,6 +33,10 @@ class UnprocessableEntity < StandardError
3233
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
3334

3435
private
36+
37+
def set_app_version
38+
@app_version = APP_VERSION.match?(/\Av\d+\.\d+\.\d+\z/) ? APP_VERSION : nil
39+
end
3540

3641
def set_selected_organisation
3742
return if Settings.cis2.enabled

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>

bin/setup

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ FileUtils.chdir APP_ROOT do
2828
puts "\n== Removing old logs and tempfiles =="
2929
system! "bin/rails log:clear tmp:clear"
3030

31+
puts "\n== Detecting app version from git tag =="
32+
33+
git_tag = `git describe --tags --abbrev=0 2>/dev/null`.strip
34+
if git_tag.match?(/^v\d+\.\d+\.\d+$/)
35+
ENV["APP_VERSION"] = git_tag
36+
puts "Detected APP_VERSION: #{git_tag}"
37+
else
38+
ENV["APP_VERSION"] = nil
39+
puts "No valid tag found. APP_VERSION set to nil."
40+
end
41+
3142
unless ARGV.include?("--skip-server")
3243
puts "\n== Starting development server =="
3344
STDOUT.flush # flush the output before exec(2) so that it displays

config/initializers/version.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_VERSION = ENV.fetch('APP_VERSION', 'unknown')

terraform/app/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ variable "enable_splunk" {
157157
nullable = false
158158
}
159159

160+
variable "app_version" {
161+
type = string
162+
default = "unknown"
163+
description = "The version of Mavis being deployed."
164+
}
165+
160166
locals {
161167
is_production = var.environment == "production"
162168
parameter_store_variables = tomap({
@@ -202,8 +208,13 @@ locals {
202208
{
203209
name = "MAVIS__SPLUNK__ENABLED"
204210
value = var.enable_splunk ? "true" : "false"
211+
},
212+
{
213+
name = "APP_VERSION"
214+
value = var.app_version
205215
}
206216
]
217+
207218
task_secrets = concat([
208219
{
209220
name = var.db_secret_arn == null ? "DB_CREDENTIALS" : "DB_SECRET"

0 commit comments

Comments
 (0)