-
Notifications
You must be signed in to change notification settings - Fork 4
280 lines (253 loc) · 10.8 KB
/
run-e2e-automation-tests.yml
File metadata and controls
280 lines (253 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
name: FHIR API and Batch Automation - E2E Tests
on:
workflow_call:
inputs:
apigee_environment:
required: true
type: string
environment:
required: true
type: string
sub_environment:
required: true
type: string
service_under_test:
required: true
type: string
suite_to_run:
required: true
type: string
secrets:
APIGEE_PASSWORD:
required: true
APIGEE_BASIC_AUTH_TOKEN:
required: true
APIGEE_OTP_KEY:
required: true
CIS2_E2E_USERNAME:
required: true
STATUS_API_KEY:
required: true
workflow_dispatch:
inputs:
apigee_environment:
type: choice
description: Select the Apigee proxy environment
options:
- internal-dev
- internal-dev-sandbox
- sandbox
- internal-qa
- int
- ref
environment:
type: choice
description: Select the AWS backend environment
options:
- dev
- preprod
sub_environment:
type: string
description: Set the sub environment name e.g. pr-xxx, internal-qa, internal-dev, int-green or int-blue
service_under_test:
description: Select the service you want to test
required: true
type: choice
options:
- fhir_api
- batch
- all
suite_to_run:
description: Select the suite you would like to run
default: "functional"
type: choice
options:
- smoke
- functional
- sandbox
- proxy_smoke
env:
APIGEE_AUTH_ENV: ${{ inputs.apigee_environment == 'int' && inputs.apigee_environment || 'internal-dev' }}
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
ENVIRONMENT: ${{ inputs.environment }}
SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
SERVICE_BASE_PATH: ${{ startsWith(inputs.sub_environment, 'pr-') && format('immunisation-fhir-api/FHIR/R4-{0}', inputs.sub_environment) || 'immunisation-fhir-api/FHIR/R4' }}
PROXY_NAME: ${{ startsWith(inputs.sub_environment, 'pr-') && format('immunisation-fhir-api-{0}', inputs.sub_environment) || format('immunisation-fhir-api-{0}', inputs.apigee_environment) }}
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}
SOURCE_COMMIT_ID: ${{ github.sha }}
jobs:
wait-for-deployment:
permissions:
contents: read
runs-on: ubuntu-latest
environment: ${{ inputs.apigee_environment }}
steps:
- name: Wait for API to be available
if: github.event_name != 'workflow_dispatch'
run: |
endpoint=""
if [[ ${APIGEE_ENVIRONMENT} =~ "prod" ]]; then
endpoint="https://api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
else
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
fi
counter=0
while [[ ${counter} -lt 31 ]]; do
response=$(curl -H "apikey: ${STATUS_API_KEY}" -s "${endpoint}")
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "${response}")
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "${response}")
status=$(jq -r '.status' <<< "${response}")
commitId=$(jq -r '.commitId' <<< "${response}")
if [[ "${response_code}" -eq 200 ]] && [[ "${response_body}" == "OK" ]] && [[ "${status}" == "pass" ]]; then
echo "Status test successful"
if [[ "${commitId}" == "${SOURCE_COMMIT_ID}" ]]; then
echo "Commit hash test successful"
break
else
echo "Waiting for ${endpoint} to return the correct commit hash..."
fi
else
echo "Waiting for ${endpoint} to return a 200 response with 'OK' body..."
fi
((counter=counter+1)) # Increment counter by 1
echo "Attempt ${counter}"
sleep 30
done
if [[ ${counter} -eq 31 ]]; then
echo "Status test failed: Maximum number of attempts reached"
echo "Last response received:"
echo "${response}"
exit 1
fi
e2e-automation-tests:
permissions:
id-token: write
checks: write
contents: write
runs-on: ubuntu-latest
needs: [wait-for-deployment]
environment: ${{ inputs.apigee_environment }}
env:
APIGEE_USERNAME: ${{ vars.APIGEE_USERNAME }}
TF_OUTPUTS_REQUIRED: ${{ inputs.suite_to_run != 'sandbox' }}
steps:
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
- name: Connect to AWS
if: ${{ env.TF_OUTPUTS_REQUIRED == 'true' }}
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
with:
aws-region: eu-west-2
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
role-session-name: github-actions
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
if: ${{ env.TF_OUTPUTS_REQUIRED == 'true' }}
with:
terraform_version: "1.12.2"
- name: Terraform Init
if: ${{ env.TF_OUTPUTS_REQUIRED == 'true' }}
working-directory: infrastructure/instance
run: make init
- name: Set Terraform workspace
if: ${{ env.TF_OUTPUTS_REQUIRED == 'true' }}
working-directory: infrastructure/instance
run: make workspace
- name: Read Terraform outputs
if: ${{ env.TF_OUTPUTS_REQUIRED == 'true' }}
working-directory: infrastructure/instance
run: |
echo "AWS_DOMAIN_NAME=$(make -s output name=service_domain_name)" >> $GITHUB_ENV
- name: Install poetry
run: pip install poetry==2.1.4
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: 3.11
cache: "poetry"
cache-dependency-path: tests/e2e_automation/poetry.lock
- name: Install e2e test dependencies
working-directory: tests/e2e_automation
run: poetry install --no-root
- name: Get Apigee access token
if: inputs.apigee_environment != 'int' && inputs.apigee_environment != 'sandbox'
working-directory: tests/e2e_automation
env:
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
run: |
CODE=$(poetry run python utilities/compute_totp_code.py "$APIGEE_OTP_KEY")
echo "::add-mask::$CODE"
echo "Requesting access token from Apigee..."
response=$(curl -s -X POST "https://login.apigee.com/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json;charset=utf-8" \
-H "Authorization: Basic $APIGEE_BASIC_AUTH_TOKEN" \
-d "username=$APIGEE_USERNAME&password=$APIGEE_PASSWORD&mfa_token=$CODE&grant_type=password")
token=$(jq -e -r '.access_token' <<< "$response")
echo "::add-mask::$token"
echo "APIGEE_ACCESS_TOKEN=$token" >> $GITHUB_ENV
- name: Run Pytest-BDD ${{ inputs.service_under_test }} tests with the ${{ inputs.suite_to_run }} filter
working-directory: tests/e2e_automation
env:
S3_env: ${{ startsWith(inputs.sub_environment, 'int-') && 'preprod' || inputs.sub_environment }}
auth_url: https://${{ env.APIGEE_AUTH_ENV }}.api.service.nhs.uk/oauth2-mock/authorize
token_url: https://${{ env.APIGEE_AUTH_ENV }}.api.service.nhs.uk/oauth2-mock/token
baseUrl: https://${{ inputs.apigee_environment }}.api.service.nhs.uk/${{env.SERVICE_BASE_PATH}}
callback_url: "https://oauth.pstmn.io/v1/callback"
username: ${{ secrets.CIS2_E2E_USERNAME }}
scope: "nhs-cis2"
sub_environment: ${{ inputs.sub_environment }}
USE_STATIC_APPS: ${{ inputs.apigee_environment == 'int' && 'True' || 'False' }}
Postman_Auth_client_Id: ${{ secrets.Postman_Auth_client_Id }} # The following static app values are only needed in INT
Postman_Auth_client_Secret: ${{ secrets.Postman_Auth_client_Secret }}
RAVS_client_Id: ${{ secrets.RAVS_client_Id }}
RAVS_client_Secret: ${{ secrets.RAVS_client_Secret }}
MAVIS_client_Id: ${{ secrets.MAVIS_client_Id }}
MAVIS_client_Secret: ${{ secrets.MAVIS_client_Secret }}
EMIS_client_Id: ${{ secrets.OPTUM_client_Id }}
EMIS_client_Secret: ${{ secrets.OPTUM_client_Secret }}
TPP_client_Id: ${{ secrets.TPP_client_Id }}
TPP_client_Secret: ${{ secrets.TPP_client_Secret }}
SONAR_client_Id: ${{ secrets.SONAR_client_Id }}
SONAR_client_Secret: ${{ secrets.SONAR_client_Secret }}
MEDICUS_client_Id: ${{ secrets.MEDICUS_client_Id }}
MEDICUS_client_Secret: ${{ secrets.MEDICUS_client_Secret }}
aws_token_refresh: "False"
TEST_PATH: ${{ inputs.service_under_test == 'batch' && 'features/batchTests' || inputs.service_under_test == 'fhir_api' && 'features/APITests' || 'features' }}
TEST_FILTER: ${{ inputs.suite_to_run == 'proxy_smoke' && 'Status_feature' || inputs.suite_to_run }}
run: poetry run pytest "$TEST_PATH" -m "$TEST_FILTER" --junitxml=output/test-results.xml --alluredir=output/allure-results
- uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
if: always()
with:
name: BDD Test Summary
path: "**/output/test-results.xml"
reporter: java-junit
fail-on-error: false
- name: Load test report history
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
if: always()
continue-on-error: true
with:
ref: gh-pages
path: gh-pages
- name: Build Allure report
if: always()
uses: simple-elf/allure-report-action@53ebb757a2097edc77c53ecef4d454fc2f2f774c
with:
allure_results: tests/e2e_automation/output/allure-results
gh_pages: gh-pages
allure_report: allure-report
allure_history: allure-history
- name: Publish Allure report to GitHub Pages
if: always()
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: allure-history
- name: Add link to Allure report
if: always()
uses: actions/github-script@v6
with:
script: |
const url = `https://${context.repo.owner}.github.io/${context.repo.repo}/`;
core.summary.addHeading('Allure Report').addLink('View Report', url).write();