Skip to content

Commit 7d97b6c

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

27 files changed

Lines changed: 398 additions & 194 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
# ============
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Acceptance tests - component
2+
description: "Run component acceptance tests for this repo"
3+
4+
inputs:
5+
testType:
6+
description: Type of test to run
7+
required: true
8+
9+
targetEnvironment:
10+
description: Name of the environment under test
11+
required: true
12+
13+
targetComponent:
14+
description: Name of the component under test
15+
required: true
16+
17+
runs:
18+
using: "composite"
19+
20+
steps:
21+
22+
- name: Fetch terraform output
23+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
24+
with:
25+
name: terraform-output-${{ inputs.targetComponent }}
26+
27+
- name: Get Node version
28+
id: nodejs_version
29+
shell: bash
30+
run: |
31+
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
32+
33+
- name: Run test - ${{ inputs.testType }}
34+
shell: bash
35+
env:
36+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
37+
run: |
38+
make test-${{ inputs.testType }}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Acceptance tests - e2e
2+
description: "Run e2e acceptance tests for this repo"
3+
4+
inputs:
5+
targetEnvironment:
6+
description: Name of the environment under test
7+
required: true
8+
9+
runs:
10+
using: "composite"
11+
12+
steps:
13+
14+
- name: Determine if proxy has been deployed
15+
id: check_proxy_deployed
16+
env:
17+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
18+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
19+
shell: bash
20+
run: |
21+
if [[ -z "$PR_NUMBER" ]]; then
22+
echo "No pull request detected; proxy was deployed."
23+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
24+
exit 0
25+
fi
26+
27+
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
28+
29+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
30+
echo "Labels on PR #$PR_NUMBER: $labels"
31+
32+
if echo "$labels" | grep -Fxq 'deploy-proxy'; then
33+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "proxy_deployed=false" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Install poetry and e2e test dependencies
39+
if: ${{ steps.check_proxy_deployed.outputs.proxy_deployed == 'true' }}
40+
shell: bash
41+
run: |
42+
pipx install poetry
43+
cd tests/e2e-tests && poetry install
44+
45+
- name: Run tests
46+
if: ${{ steps.check_proxy_deployed.outputs.proxy_deployed == 'true' }}
47+
shell: bash
48+
env:
49+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
50+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
51+
run: |
52+
echo "$SUPPLIER_API_PRIVATE_KEY" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
53+
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
54+
BASE_PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
55+
56+
export API_ENVIRONMENT=internal-dev
57+
if [[ -z "$PR_NUMBER" ]]; then
58+
export PROXY_NAME="${BASE_PROXY_NAME}"
59+
export NON_PROD_API_KEY="${APIM_API_KEY}"
60+
else
61+
export PROXY_NAME="${BASE_PROXY_NAME}-PR-${PR_NUMBER}"
62+
export NON_PROD_API_KEY="${APIM_PR_API_KEY}"
63+
fi
64+
65+
export STATUS_ENDPOINT_API_KEY="${APIM_STATUS_API_KEY}"
66+
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
67+
make .internal-dev-test

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,21 @@ runs:
2323
using: "composite"
2424

2525
steps:
26-
- name: Fetch terraform output
27-
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
28-
with:
29-
name: terraform-output-${{ inputs.targetComponent }}
30-
31-
- name: Get Node version
32-
id: nodejs_version
33-
shell: bash
34-
run: |
35-
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
3626

37-
- name: "Repo setup"
27+
- name: Repo setup
3828
uses: ./.github/actions/node-install
3929
with:
4030
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
31+
- name: Run component tests
32+
if: ${{ inputs.testType != 'e2e' }}
33+
uses: ./.github/actions/acceptance-tests-component
34+
with:
35+
testType: ${{ inputs.testType }}
36+
targetEnvironment: ${{ inputs.targetEnvironment }}
37+
targetComponent: ${{ inputs.targetComponent }}
4138

42-
- name: "Set PR NUMBER"
43-
shell: bash
44-
run: |
45-
echo "PR_NUMBER=${{ inputs.targetEnvironment }}" >> $GITHUB_ENV
46-
47-
- name: Run test - ${{ inputs.testType }}
48-
shell: bash
49-
run: |
50-
make test-${{ inputs.testType }}
39+
- name: Run e2e tests
40+
if: ${{ inputs.testType == 'e2e' && inputs.targetEnvironment == 'main' }}
41+
uses: ./.github/actions/acceptance-tests-e2e
42+
with:
43+
targetEnvironment: ${{ inputs.targetEnvironment }}

.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: 34 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
@@ -180,7 +207,7 @@ jobs:
180207
with:
181208
version: "${{ inputs.version }}"
182209
environment: ${{ needs.pr-create-dynamic-environment.outputs.environment_name }}
183-
apimEnv: "internal-dev-sandbox"
210+
apimEnv: "internal-dev-pr"
184211
runId: "${{ github.run_id }}"
185212
buildSandbox: true
186213
releaseVersion: ${{ github.head_ref || github.ref_name }}

.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"]'

0 commit comments

Comments
 (0)