Skip to content

Commit 234d2c8

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

26 files changed

Lines changed: 406 additions & 187 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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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: Repo setup
23+
uses: ./.github/actions/node-install
24+
with:
25+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
26+
27+
- name: Fetch terraform output
28+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
29+
with:
30+
name: terraform-output-${{ inputs.targetComponent }}
31+
32+
- name: Get Node version
33+
id: nodejs_version
34+
shell: bash
35+
run: |
36+
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
37+
38+
- name: Run test - ${{ inputs.testType }}
39+
shell: bash
40+
env:
41+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
42+
run: |
43+
make test-${{ inputs.testType }}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
- name: "Set PR NUMBER"
14+
id: set_pr_number
15+
shell: bash
16+
run: |
17+
env="${{ inputs.targetEnvironment }}"
18+
if [[ "$env" == main ]]; then
19+
echo "pr_number=" >> $GITHUB_OUTPUT
20+
elif [[ "$env" == pr* ]]; then
21+
echo "pr_number=${env#pr}" >> $GITHUB_OUTPUT
22+
else
23+
echo "pr_number=$env" >> $GITHUB_OUTPUT
24+
fi
25+
26+
- name: Determine if proxy has been deployed
27+
id: check_proxy_deployed
28+
env:
29+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
30+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
31+
shell: bash
32+
run: |
33+
if [[ -z "$PR_NUMBER" ]]; then
34+
echo "No pull request detected; proxy was deployed."
35+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
36+
exit 0
37+
fi
38+
39+
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
40+
41+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
42+
echo "Labels on PR #$PR_NUMBER: $labels"
43+
44+
if echo "$labels" | grep -Fxq 'deploy-proxy'; then
45+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
46+
else
47+
echo "proxy_deployed=false" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Repo setup
51+
if: ${{ steps.check_proxy_deployed.outputs.proxy_deployed == 'true' }}
52+
uses: ./.github/actions/node-install
53+
with:
54+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
55+
56+
- name: Install poetry and e2e test dependencies
57+
shell: bash
58+
run: |
59+
pipx install poetry
60+
cd tests/e2e-tests && poetry install
61+
62+
- name: Run tests
63+
if: ${{ steps.check_proxy_deployed.outputs.proxy_deployed == 'true' }}
64+
shell: bash
65+
env:
66+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
67+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
68+
run: |
69+
echo "$SUPPLIER_API_PRIVATE_KEY" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
70+
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
71+
BASE_PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
72+
73+
export API_ENVIRONMENT=internal-dev
74+
if [[ -z "$PR_NUMBER" ]]; then
75+
export PROXY_NAME="${BASE_PROXY_NAME}"
76+
export NON_PROD_API_KEY="${SUPPLIER_API_APIM_API_KEY}"
77+
else
78+
export PROXY_NAME="${BASE_PROXY_NAME}-PR-${PR_NUMBER}"
79+
export NON_PROD_API_KEY="${SUPPLIER_API_APIM_PR_API_KEY}"
80+
fi
81+
82+
export STATUS_ENDPOINT_API_KEY="${SUPPLIER_API_APIM_STATUS_API_KEY}"
83+
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
84+
make .internal-dev-test

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,17 @@ 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"
38-
uses: ./.github/actions/node-install
27+
- name: Run component tests
28+
if: ${{ inputs.testType != 'e2e' }}
29+
uses: ./.github/actions/acceptance-tests-component
3930
with:
40-
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
31+
testType: ${{ inputs.testType }}
32+
targetEnvironment: ${{ inputs.targetEnvironment }}
33+
targetComponent: ${{ inputs.targetComponent }}
4134

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 }}
35+
- name: Run e2e tests
36+
if: ${{ inputs.testType == 'e2e' && inputs.targetEnvironment == 'main' }}
37+
uses: ./.github/actions/acceptance-tests-e2e
38+
with:
39+
targetEnvironment: ${{ inputs.targetEnvironment }}

.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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

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

Lines changed: 32 additions & 5 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:
@@ -165,8 +192,8 @@ jobs:
165192
artefact-proxies:
166193
name: "Build proxies"
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: "${{ inputs.pr_number == '' && 'internal-dev' || '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: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,5 @@ jobs:
8080
--overrideProjectName "nhs" \
8181
--targetEnvironment "$ENVIRONMENT" \
8282
--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"
83+
--targetComponent "api" \
84+
--extraSecretNames '["SUPPLIER_API_PRIVATE_KEY","SUPPLIER_API_APIM_API_KEY","SUPPLIER_API_APIM_PR_API_KEY", "SUPPLIER_API_APIM_STATUS_API_KEY"]'

.gitleaksignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ debc75a97cfe551a69fd1e8694be483213322a9d:pact-contracts/pacts/letter-rendering/s
2525
4fa1923947bbff2387218d698d766cbb7c121a0f:pact-contracts/pacts/letter-rendering/supplier-api-letter-request-prepared.json:generic-api-key:10
2626
d005112adcfd286c3bef076214836dbb2fe8d0b5:.npmrc:npm-access-token:9
2727
d005112adcfd286c3bef076214836dbb2fe8d0b5:.npmrc:github-pat:7
28+
ff889d4c3f29da4468ecf1f05f467fe84d35b2a1:lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js.map:ipv4:4
29+
ff889d4c3f29da4468ecf1f05f467fe84d35b2a1:lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js:ipv4:63
30+
ff889d4c3f29da4468ecf1f05f467fe84d35b2a1:lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js:ipv4:62
31+
ff889d4c3f29da4468ecf1f05f467fe84d35b2a1:lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js:ipv4:60
32+
ff889d4c3f29da4468ecf1f05f467fe84d35b2a1:lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js:ipv4:59
33+
ff889d4c3f29da4468ecf1f05f467fe84d35b2a1:lambdas/supplier-mock/.aws-sam/build/SupplierMockFunction/index.js:ipv4:24

0 commit comments

Comments
 (0)