Skip to content

Commit 2c17421

Browse files
test-suite
1 parent f8700c4 commit 2c17421

10 files changed

Lines changed: 1220 additions & 1151 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Run test suite"
2+
description: |
3+
Composite action that runs a single test type (unit/contract/schema/integration/acceptance),
4+
uploads the test artefacts, and publishes a JUnit summary to the GitHub Actions job.
5+
Delegates to `make test-<type>` which invokes scripts/tests/run-test.sh.
6+
For remote tests, pass apigee-access-token to authenticate with the APIM proxy.
7+
8+
inputs:
9+
test-type:
10+
description: "Test type: unit, contract, schema, integration, acceptance"
11+
required: true
12+
apigee-access-token:
13+
description: "Apigee access token (if needed)"
14+
required: false
15+
default: ""
16+
env:
17+
description: "Environment: local or remote"
18+
required: false
19+
default: "remote"
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: "Run ${{ inputs.test-type }} tests"
25+
shell: bash
26+
env:
27+
APIGEE_ACCESS_TOKEN: ${{ inputs.apigee-access-token }}
28+
ENV: ${{ inputs.env }}
29+
run: |
30+
if [[ -n "${APIGEE_ACCESS_TOKEN}" ]]; then
31+
echo "::add-mask::${APIGEE_ACCESS_TOKEN}"
32+
fi
33+
make test-${{ inputs.test-type }}
34+
35+
- name: "Upload ${{ inputs.test-type }} test results"
36+
if: always()
37+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
38+
with:
39+
name: ${{ inputs.test-type }}-test-results
40+
path: gateway_api/test-artefacts/
41+
retention-days: 30
42+
43+
- name: "Check ${{ inputs.test-type }}-tests.xml exists"
44+
id: check
45+
if: always()
46+
shell: bash
47+
run: |
48+
if [[ -f "gateway_api/test-artefacts/${{ inputs.test-type }}-tests.xml" ]]; then
49+
echo "exists=true" >> "$GITHUB_OUTPUT"
50+
else
51+
echo "exists=false" >> "$GITHUB_OUTPUT"
52+
fi
53+
54+
- name: "Publish ${{ inputs.test-type }} test results to summary"
55+
if: ${{ always() && steps.check.outputs.exists == 'true' }}
56+
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
57+
with:
58+
paths: gateway_api/test-artefacts/${{ inputs.test-type }}-tests.xml

.github/actions/setup-python-project/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ inputs:
77
runs:
88
using: "composite"
99
steps:
10+
- name: "Install system dependencies"
11+
shell: bash
12+
run: |
13+
sudo apt-get update
14+
sudo apt-get install -y libxml2-dev libxslt-dev
1015
- name: "Set up Python"
1116
uses: actions/setup-python@v5
1217
with:

.github/workflows/preview-env.yml

Lines changed: 40 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ env:
1010
ECR_REPOSITORY_NAME: "whoami"
1111
TF_STATE_BUCKET: "cds-cdg-dev-tfstate-900119715266"
1212
PREVIEW_STATE_PREFIX: "dev/preview/"
13+
BASE_URL: 'https://internal-dev.api.service.nhs.uk/${{ vars.PROXYGEN_API_NAME }}-pr-${{ github.event.pull_request.number }}'
14+
ENV: "remote"
1315
python_version: "3.14"
1416

1517
jobs:
@@ -293,151 +295,62 @@ jobs:
293295
294296
# ---------- QUALITY CHECKS (Test Suites) ----------
295297

296-
# UNIT TESTS
297-
- name: Run unit tests
298-
if: github.event.action != 'closed'
299-
run: make test-unit
300-
301-
- name: Upload unit test results
302-
if: always()
303-
uses: actions/upload-artifact@v7
304-
with:
305-
name: unit-test-results
306-
path: gateway-api/test-artefacts/unit-tests*
307-
retention-days: 30
308-
309-
- name: Check unit-tests.xml exists
310-
id: check-unit
311-
if: always()
298+
- name: Retrieve Apigee Token
299+
id: apigee-token
300+
shell: bash
312301
run: |
313-
[ -f "gateway-api/test-artefacts/unit-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
302+
set -euo pipefail
314303
315-
- name: Publish unit test results to summary
316-
if: ${{ always() && steps.check-unit.outputs.exists == 'true' }}
317-
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
318-
with:
319-
paths: gateway-api/test-artefacts/unit-tests.xml
320-
321-
# CONTRACT TESTS
322-
- name: Run contract tests against preview
323-
if: github.event.action != 'closed'
324-
env:
325-
BASE_URL: ${{ steps.tf-output.outputs.preview_url }}
326-
MTLS_CERT: /tmp/client1-cert.pem
327-
MTLS_KEY: /tmp/client1-key.pem
328-
run: make test-contract
329-
330-
- name: Upload contract test results
331-
if: always()
332-
uses: actions/upload-artifact@v7
333-
with:
334-
name: contract-test-results
335-
path: gateway-api/test-artefacts/contract-tests*
336-
retention-days: 30
304+
APIGEE_TOKEN="$(proxygen pytest-nhsd-apim get-token | jq -r '.pytest_nhsd_apim_token' 2>/dev/null)"
305+
if [ -z "$APIGEE_TOKEN" ] || [ "$APIGEE_TOKEN" = "null" ]; then
306+
echo "::error::Failed to retrieve Apigee token"
307+
exit 1
308+
fi
337309
338-
- name: Check contract-tests.xml exists
339-
id: check-contract
340-
if: always()
341-
run: |
342-
[ -f "gateway-api/test-artefacts/contract-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
310+
echo "::add-mask::$APIGEE_TOKEN"
311+
printf 'apigee-access-token=%s\n' "$APIGEE_TOKEN" >> "$GITHUB_OUTPUT"
312+
echo "Token retrieved successfully (length: ${#APIGEE_TOKEN})"
343313
344-
- name: Publish contract test results to summary
345-
if: ${{ always() && steps.check-contract.outputs.exists == 'true' }}
346-
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
314+
- name: "Create coverage artefact name"
315+
id: create-name
316+
uses: ./.github/actions/create-artefact-name
347317
with:
348-
paths: gateway-api/test-artefacts/contract-tests.xml
318+
prefix: coverage
349319

350-
# SCHEMA TESTS
351-
- name: Run schema validation against preview
320+
- name: "Run unit tests"
352321
if: github.event.action != 'closed'
353-
env:
354-
BASE_URL: ${{ steps.tf-output.outputs.preview_url }}
355-
MTLS_CERT: /tmp/client1-cert.pem
356-
MTLS_KEY: /tmp/client1-key.pem
357-
run: make test-schema
358-
359-
- name: Upload schema test results
360-
if: always()
361-
uses: actions/upload-artifact@v7
362-
with:
363-
name: schema-test-results
364-
path: gateway-api/test-artefacts/schema-tests*
365-
retention-days: 30
366-
367-
- name: Check schema-tests.xml exists
368-
id: check-schema
369-
if: always()
370-
run: |
371-
[ -f "gateway-api/test-artefacts/schema-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
372-
373-
- name: Publish schema test results to summary
374-
if: ${{ always() && steps.check-schema.outputs.exists == 'true' }}
375-
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
322+
uses: ./.github/actions/run-test-suite
376323
with:
377-
paths: gateway-api/test-artefacts/schema-tests.xml
324+
test-type: unit
325+
env: local
378326

379-
# INTEGRATION TESTS
380-
- name: Run integration tests against preview using remote APIM proxy
327+
- name: "Run contract tests"
381328
if: github.event.action != 'closed'
382-
env:
383-
BASE_URL: "https://internal-dev.api.service.nhs.uk/clinical-data-gateway-api-poc"
384-
PR_NUMBER: ${{ github.event.pull_request.number }}
385-
PROXYGEN_KEY_ID: ${{ vars.PREVIEW_ENV_PROXYGEN_KEY_ID }}
386-
PROXYGEN_CLIENT_ID: ${{ vars.PREVIEW_ENV_PROXYGEN_CLIENT_ID }}
387-
PROXYGEN_KEY_SECRET: ${{ env._cds_gateway_dev_proxygen_proxygen_key_secret }}
388-
MTLS_CERT: /tmp/client1-cert.pem
389-
MTLS_KEY: /tmp/client1-key.pem
390-
run: |
391-
make test-integration
392-
393-
- name: Upload integration test results
394-
if: always()
395-
uses: actions/upload-artifact@v7
329+
uses: ./.github/actions/run-test-suite
396330
with:
397-
name: integration-test-results
398-
path: gateway-api/test-artefacts/integration-tests*
399-
retention-days: 30
331+
test-type: contract
332+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
400333

401-
- name: Check integration-tests.xml exists
402-
id: check-integration
403-
if: always()
404-
run: |
405-
[ -f "gateway-api/test-artefacts/integration-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
406-
407-
- name: Publish integration test results to summary
408-
if: ${{ always() && steps.check-integration.outputs.exists == 'true' }}
409-
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
334+
- name: "Run schema validation tests"
335+
if: github.event.action != 'closed'
336+
uses: ./.github/actions/run-test-suite
410337
with:
411-
paths: gateway-api/test-artefacts/integration-tests.xml
338+
test-type: schema
339+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
412340

413-
# ACCEPTANCE TESTS
414-
- name: Run acceptance tests against preview
341+
- name: "Run integration tests"
415342
if: github.event.action != 'closed'
416-
env:
417-
BASE_URL: ${{ steps.tf-output.outputs.preview_url }}
418-
MTLS_CERT: /tmp/client1-cert.pem
419-
MTLS_KEY: /tmp/client1-key.pem
420-
run: make test-acceptance
421-
422-
- name: Upload acceptance test results
423-
if: always()
424-
uses: actions/upload-artifact@v7
343+
uses: ./.github/actions/run-test-suite
425344
with:
426-
name: acceptance-test-results
427-
path: gateway-api/test-artefacts/acceptance-tests*
428-
retention-days: 30
345+
test-type: integration
346+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
429347

430-
- name: Check acceptance-tests.xml exists
431-
id: check-acceptance
432-
if: always()
433-
run: |
434-
[ -f "gateway-api/test-artefacts/acceptance-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
435-
436-
- name: Publish acceptance test results to summary
437-
if: ${{ always() && steps.check-acceptance.outputs.exists == 'true' }}
438-
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
348+
- name: "Run acceptance tests"
349+
if: github.event.action != 'closed'
350+
uses: ./.github/actions/run-test-suite
439351
with:
440-
paths: gateway-api/test-artefacts/acceptance-tests.xml
352+
test-type: acceptance
353+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
441354

442355
# Cleanup after tests
443356
- name: Remove mTLS temp files

0 commit comments

Comments
 (0)