Skip to content

Commit 5506643

Browse files
committed
Re-enable end-to-end tests, sourcing status endpoint from github secret, rather than fetching from APIM
1 parent 72c1a69 commit 5506643

26 files changed

Lines changed: 16577 additions & 15344 deletions

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PROXY_NAME=
1818
export NON_PROD_API_KEY=xxx
1919
export INTEGRATION_API_KEY=xxx
2020
export PRODUCTION_API_KEY=xxx
21+
export STATUS_ENDPOINT_API_KEY=xxx
2122

2223
# Private Keys
2324
# ============

.github/actions/acceptance-tests/action.yml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ runs:
2424

2525
steps:
2626
- name: Fetch terraform output
27+
if: ${{ inputs.testType != 'e2e' }}
2728
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
2829
with:
2930
name: terraform-output-${{ inputs.targetComponent }}
3031

3132
- name: Get Node version
33+
if: ${{ inputs.testType != 'e2e' }}
3234
id: nodejs_version
3335
shell: bash
3436
run: |
@@ -40,11 +42,80 @@ runs:
4042
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
4143

4244
- name: "Set PR NUMBER"
45+
if: ${{ inputs.testType == 'e2e' }}
46+
id: set_pr_number
4347
shell: bash
4448
run: |
45-
echo "PR_NUMBER=${{ inputs.targetEnvironment }}" >> $GITHUB_ENV
49+
env="${{ inputs.targetEnvironment }}"
50+
if [[ "$env" == main ]]; then
51+
echo "pr_number=" >> $GITHUB_OUTPUT
52+
elif [[ "$env" == pr* ]]; then
53+
echo "pr_number=${env#pr}" >> $GITHUB_OUTPUT
54+
else
55+
echo "pr_number=$env" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Install poetry and e2e test dependencies
59+
if: ${{ inputs.testType == 'e2e' }}
60+
shell: bash
61+
run: |
62+
pipx install poetry
63+
cd tests/e2e-tests && poetry install
64+
65+
- name: "Determine if proxy has been deployed"
66+
if: ${{ inputs.testType == 'e2e' }}
67+
id: check_proxy_deployed
68+
env:
69+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
70+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
71+
shell: bash
72+
run: |
73+
if [[ -z "$PR_NUMBER" ]]; then
74+
echo "No pull request detected; proxy was deployed."
75+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
76+
exit 0
77+
fi
78+
79+
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
80+
81+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
82+
echo "Labels on PR #$PR_NUMBER: $labels"
83+
84+
if echo "$labels" | grep -Fxq 'deploy-proxy'; then
85+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
86+
else
87+
echo "proxy_deployed=false" >> $GITHUB_OUTPUT
88+
fi
4689
4790
- name: Run test - ${{ inputs.testType }}
91+
if: ${{ inputs.testType != 'e2e'}}
4892
shell: bash
93+
env:
94+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
4995
run: |
5096
make test-${{ inputs.testType }}
97+
98+
- name: Run test - e2e
99+
if: ${{ inputs.testType == 'e2e' && steps.check_proxy_deployed.outputs.proxy_deployed == 'true'}}
100+
shell: bash
101+
env:
102+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
103+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
104+
run: |
105+
PR_NUMBER=""
106+
echo "$SUPPLIER_API_PRIVATE_KEY" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
107+
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
108+
BASE_PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
109+
110+
export API_ENVIRONMENT=internal-dev
111+
if [[ -z "$PR_NUMBER" ]]; then
112+
export PROXY_NAME="${BASE_PROXY_NAME}"
113+
export NON_PROD_API_KEY="${APIM_API_KEY}"
114+
else
115+
export PROXY_NAME="${BASE_PROXY_NAME}-PR-${PR_NUMBER}"
116+
export NON_PROD_API_KEY="${APIM_PR_API_KEY}"
117+
fi
118+
119+
export STATUS_ENDPOINT_API_KEY="${APIM_STATUS_API_KEY}"
120+
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
121+
make .internal-dev-test

.github/actions/build-proxies/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ runs:
113113
--targetComponent "${{ inputs.targetComponent }}" \
114114
--targetWorkflow "proxy-deploy.yaml" \
115115
--targetEnvironment "${{ inputs.environment }}" \
116+
--internalRef "feature/CCM-14778" \
116117
--runId "${{ inputs.runId }}" \
117118
--buildSandbox ${{ inputs.buildSandbox }} \
118119
--apimEnvironment "${{ env.APIM_ENV }}" \

.github/actions/e2e-tests/action.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/actions/test-types.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
22
"component",
3+
"e2e",
34
"sandbox"
45
]

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ./dispatch_internal_repo_workflow.sh \
77
# --infraRepoName <repo> \
88
# --releaseVersion <version> \
9-
# --targetWorkflow <workflow.yaml> \
9+
# --targetWorkflow "deploy.yaml" \
1010
# --targetEnvironment <env> \
1111
# --targetComponent <component> \
1212
# --targetAccountGroup <group> \
@@ -17,7 +17,11 @@
1717
# --overrideRoleName <name>
1818

1919
#
20-
# All arguments are required except terraformAction, and internalRef.
20+
# Required arguments are:
21+
# infraRepoName, releaseVersion, targetWorkflow, targetEnvironment, targetComponent, targetAccountGroup.
22+
#
23+
# All other arguments are optional.
24+
#
2125
# Example:
2226
# ./dispatch_internal_repo_workflow.sh \
2327
# --infraRepoName "nhs-notify-web-template-management" \
@@ -30,7 +34,9 @@
3034
# --internalRef "main" \
3135
# --overrides "tf_var=someString" \
3236
# --overrideProjectName nhs \
33-
# --overrideRoleName nhs-service-iam-role
37+
# --overrideRoleName nhs-service-iam-role \
38+
# --extraSecretNames '["MY_API_KEY"]'
39+
3440

3541
set -e
3642

@@ -104,6 +110,10 @@ while [[ $# -gt 0 ]]; do
104110
version="$2"
105111
shift 2
106112
;;
113+
--extraSecretNames) # JSON array of secret names to fetch in the internal repo (optional)
114+
extraSecretNames="$2"
115+
shift 2
116+
;;
107117
*)
108118
echo "[ERROR] Unknown argument: $1"
109119
exit 1
@@ -202,6 +212,10 @@ if [[ -z "$version" ]]; then
202212
version=""
203213
fi
204214

215+
if [[ -z "$extraSecretNames" ]]; then
216+
extraSecretNames=""
217+
fi
218+
205219
echo "==================== Workflow Dispatch Parameters ===================="
206220
echo " infraRepoName: $infraRepoName"
207221
echo " releaseVersion: $releaseVersion"
@@ -240,6 +254,7 @@ DISPATCH_EVENT=$(jq -ncM \
240254
--arg boundedContext "$boundedContext" \
241255
--arg targetDomain "$targetDomain" \
242256
--arg version "$version" \
257+
--argjson extraSecretNames "${extraSecretNames:-null}" \
243258
'{
244259
"ref": "'"$internalRef"'",
245260
"inputs": (
@@ -255,6 +270,7 @@ DISPATCH_EVENT=$(jq -ncM \
255270
(if $boundedContext != "" then { "boundedContext": $boundedContext } else {} end) +
256271
(if $targetDomain != "" then { "targetDomain": $targetDomain } else {} end) +
257272
(if $version != "" then { "version": $version } else {} end) +
273+
(if $extraSecretNames != null then { "extraSecretNames": ($extraSecretNames | tojson) } else {} end) +
258274
(if $targetAccountGroup != "" then { "targetAccountGroup": $targetAccountGroup } else {} end) +
259275
{
260276
"releaseVersion": $releaseVersion,
@@ -269,16 +285,22 @@ echo "[INFO] Triggering workflow '$targetWorkflow' in nhs-notify-internal..."
269285
echo "[DEBUG] Dispatch event payload: $DISPATCH_EVENT"
270286

271287
trigger_response=$(curl -s -L \
272-
--fail \
288+
-w "\nHTTP_STATUS:%{http_code}" \
273289
-X POST \
274290
-H "Accept: application/vnd.github+json" \
275291
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
276292
-H "X-GitHub-Api-Version: 2022-11-28" \
277293
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/$targetWorkflow/dispatches" \
278294
-d "$DISPATCH_EVENT" 2>&1)
279295

280-
if [[ $? -ne 0 ]]; then
281-
echo "[ERROR] Failed to trigger workflow. Response: $trigger_response"
296+
http_status=$(echo "$trigger_response" | grep "HTTP_STATUS:" | cut -d: -f2)
297+
body=$(echo "$trigger_response" | grep -v "HTTP_STATUS:")
298+
299+
echo "[DEBUG] HTTP status: $http_status"
300+
echo "[DEBUG] Response body: $body"
301+
302+
if [[ "$http_status" -lt 200 || "$http_status" -ge 300 ]]; then
303+
echo "[ERROR] Failed to trigger workflow. HTTP $http_status. Response: $body"
282304
exit 1
283305
fi
284306

.github/workflows/stage-3-build.yaml

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ jobs:
5959
version: "${{ inputs.version }}"
6060
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6161

62-
artefact-oas-spec:
63-
name: "Build OAS spec (${{ matrix.apimEnv }})"
62+
artefact-oas-spec-main:
63+
name: "Build OAS spec for main"
6464
if: (github.event_name == 'push' && github.ref == 'refs/heads/main')
6565
runs-on: ubuntu-latest
6666
needs: [artefact-jekyll-docs]
@@ -80,6 +80,24 @@ jobs:
8080
nodejs_version: ${{ inputs.nodejs_version }}
8181
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8282

83+
artefact-oas-spec-pr:
84+
name: "Build OAS spec for PR"
85+
if: (inputs.pr_number != '')
86+
runs-on: ubuntu-latest
87+
needs: [artefact-jekyll-docs]
88+
timeout-minutes: 10
89+
steps:
90+
- name: "Checkout code"
91+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
92+
- name: "Build OAS spec"
93+
uses: ./.github/actions/build-oas-spec
94+
with:
95+
version: "${{ inputs.version }}"
96+
apimEnv: internal-dev-pr
97+
buildSandbox: false
98+
nodejs_version: ${{ inputs.nodejs_version }}
99+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
83101
artefact-oas-spec-sandbox:
84102
name: "Build OAS spec for sandbox"
85103
runs-on: ubuntu-latest
@@ -97,9 +115,18 @@ jobs:
97115
nodejs_version: ${{ inputs.nodejs_version }}
98116
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99117

118+
artefact-oas-spec:
119+
name: "OAS spec ready"
120+
runs-on: ubuntu-latest
121+
needs: [artefact-oas-spec-pr, artefact-oas-spec-main]
122+
if: always() && !failure()
123+
steps:
124+
- run: echo "OAS spec build complete"
125+
100126
artefact-sdks:
101127
name: "Build SDKs"
102128
runs-on: ubuntu-latest
129+
if: always() && !failure()
103130
needs: [artefact-oas-spec]
104131
timeout-minutes: 10
105132
steps:
@@ -162,11 +189,11 @@ jobs:
162189
--terraformAction "apply" \
163190
--overrideProjectName "nhs" \
164191
--overrideRoleName "nhs-main-acct-supplier-api-github-deploy"
165-
artefact-proxies:
166-
name: "Build proxies"
192+
artefact-proxy:
193+
name: "Build proxy"
167194
runs-on: ubuntu-latest
168-
if: inputs.deploy_proxy == 'true'
169-
needs: [artefact-oas-spec-sandbox, pr-create-dynamic-environment]
195+
if: always() && !failure() && inputs.deploy_proxy == 'true'
196+
needs: [artefact-oas-spec, pr-create-dynamic-environment]
170197
timeout-minutes: 10
171198
env:
172199
PROXYGEN_API_NAME: nhs-notify-supplier
@@ -175,7 +202,29 @@ jobs:
175202
steps:
176203
- name: "Checkout code"
177204
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
178-
- name: "Build proxies"
205+
- name: "Build proxy"
206+
uses: ./.github/actions/build-proxies
207+
with:
208+
version: "${{ inputs.version }}"
209+
environment: ${{ needs.pr-create-dynamic-environment.outputs.environment_name }}
210+
apimEnv: "internal-dev-pr"
211+
runId: "${{ github.run_id }}"
212+
buildSandbox: false
213+
releaseVersion: ${{ github.head_ref || github.ref_name }}
214+
artefact-sandbox-proxy:
215+
name: "Build proxy for sandbox"
216+
runs-on: ubuntu-latest
217+
if: always() && !failure() && inputs.deploy_proxy == 'true'
218+
needs: [artefact-oas-spec-sandbox, artefact-oas-spec, pr-create-dynamic-environment]
219+
timeout-minutes: 10
220+
env:
221+
PROXYGEN_API_NAME: nhs-notify-supplier
222+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
223+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
224+
steps:
225+
- name: "Checkout code"
226+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
227+
- name: "Build proxy for sandbox"
179228
uses: ./.github/actions/build-proxies
180229
with:
181230
version: "${{ inputs.version }}"

.github/workflows/stage-4-acceptance.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,9 @@ jobs:
7777
--targetWorkflow "dispatch-contextual-tests-dynamic-env.yaml" \
7878
--infraRepoName "nhs-notify-supplier-api" \
7979
--releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
80+
--internalRef "feature/CCM-14778" \
8081
--overrideProjectName "nhs" \
8182
--targetEnvironment "$ENVIRONMENT" \
8283
--targetAccountGroup "nhs-notify-supplier-api-dev" \
83-
--targetComponent "api"
84-
85-
run-e2e-tests:
86-
name: Run End-to-End Tests
87-
runs-on: ubuntu-latest
88-
if: inputs.proxy_deployed == 'true'
89-
steps:
90-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
91-
92-
- name: "Run e2e tests"
93-
#uses: ./.github/actions/e2e-tests
94-
env:
95-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96-
NON_PROD_API_KEY: ${{ secrets.NON_PROD_API_KEY }}
97-
INTERNAL_DEV_TEST_PEM: ${{ secrets.INTERNAL_DEV_TEST_PEM }}
98-
shell: bash
99-
run: |
100-
echo "E2E tests are currently disabled. See CCM-14778"
84+
--targetComponent "api" \
85+
--extraSecretNames '["SUPPLIER_API_PRIVATE_KEY","APIM_API_KEY","APIM_PR_API_KEY", "APIM_STATUS_API_KEY"]'

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ ${VERBOSE}.SILENT: \
131131
#####################
132132

133133
TEST_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
134+
STATUS_ENDPOINT_API_KEY="$(STATUS_ENDPOINT_API_KEY)" \
134135
PYTHONPATH=. poetry run pytest --disable-warnings -vv \
135136
--color=yes \
136137
-n 4 \

myContext.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When asking me questions, ask one at a time, or at most two.
2+
3+
Don't tell me to raise JIRA tickets - I can decide for myself when to do this.

0 commit comments

Comments
 (0)