@@ -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