Skip to content

Commit d7b9d0c

Browse files
committed
VED-812: Tidy up. Use env vars associated with the Apigee environment. Make more steps conditional.
1 parent 2096d8a commit d7b9d0c

File tree

2 files changed

+40
-45
lines changed

2 files changed

+40
-45
lines changed

.github/workflows/deploy-backend.yml

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,42 @@ on:
4242
type: string
4343
description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments
4444

45+
env: # Sonarcloud - do not allow direct usage of untrusted data
46+
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
47+
ENVIRONMENT: ${{ inputs.environment }}
48+
SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
49+
50+
permissions:
51+
id-token: write
52+
contents: read
53+
4554
jobs:
4655
terraform-plan:
4756
runs-on: ubuntu-latest
4857
environment:
4958
name: ${{ inputs.environment }}
50-
env: # Sonarcloud - do not allow direct usage of untrusted data
51-
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
52-
BACKEND_ENVIRONMENT: ${{ inputs.environment }}
53-
BACKEND_SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
54-
permissions:
55-
id-token: write
56-
contents: read
5759
steps:
60+
- name: Checkout
61+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
62+
5863
- name: Connect to AWS
5964
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838
6065
with:
6166
aws-region: eu-west-2
6267
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
6368
role-session-name: github-actions
6469

65-
- name: Whoami
66-
run: aws sts get-caller-identity
67-
68-
- name: Checkout
69-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
70-
7170
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
7271
with:
7372
terraform_version: "1.12.2"
7473

7574
- name: Terraform Init
7675
working-directory: terraform
77-
run: make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
76+
run: make init
7877

7978
- name: Terraform Plan
8079
working-directory: terraform
81-
run: make plan-ci apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
80+
run: make plan-ci
8281

8382
- name: Save Terraform Plan
8483
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
@@ -91,13 +90,6 @@ jobs:
9190
runs-on: ubuntu-latest
9291
environment:
9392
name: ${{ inputs.environment }}
94-
env: # Sonarcloud - do not allow direct usage of untrusted data
95-
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
96-
BACKEND_ENVIRONMENT: ${{ inputs.environment }}
97-
BACKEND_SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
98-
permissions:
99-
id-token: write
100-
contents: read
10193
steps:
10294
- name: Checkout
10395
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
@@ -120,12 +112,12 @@ jobs:
120112

121113
- name: Terraform Init
122114
working-directory: terraform
123-
run: make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
115+
run: make init
124116

125117
- name: Terraform Apply
126118
working-directory: terraform
127119
run: |
128-
make apply-ci apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
120+
make apply-ci
129121
echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV
130122
131123
- name: Install poetry
@@ -145,7 +137,6 @@ jobs:
145137
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
146138
working-directory: "./lambdas/mns_subscription"
147139
env:
148-
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
149140
SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }}
150141
run: |
151142
poetry install --no-root

.github/workflows/run-e2e-tests.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,73 +48,76 @@ permissions:
4848
jobs:
4949
wait-for-deployment:
5050
runs-on: ubuntu-latest
51-
environment: ${{ inputs.environment }}
51+
environment: ${{ inputs.apigee_environment }}
5252
steps:
5353
- name: Wait for API to be available
5454
run: |
55-
set -ex
56-
5755
endpoint=""
58-
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
56+
if [[ ${APIGEE_ENVIRONMENT} =~ "prod" ]]; then
5957
endpoint="https://api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
6058
else
6159
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
6260
fi
6361
6462
counter=0
65-
while [[ $counter -lt 31 ]]; do
66-
response=$(curl -H "apikey: ${STATUS_API_KEY}" -s "$endpoint")
67-
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
68-
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
69-
status=$(jq -r '.status' <<< "$response")
70-
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ] && [ "$status" == "pass" ]; then
63+
while [[ ${counter} -lt 31 ]]; do
64+
response=$(curl -H "apikey: ${STATUS_API_KEY}" -s "${endpoint}")
65+
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "${response}")
66+
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "${response}")
67+
status=$(jq -r '.status' <<< "${response}")
68+
if [[ "${response_code}" -eq 200 ]] && [[ "${response_body}" == "OK" ]] && [[ "${status}" == "pass" ]]; then
7169
echo "Status test successful"
7270
break
7371
else
74-
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
72+
echo "Waiting for ${endpoint} to return a 200 response with 'OK' body..."
7573
((counter=counter+1)) # Increment counter by 1
76-
echo "Attempt $counter"
74+
echo "Attempt ${counter}"
7775
sleep 30
7876
fi
7977
done
8078
81-
if [ $counter -eq 31 ]; then
79+
if [[ ${counter} -eq 31 ]]; then
8280
echo "Status test failed: Maximum number of attempts reached"
8381
echo "Last response received:"
84-
echo "$response"
82+
echo "${response}"
8583
exit 1
8684
fi
8785
8886
e2e-tests:
8987
runs-on: ubuntu-latest
9088
needs: [wait-for-deployment]
91-
environment: ${{ inputs.environment }}
89+
environment: ${{ inputs.apigee_environment }}
9290
env:
9391
APIGEE_USERNAME: ${{ vars.APIGEE_USERNAME }}
9492
SOURCE_COMMIT_ID: ${{ github.sha }}
9593
steps:
94+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
95+
9696
- name: Connect to AWS
97+
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
9798
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838
9899
with:
99100
aws-region: eu-west-2
100101
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
101102
role-session-name: github-actions
102103

103-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
104-
105104
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
105+
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
106106
with:
107107
terraform_version: "1.12.2"
108108

109109
- name: Terraform Init
110+
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
110111
working-directory: terraform
111112
run: make init
112113

113114
- name: Set Terraform workspace
115+
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
114116
working-directory: terraform
115117
run: make workspace
116118

117119
- name: Read Terraform outputs
120+
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
118121
working-directory: terraform
119122
run: |
120123
echo "IMMS_DELTA_TABLE_NAME=$(make -s output name=imms_delta_table_name)" >> $GITHUB_ENV
@@ -137,6 +140,7 @@ jobs:
137140
run: poetry install --no-root
138141

139142
- name: Get Apigee access token
143+
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
140144
working-directory: e2e
141145
env:
142146
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
@@ -181,17 +185,17 @@ jobs:
181185
# Only actually depend on wait-for-deployment, but run after e2e-tests
182186
if: ${{ !cancelled() && needs.wait-for-deployment.result == 'success' && vars.RUN_BATCH_E2E_TESTS == 'true' }}
183187
runs-on: ubuntu-latest
184-
environment: ${{ inputs.environment }}
188+
environment: ${{ inputs.apigee_environment }}
185189
steps:
190+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
191+
186192
- name: Connect to AWS
187193
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838
188194
with:
189195
aws-region: eu-west-2
190196
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
191197
role-session-name: github-actions
192198

193-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
194-
195199
- name: Install poetry
196200
run: pip install poetry==2.1.4
197201

0 commit comments

Comments
 (0)