Skip to content

Commit 42cd8f8

Browse files
test-suite
1 parent bc44ce1 commit 42cd8f8

3 files changed

Lines changed: 101 additions & 127 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: pathology-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 "pathology-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: pathology-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: 38 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -293,151 +293,62 @@ jobs:
293293
294294
# ---------- QUALITY CHECKS (Test Suites) ----------
295295

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()
296+
- name: Retrieve Apigee Token
297+
id: apigee-token
298+
shell: bash
312299
run: |
313-
[ -f "gateway-api/test-artefacts/unit-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
300+
set -euo pipefail
314301
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
302+
APIGEE_TOKEN="$(proxygen pytest-nhsd-apim get-token | jq -r '.pytest_nhsd_apim_token' 2>/dev/null)"
303+
if [ -z "$APIGEE_TOKEN" ] || [ "$APIGEE_TOKEN" = "null" ]; then
304+
echo "::error::Failed to retrieve Apigee token"
305+
exit 1
306+
fi
337307
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"
308+
echo "::add-mask::$APIGEE_TOKEN"
309+
printf 'apigee-access-token=%s\n' "$APIGEE_TOKEN" >> "$GITHUB_OUTPUT"
310+
echo "Token retrieved successfully (length: ${#APIGEE_TOKEN})"
343311
344-
- name: Publish contract test results to summary
345-
if: ${{ always() && steps.check-contract.outputs.exists == 'true' }}
346-
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
312+
- name: "Create coverage artefact name"
313+
id: create-name
314+
uses: ./.github/actions/create-artefact-name
347315
with:
348-
paths: gateway-api/test-artefacts/contract-tests.xml
316+
prefix: coverage
349317

350-
# SCHEMA TESTS
351-
- name: Run schema validation against preview
318+
- name: "Run unit tests"
352319
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
320+
uses: ./.github/actions/run-test-suite
376321
with:
377-
paths: gateway-api/test-artefacts/schema-tests.xml
322+
test-type: unit
323+
env: local
378324

379-
# INTEGRATION TESTS
380-
- name: Run integration tests against preview using remote APIM proxy
325+
- name: "Run contract tests"
381326
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
327+
uses: ./.github/actions/run-test-suite
396328
with:
397-
name: integration-test-results
398-
path: gateway-api/test-artefacts/integration-tests*
399-
retention-days: 30
329+
test-type: contract
330+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
400331

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
332+
- name: "Run schema validation tests"
333+
if: github.event.action != 'closed'
334+
uses: ./.github/actions/run-test-suite
410335
with:
411-
paths: gateway-api/test-artefacts/integration-tests.xml
336+
test-type: schema
337+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
412338

413-
# ACCEPTANCE TESTS
414-
- name: Run acceptance tests against preview
339+
- name: "Run integration tests"
415340
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
341+
uses: ./.github/actions/run-test-suite
425342
with:
426-
name: acceptance-test-results
427-
path: gateway-api/test-artefacts/acceptance-tests*
428-
retention-days: 30
343+
test-type: integration
344+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
429345

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
346+
- name: "Run acceptance tests"
347+
if: github.event.action != 'closed'
348+
uses: ./.github/actions/run-test-suite
439349
with:
440-
paths: gateway-api/test-artefacts/acceptance-tests.xml
350+
test-type: acceptance
351+
apigee-access-token: ${{ steps.apigee-token.outputs.apigee-access-token }}
441352

442353
# Cleanup after tests
443354
- name: Remove mTLS temp files

0 commit comments

Comments
 (0)