Skip to content

Commit 2dac59a

Browse files
authored
[PRM-392] Workflow enhancements: Input cleanup, cron file renaming, prod releases limited to tags, sandbox name limit (9 characters), introducing run-names and tear down fix (Virus Scanner) (#433)
1 parent aecbd07 commit 2dac59a

12 files changed

+111
-133
lines changed

.github/workflows/base-cleanup-lambda-edge.yml

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@ name: 'Z-BASE: Cleanup - Lambda@Edge'
33
on:
44
workflow_call:
55
inputs:
6-
sandbox_workspace:
7-
description: 'The sandbox workspace name'
6+
git_ref:
7+
description: 'Branch, tag or SHA'
88
required: true
99
type: string
10-
environment:
10+
sandbox_name:
11+
description: 'Sandbox name'
1112
required: true
1213
type: string
13-
lambda_function_name:
14-
description: 'The sandbox workspace name'
14+
environment:
15+
description: "GitHub Environment name"
1516
required: true
1617
type: string
17-
python_version:
18-
description: 'Version of Python to run the cleanup script against'
19-
required: true
20-
type: 'string'
21-
build_branch:
22-
description: 'Feature branch to push to sandbox.'
23-
required: true
24-
type: 'string'
2518
secrets:
2619
AWS_ASSUME_ROLE:
2720
required: true
@@ -39,23 +32,21 @@ jobs:
3932
steps:
4033
- name: Display passed variables
4134
run: |
42-
echo Python Version: ${{ inputs.python_version }}
43-
echo Build Branch: ${{ inputs.build_branch }}
35+
echo Sandbox name: ${{ inputs.sandbox_name }}
36+
echo Git branch/tag/sha: ${{ inputs.git_ref }}
4437
echo Environment: ${{ inputs.environment }}
45-
echo Sandbox: ${{ inputs.sandbox_workspace }}
46-
echo Lambda Function Name: ${{ inputs.lambda_function_name }}
4738
4839
- name: Checkout
4940
uses: actions/checkout@v5
5041
with:
5142
repository: 'nhsconnect/national-document-repository-infrastructure'
52-
ref: ${{ inputs.build_branch }}
43+
ref: ${{ inputs.git_ref }}
5344
fetch-depth: '0'
5445

55-
- name: Set up Python ${{ inputs.python_version }}
46+
- name: Set up Python 3.11
5647
uses: actions/setup-python@v6
5748
with:
58-
python-version: ${{ inputs.python_version }}
49+
python-version: 3.11
5950

6051
- name: Configure AWS Credentials for ${{ vars.AWS_REGION }}
6152
uses: aws-actions/configure-aws-credentials@v5
@@ -69,11 +60,11 @@ jobs:
6960
id: cloudfront
7061
run: |
7162
aws cloudfront list-distributions > distributions.json
72-
distribution_id=$(jq -r --arg origin_id "${{ inputs.sandbox_workspace }}-lloyd-george-store" \
63+
distribution_id=$(jq -r --arg origin_id "${{ inputs.sandbox_name }}-lloyd-george-store" \
7364
'.DistributionList.Items[] | select(.Origins.Items[].Id==$origin_id) | .Id' distributions.json | head -n 1)
7465
7566
if [ -z "$distribution_id" ]; then
76-
echo "No distribution found for origin ID: ${{ inputs.sandbox_workspace }}-lloyd-george-store"
67+
echo "No distribution found for origin ID: ${{ inputs.sandbox_name }}-lloyd-george-store"
7768
else
7869
echo "Distribution ID found: $distribution_id"
7970
fi
@@ -91,4 +82,4 @@ jobs:
9182
run: ./venv/bin/python3 -u scripts/remove_edge_associations.py
9283
env:
9384
DISTRIBUTION_ID: ${{ env.DISTRIBUTION_ID }}
94-
LAMBDA_FUNCTION_NAME: ${{ inputs.lambda_function_name }}
85+
LAMBDA_FUNCTION_NAME: "${{ inputs.sandbox_name }}_EdgePresignLambda"

.github/workflows/base-cleanup-workspace.yml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ name: 'Z-BASE: Cleanup - Workspace'
33
on:
44
workflow_call:
55
inputs:
6-
build_branch:
7-
description: 'Feature branch to push to sandbox.'
6+
git_ref:
7+
description: 'Branch, tag or SHA'
88
required: true
9-
type: 'string'
10-
sandbox:
11-
description: 'Which Sandbox to push to.'
9+
type: string
10+
sandbox_name:
11+
description: 'Sandbox name'
1212
required: true
13-
type: 'string'
13+
type: string
1414
environment:
15-
description: "Which environment should this run against"
15+
description: "GitHub Environment name"
1616
required: true
17-
type: "string"
18-
python_version:
19-
description: "Version of Python to run the cleanup script against"
20-
required: true
21-
type: "string"
17+
type: string
2218
secrets:
2319
AWS_ASSUME_ROLE:
2420
required: true
@@ -35,10 +31,9 @@ jobs:
3531
steps:
3632
- name: Display client passed variables
3733
run: |
38-
echo Python Version: ${{ inputs.python_version }}
39-
echo Build Branch: ${{ inputs.build_branch }}
34+
echo Sandbox name: ${{ inputs.sandbox_name }}
35+
echo Git branch/tag/sha: ${{ inputs.git_ref }}
4036
echo Environment: ${{ inputs.environment }}
41-
echo Sandbox: ${{ inputs.sandbox }}
4237
4338
cleanup_process:
4439
name: Run Cleanup Versions script
@@ -50,13 +45,13 @@ jobs:
5045
uses: actions/checkout@v5
5146
with:
5247
repository: 'nhsconnect/national-document-repository-infrastructure'
53-
ref: ${{ inputs.build_branch }}
48+
ref: ${{ inputs.git_ref }}
5449
fetch-depth: '0'
5550

56-
- name: Set up Python ${{ inputs.python_version }}
51+
- name: Set up Python 3.11
5752
uses: actions/setup-python@v6
5853
with:
59-
python-version: ${{ inputs.python_version }}
54+
python-version: 3.11
6055

6156
- name: Make virtual environment
6257
run: |
@@ -74,4 +69,4 @@ jobs:
7469

7570
- name: Run Version Cleanup Script
7671
run: |
77-
./venv/bin/python3 scripts/cleanup_versions.py ${{ inputs.sandbox }}
72+
./venv/bin/python3 scripts/cleanup_versions.py ${{ inputs.sandbox_name }}

.github/workflows/automated-daily-health-check.yml renamed to .github/workflows/cron-daily-health-check.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: 'Z-AUTOMATED: Daily health check'
1+
name: 'Z-CRON: Daily health check'
22

33
on:
4-
schedule:
5-
- cron: 30 4 * * 1-5
4+
schedule:
5+
- cron: 30 4 * * 1-5
66

77
permissions:
88
pull-requests: write
@@ -189,9 +189,7 @@ jobs:
189189
needs: [ 'set_workspace', 'deploy_ui', 'deploy_all_lambdas' ]
190190
uses: ./.github/workflows/tear-down-sandbox.yml
191191
with:
192-
build_branch: main
192+
git_ref: main
193+
sandbox_name: ${{ needs.set_workspace.outputs.workspace }}
193194
environment: development
194-
sandbox_workspace: ${{ needs.set_workspace.outputs.workspace }}
195-
terraform_vars: dev.tfvars
196-
backend: backend.conf
197195
secrets: inherit

.github/workflows/automated-tear-down-sandbox.yml renamed to .github/workflows/cron-tear-down-sandbox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Z-AUTOMATED: Tear down - Sandbox'
1+
name: 'Z-CRON: Tear down - Sandbox'
22

33
on:
44
schedule:

.github/workflows/automated-tear-down-test.yml renamed to .github/workflows/cron-tear-down-test.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Z-AUTOMATED: Tear down - Test'
1+
name: 'Z-CRON: Tear down - Test'
22

33
on:
44
schedule:
@@ -14,10 +14,8 @@ jobs:
1414
name: Remove Lambda@Edge Associations
1515
uses: ./.github/workflows/base-cleanup-lambda-edge.yml
1616
with:
17-
sandbox_workspace: ndr-test
18-
lambda_function_name: 'ndr-test_EdgePresignLambda'
19-
python_version: 3.11
20-
build_branch: main
17+
git_ref: main
18+
sandbox_name: ndr-test
2119
environment: test
2220
secrets:
2321
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
@@ -26,10 +24,9 @@ jobs:
2624
name: Cleanup Versions Process
2725
uses: ./.github/workflows/base-cleanup-workspace.yml
2826
with:
29-
build_branch: main
30-
sandbox: ndr-test
27+
git_ref: main
28+
sandbox_name: ndr-test
3129
environment: test
32-
python_version: 3.11
3330
secrets:
3431
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
3532

.github/workflows/deploy-pre-prod.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: "Deploy - Pre-prod"
22

3+
run-name: "${{ github.event.inputs.branch_or_tag }}"
4+
35
on:
46
workflow_dispatch:
57
inputs:
68
branch_or_tag:
7-
description: "Which branch or tag do you want to deploy to pre-prod?"
9+
description: "Branch or tag to deploy"
810
required: true
911
type: string
1012
default: main

.github/workflows/deploy-prod.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# .github/workflows/terraform-dev
21
name: "Deploy - Prod"
32

3+
run-name: "${{ github.event.inputs.git_tag }}"
4+
45
on:
56
workflow_dispatch:
67
inputs:
7-
tagVersion:
8-
description: "What tagged verison do you want to push to prod?"
8+
git_tag:
9+
description: "Git tag to deploy"
910
required: true
1011
type: "string"
1112

@@ -24,7 +25,7 @@ jobs:
2425
- name: Checkout
2526
uses: actions/checkout@v5
2627
with:
27-
ref: ${{ github.event.inputs.tagVersion}}
28+
ref: refs/tags/${{ github.event.inputs.git_tag}}
2829
fetch-depth: "0"
2930

3031
- name: Configure AWS Credentials

.github/workflows/deploy-sandbox.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
# .github/workflows/terraform-dev
21
name: "Deploy - Sandbox"
32

3+
run-name: "${{ github.event.inputs.git_ref }} | ${{ github.event.inputs.sandbox_name }}"
4+
45
on:
56
workflow_dispatch:
67
inputs:
7-
buildBranch:
8-
description: "Feature branch to push to sandbox."
9-
required: true
10-
type: "string"
11-
sandboxWorkspace:
12-
description: "Which Sandbox to push to."
8+
git_ref:
9+
description: "Branch, tag or SHA to deploy"
1310
required: true
1411
type: "string"
15-
environment:
16-
default: "development"
17-
description: "Which environment should this run against"
12+
sandbox_name:
13+
description: "Sandbox name [a-z0-9]{1,9}"
1814
required: true
1915
type: "string"
2016

@@ -26,9 +22,18 @@ permissions:
2622
jobs:
2723
terraform_process:
2824
runs-on: ubuntu-latest
29-
environment: ${{ github.event.inputs.environment }}
25+
environment: development
3026

3127
steps:
28+
- name: Validate inputs
29+
run: |
30+
if ! [[ "$SANDBOX_NAME" =~ ^[a-z0-9]{1,9}$ ]]; then
31+
echo "Sandbox name must match [a-z0-9]{1,9} (lowercase letters and digits only, 1-9 chars)."
32+
exit 1
33+
fi
34+
env:
35+
SANDBOX_NAME: ${{ github.event.inputs.sandbox_name }}
36+
3237
# Checkout the repository to the GitHub Actions runner
3338
- name: Checkout Base
3439
uses: actions/checkout@v5
@@ -61,7 +66,7 @@ jobs:
6166

6267
- name: Terraform Set Workspace Base
6368
id: base_workspace
64-
run: terraform workspace select -or-create ${{ github.event.inputs.sandboxWorkspace}}
69+
run: terraform workspace select -or-create ${{ github.event.inputs.sandbox_name}}
6570
working-directory: ./infrastructure
6671
shell: bash
6772

@@ -79,7 +84,7 @@ jobs:
7984
- name: Checkout Branch
8085
uses: actions/checkout@v5
8186
with:
82-
ref: ${{ github.event.inputs.buildBranch}}
87+
ref: ${{ github.event.inputs.git_ref}}
8388

8489
# Checks that all Terraform configuration files adhere to a canonical format.
8590
- name: Terraform Format
@@ -94,7 +99,7 @@ jobs:
9499

95100
- name: Terraform Set Workspace
96101
id: workspace
97-
run: terraform workspace select ${{ github.event.inputs.sandboxWorkspace}}
102+
run: terraform workspace select ${{ github.event.inputs.sandbox_name}}
98103
working-directory: ./infrastructure
99104
shell: bash
100105

.github/workflows/deploy-test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# .github/workflows/terraform-dev
21
name: "Deploy - Test"
32

3+
run-name: "${{ github.event.inputs.git_ref }}"
4+
45
on:
56
workflow_dispatch:
67
inputs:
7-
build_branch:
8-
description: "Feature branch to push to test?"
8+
git_ref:
9+
description: "Branch, tag or SHA to deploy"
910
required: true
1011
type: "string"
1112

@@ -24,7 +25,7 @@ jobs:
2425
- name: Checkout
2526
uses: actions/checkout@v5
2627
with:
27-
ref: ${{ github.event.inputs.build_branch}}
28+
ref: ${{ github.event.inputs.git_ref}}
2829

2930
- name: Configure AWS Credentials
3031
uses: aws-actions/configure-aws-credentials@v5

0 commit comments

Comments
 (0)