Skip to content

Commit 744c2d5

Browse files
authored
Merge pull request #3661 from nhsuk/fix-version-number-footer
Fix version number display in production
2 parents 86d6d39 + 2cbe18e commit 744c2d5

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ 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
1310

1411
concurrency:
1512
group: build-and-push-image-${{ inputs.git-sha || github.sha }}
@@ -68,10 +65,8 @@ jobs:
6865
uses: actions/checkout@v4
6966
with:
7067
ref: ${{ inputs.git-sha || github.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
68+
- name: Write build SHA
69+
run: git rev-parse HEAD > public/sha
7570
- name: Build Docker image
7671
run: docker build -t "mavis:latest" .
7772
- name: Save Docker image

.github/workflows/deploy-infrastructure.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ on:
2020
description: Docker image tag to deploy
2121
required: false
2222
type: string
23+
git_ref_to_deploy:
24+
required: true
25+
type: string
26+
2327
workflow_call:
2428
inputs:
2529
environment:
@@ -29,6 +33,9 @@ on:
2933
image_tag:
3034
required: false
3135
type: string
36+
git_ref_to_deploy:
37+
required: true
38+
type: string
3239

3340
permissions: {}
3441

@@ -141,12 +148,15 @@ jobs:
141148
run: sudo snap install --classic aws-cli
142149
- name: Check if any deployments are running
143150
run: ../scripts/check-for-running-deployments.sh ${{ inputs.environment }}
151+
- name: Set Mavis app version
152+
run: |
153+
echo "APP_VERSION=${{ inputs.git_ref_to_deploy }}" >> $GITHUB_ENV
144154
- name: Terraform Plan
145155
id: plan
146156
run: |
147157
set -e
148158
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
149-
terraform plan -var="image_digest=$DIGEST" -var-file="env/${{ inputs.environment }}.tfvars" \
159+
terraform plan -var="image_digest=$DIGEST" -var="app_version=$APP_VERSION" -var-file="env/${{ inputs.environment }}.tfvars" \
150160
-out ${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
151161
- name: Validate the changes
152162
run: |

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ jobs:
8585
with:
8686
environment: ${{ inputs.environment }}
8787
image_tag: ${{ needs.determine-git-sha.outputs.git-sha }}
88+
git_ref_to_deploy: ${{ inputs.git_ref_to_deploy || github.ref_name }}
8889
deploy-application:
8990
permissions:
9091
id-token: write

config/initializers/version.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# frozen_string_literal: true
22

3-
path = Rails.root.join("public/ref")
3+
version = ENV["APP_VERSION"]
4+
if Rails.env.production? && version.present? &&
5+
!version.match?(/\Av\d+(\.\d+)+\z/)
6+
version = nil
7+
end
48

5-
version = File.read(path).strip if File.exist?(path)
69
APP_VERSION = version.presence

terraform/app/variables.tf

Lines changed: 10 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+
description = "The version identifier for the MAVIS application deployment"
163+
nullable = false
164+
}
165+
160166
locals {
161167
is_production = var.environment == "production"
162168
parameter_store_variables = tomap({
@@ -202,6 +208,10 @@ 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
]
207217
task_secrets = concat([

0 commit comments

Comments
 (0)