|
10 | 10 | ECR_REPOSITORY_NAME: "whoami" |
11 | 11 | TF_STATE_BUCKET: "cds-cdg-dev-tfstate-900119715266" |
12 | 12 | 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" |
13 | 15 | python_version: "3.14" |
14 | 16 |
|
15 | 17 | jobs: |
@@ -293,151 +295,62 @@ jobs: |
293 | 295 |
|
294 | 296 | # ---------- QUALITY CHECKS (Test Suites) ---------- |
295 | 297 |
|
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 |
312 | 301 | run: | |
313 | | - [ -f "gateway-api/test-artefacts/unit-tests.xml" ] && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT" |
| 302 | + set -euo pipefail |
314 | 303 |
|
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 |
337 | 309 |
|
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})" |
343 | 313 |
|
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 |
347 | 317 | with: |
348 | | - paths: gateway-api/test-artefacts/contract-tests.xml |
| 318 | + prefix: coverage |
349 | 319 |
|
350 | | - # SCHEMA TESTS |
351 | | - - name: Run schema validation against preview |
| 320 | + - name: "Run unit tests" |
352 | 321 | 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 |
376 | 323 | with: |
377 | | - paths: gateway-api/test-artefacts/schema-tests.xml |
| 324 | + test-type: unit |
| 325 | + env: local |
378 | 326 |
|
379 | | - # INTEGRATION TESTS |
380 | | - - name: Run integration tests against preview using remote APIM proxy |
| 327 | + - name: "Run contract tests" |
381 | 328 | 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 |
396 | 330 | 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 }} |
400 | 333 |
|
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 |
410 | 337 | 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 }} |
412 | 340 |
|
413 | | - # ACCEPTANCE TESTS |
414 | | - - name: Run acceptance tests against preview |
| 341 | + - name: "Run integration tests" |
415 | 342 | 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 |
425 | 344 | 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 }} |
429 | 347 |
|
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 |
439 | 351 | 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 }} |
441 | 354 |
|
442 | 355 | # Cleanup after tests |
443 | 356 | - name: Remove mTLS temp files |
|
0 commit comments