From 532e4c7082a7a4169274ab085c3e45853da925d4 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Fri, 27 Oct 2023 13:53:56 +0100 Subject: [PATCH] PI-1513 Re-usable workflow for running e2e tests (#2454) --- .../render-project-template/action.yml | 1 - .github/workflows/bootstrap.yml | 48 +++- .github/workflows/cleanup.yml | 8 - .github/workflows/end-to-end-tests.yml | 232 ------------------ .github/workflows/pipeline.yml | 5 +- 5 files changed, 38 insertions(+), 256 deletions(-) delete mode 100644 .github/workflows/end-to-end-tests.yml diff --git a/.github/actions/render-project-template/action.yml b/.github/actions/render-project-template/action.yml index 87d1ffc832..9882874043 100644 --- a/.github/actions/render-project-template/action.yml +++ b/.github/actions/render-project-template/action.yml @@ -31,7 +31,6 @@ runs: sed -i '/add new projects here/i \ - '"'"'["${{ inputs.project_name }}"]'"'"'' .github/workflows/access.yml sed -i '/add new projects here/i \ - '"'"'["${{ inputs.project_name }}"]'"'"'' .github/workflows/deploy.yml sed -i '/add new projects here/i \ - '"'"'["${{ inputs.project_name }}"]'"'"'' .github/workflows/docs.yml - sed -i '/add new projects here/i \ - '"'"'["${{ inputs.project_name }}"]'"'"'' .github/workflows/end-to-end-tests.yml sed -i '/add new projects here/i \ - ${{ inputs.project_name }}' .github/workflows/suppress-trivy.yml sed -i '/add new projects here/i \ - ${{ inputs.project_name }}' .github/workflows/build.yml sed -i '/add new projects here/i \* [${{ steps.project_name.outputs.title_case }}](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/${{ inputs.project_name }})' doc/tech-docs/source/index.html.md.erb diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index cc8492572e..96253522cd 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -97,11 +97,33 @@ jobs: passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} token: ${{ secrets.BOT_GITHUB_TOKEN }} + - uses: actions/checkout@v4 + with: + path: hmpps-probation-integration-e2e-tests + repository: ministryofjustice/hmpps-probation-integration-e2e-tests + token: ${{ secrets.BOT_GITHUB_TOKEN }} + + - name: Update e2e test repo + run: sed -i '/add new projects here/i \ - '"'"'["${{ inputs.project_name }}"]'"'"'' hmpps-probation-integration-e2e-tests/.github/workflows/end-to-end-tests.yml + + - name: Create pull request + id: e2e-pr + uses: ./.github/actions/create-signed-pull-request + with: + path: hmpps-probation-integration-e2e-tests + add-paths: .github/workflows + branch: ${{ inputs.issue_number }}-create-${{ inputs.project_name }}-project + commit-message: ${{ inputs.issue_number }} Add option to run tests for ${{ inputs.project_name }} + private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} + token: ${{ secrets.BOT_GITHUB_TOKEN }} + - name: Create issue for manual steps run: | gh issue create \ --title "${{ inputs.issue_number }} Complete project setup for ${{ inputs.project_name }}" \ - --body "- [ ] Merge pull request: ${{ steps.pr.outputs.pull-request-url }}" \ + --body "- [ ] Merge project pull request: ${{ steps.pr.outputs.pull-request-url }}" \ + --body "- [ ] Merge e2e tests pull request: ${{ steps.e2e-pr.outputs.pull-request-url }}" \ --label bootstrap env: GITHUB_TOKEN: ${{ github.token }} @@ -219,19 +241,19 @@ jobs: with: path: cloud-platform-environments-dev repository: ministryofjustice/cloud-platform-environments - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - uses: actions/checkout@v4 with: path: cloud-platform-environments-preprod repository: ministryofjustice/cloud-platform-environments - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - uses: actions/checkout@v4 with: path: cloud-platform-environments-prod repository: ministryofjustice/cloud-platform-environments - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Render Terraform queue template run: | @@ -258,7 +280,7 @@ jobs: commit-message: ${{ inputs.issue_number }} Create SQS queues for ${{ inputs.project_name }} (dev) private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Create preprod pull request id: preprod-pr @@ -270,7 +292,7 @@ jobs: commit-message: ${{ inputs.issue_number }} Create SQS queues for ${{ inputs.project_name }} (preprod) private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Create prod pull request id: prod-pr @@ -282,7 +304,7 @@ jobs: commit-message: ${{ inputs.issue_number }} Create SQS queues for ${{ inputs.project_name }} (prod) private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Create issue for manual steps run: | @@ -316,19 +338,19 @@ jobs: with: path: cloud-platform-environments-dev repository: ministryofjustice/cloud-platform-environments - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - uses: actions/checkout@v4 with: path: cloud-platform-environments-preprod repository: ministryofjustice/cloud-platform-environments - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - uses: actions/checkout@v4 with: path: cloud-platform-environments-prod repository: ministryofjustice/cloud-platform-environments - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Add Pingdom check run: sed -i '/add new projects here/i \ "${{ inputs.project_name }}",' 'cloud-platform-environments-prod/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-probation-integration-services-prod/resources/pingdom.tf' @@ -349,7 +371,7 @@ jobs: commit-message: ${{ inputs.issue_number }} Create certificate for ${{ inputs.project_name }} (dev) private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Create preprod pull request id: preprod-pr @@ -361,7 +383,7 @@ jobs: commit-message: ${{ inputs.issue_number }} Create certificate for ${{ inputs.project_name }} (preprod) private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Create prod pull request id: prod-pr @@ -373,7 +395,7 @@ jobs: commit-message: ${{ inputs.issue_number }} Create Pingdom check and certificate for ${{ inputs.project_name }} (prod) private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} - token: ${{ secrets.BOT_GITHUB_TOKEN }} + token: ${{ secrets.BOT_GITHUB_EXTERNAL_REPOS_TOKEN }} - name: Create issue for manual steps run: | diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml index 328870009d..072dbc915e 100644 --- a/.github/workflows/cleanup.yml +++ b/.github/workflows/cleanup.yml @@ -47,14 +47,6 @@ jobs: --path 'tech-docs' \ --path 'tech-docs-drafts' \ --path 'schema-spy-report' \ - --path "playwright-report/test/main/$(date -d '-7 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date -d '-6 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date -d '-5 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date -d '-4 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date -d '-3 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date -d '-2 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date -d '-1 days' '+%Y-%m-%d')" \ - --path "playwright-report/test/main/$(date '+%Y-%m-%d')" \ --refs gh-pages \ --force git gc --prune=now diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml deleted file mode 100644 index 5fab870519..0000000000 --- a/.github/workflows/end-to-end-tests.yml +++ /dev/null @@ -1,232 +0,0 @@ -name: End-to-end tests - -on: - schedule: - - cron: "0 8 * * MON-FRI" # Every weekday at 08:00 UTC - workflow_call: - inputs: - test-branch: - description: The branch to run in the e2e repo - default: main - type: string - required: false - projects: - description: A JSON array of projects to deploy - type: string - required: true - outputs: - failed-projects: - description: The projects that failed end-to-end testing - value: ${{ jobs.test.outputs.failed-projects }} - passed-projects: - description: The projects that passed end-to-end testing - value: ${{ jobs.test.outputs.passed-projects }} - report-url: - description: The URL of the Playwright HTML report - value: ${{ jobs.test.outputs.report-url }} - workflow_dispatch: - inputs: - test-branch: - description: Test branch - default: main - type: string - required: true - projects: - description: Project - type: choice - required: true - options: - - 'All' - - '["approved-premises-and-delius"]' - - '["approved-premises-and-oasys"]' - - '["court-case-and-delius"]' - - '["create-and-vary-a-licence-and-delius"]' - - '["custody-key-dates-and-delius"]' - - '["domain-events-and-delius"]' - - '["effective-proposal-framework-and-delius"]' - - '["external-api-and-delius"]' - - '["make-recall-decisions-and-delius"]' - - '["manage-pom-cases-and-delius"]' - - '["offender-events-and-delius"]' - - '["pathfinder-and-delius"]' - - '["person-search-index-from-delius"]' - - '["pre-sentence-reports-to-delius"]' - - '["prison-case-notes-to-probation"]' - - '["prison-custody-status-to-delius"]' - - '["refer-and-monitor-and-delius"]' - - '["risk-assessment-scores-to-delius"]' - - '["sentence-plan-and-delius"]' - - '["sentence-plan-and-oasys"]' - - '["soc-and-delius"]' - - '["tier-to-delius"]' - - '["unpaid-work-and-delius"]' - - '["workforce-allocations-to-delius"]' - - '["manage-offences-and-delius"]' - - '["resettlement-passport-and-delius"]' - - '["prison-education-and-delius"]' - - '["opd-and-delius"]' - - '["hmpps-auth-and-delius"]' - - '["dps-and-delius"]' - - '["arns-and-delius"]' - - '["cas3-and-delius"]' - # ^ add new projects here - # GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments - # See https://github.com/community/community/discussions/11795 -env: - auto_pass_projects: '["manage-offences-and-delius"]' - -jobs: - test: - runs-on: moj-cloud-platform - timeout-minutes: 60 - outputs: - failed-projects: ${{ steps.json.outputs.failed-projects }} - passed-projects: ${{ steps.json.outputs.passed-projects }} - report-url: ${{ steps.html.outputs.report-url }} - steps: - - uses: actions/checkout@v3 - with: - repository: ministryofjustice/hmpps-probation-integration-e2e-tests - ref: ${{ inputs.test-branch }} - - name: Get tests to run - all tests - if: inputs.projects == '' || inputs.projects == 'All' - run: echo "projects=$(find projects -mindepth 1 -maxdepth 1 -printf "%f\n" | jq --raw-input . | jq --slurp --compact-output .)" | tee -a "$GITHUB_ENV" - - name: Get tests to run - specific tests - if: inputs.projects != '' && inputs.projects != 'All' - run: echo 'projects=${{ inputs.projects }}' | tee -a "$GITHUB_ENV" - - name: Get report output directory - run: echo "report-dir=playwright-report/test/$REF/$(date '+%Y-%m-%d')/${{ github.sha }}/${{ github.run_id }}/${{ github.run_attempt }}" | tee -a "$GITHUB_ENV" - env: - REF: ${{ github.ref_name }} - - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: npm - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install - - name: Run Playwright tests - id: tests - run: echo '${{ env.projects }}' | jq -r '.[]' | xargs npx playwright test --reporter=html,junit,json,line --workers=16 - env: - TZ: Europe/London - ENV: test - DELIUS_URL: https://ndelius.test.probation.service.justice.gov.uk - WORKFORCE_URL: https://workforce-management-dev.hmpps.service.justice.gov.uk - DPS_URL: https://digital-dev.prison.service.justice.gov.uk - AUTH_URL: https://sign-in-dev.hmpps.service.justice.gov.uk - PRISON_API: https://prison-api-dev.prison.service.justice.gov.uk - EPF_API: https://effective-proposal-framework-and-delius-dev.hmpps.service.justice.gov.uk - EXTERNAL_API: https://external-api-and-delius-dev.hmpps.service.justice.gov.uk - REFERANDMONITOR_URL: https://hmpps-interventions-ui-dev.apps.live-1.cloud-platform.service.justice.gov.uk - OASYS_URL: https://t2.oasys.service.justice.gov.uk/eor/f?p=100:101 - APPROVEDPREMISES_URL: https://approved-premises-dev.hmpps.service.justice.gov.uk - CONSIDER_A_RECALL_URL: https://consider-a-recall-dev.hmpps.service.justice.gov.uk - MANAGE_POM_CASES_URL: https://dev.moic.service.justice.gov.uk - DELIUS_USERNAME: ${{ secrets.E2E_DELIUS_USERNAME }} - DELIUS_PASSWORD: ${{ secrets.E2E_DELIUS_PASSWORD }} - DPS_USERNAME: ${{ secrets.E2E_DPS_USERNAME }} - DPS_PASSWORD: ${{ secrets.E2E_DPS_PASSWORD }} - CRED_USERNAME: ${{ secrets.E2E_CLIENT_ID }} - CRED_PASSWORD: ${{ secrets.E2E_CLIENT_SECRET }} - REFERANDMONITOR_SUPPLIER_USERNAME: ${{ secrets.E2E_REFERANDMONITOR_SUPPLIER_USERNAME }} - REFERANDMONITOR_SUPPLIER_PASSWORD: ${{ secrets.E2E_REFERANDMONITOR_SUPPLIER_PASSWORD }} - RESETTLEMENT_PASSPORT_AND_DELIUS_API: https://resettlement-passport-and-delius-dev.hmpps.service.justice.gov.uk - OASYS_USERNAME_BOOKING: ${{ secrets.E2E_OASYS_USERNAME_BOOKING }} - OASYS_PASSWORD_BOOKING: ${{ secrets.E2E_OASYS_PASSWORD_BOOKING }} - OASYS_USERNAME_RSR: ${{ secrets.E2E_OASYS_USERNAME_RSR }} - OASYS_PASSWORD_RSR: ${{ secrets.E2E_OASYS_PASSWORD_RSR }} - OASYS_USERNAME_TIMELINE: ${{ secrets.E2E_OASYS_USERNAME_TIMELINE }} - OASYS_PASSWORD_TIMELINE: ${{ secrets.E2E_OASYS_PASSWORD_TIMELINE }} - APPROVEDPREMISES_USERNAME: ${{ secrets.E2E_DELIUS_USERNAME }} - APPROVEDPREMISES_PASSWORD: ${{ secrets.E2E_DELIUS_PASSWORD }} - CONSIDER_A_RECALL_MRD_USERNAME: ${{ secrets.E2E_CONSIDER_RECALL_MRD_USERNAME }} - CONSIDER_A_RECALL_MRD_PASSWORD: ${{ secrets.E2E_CONSIDER_RECALL_MRD_PASSWORD }} - CONSIDER_RECALL_MRD_PASSWORD: ${{ secrets.E2E_CONSIDER_RECALL_MRD_PASSWORD }} - PLAYWRIGHT_JUNIT_OUTPUT_NAME: junit.xml - PLAYWRIGHT_JSON_OUTPUT_NAME: results.json - - name: Parse JSON results - if: always() - id: json - run: | - if [ -f results.json ]; then - skipped_projects=$(echo "$all_projects" | jq -r '.[]' | while read -r project; do if [ ! -d "tests/$project" ]; then echo $project; fi; done | jq --raw-input . | jq --slurp --compact-output .) - failed_projects=$(jq -r '.suites[].specs[] | select(.ok == false).file' results.json | xargs -n1 dirname | sort -u | jq --raw-input . | jq --slurp --compact-output .) - passed_projects=$(jq --compact-output --null-input --argjson all "$all_projects" --argjson failed "$failed_projects" --argjson skipped "$skipped_projects" '{all: $all, failed: $failed, skipped: $skipped} | .all - .failed - .skipped') - merged=$(echo "$auto_pass_projects $passed_projects" | jq -s 'add') - passed_projects=$(echo "$merged $projects" | jq -sc '.[0] - (.[0] - .[1])') - fi - echo "skipped-projects=${skipped_projects:-'[]'}" | tee -a "$GITHUB_OUTPUT" - echo "failed-projects=${failed_projects:-'[]'}" | tee -a "$GITHUB_OUTPUT" - echo "passed-projects=${passed_projects:-'[]'}" | tee -a "$GITHUB_OUTPUT" - env: - all_projects: ${{ env.projects }} - - name: Publish JUnit report - if: always() - uses: mikepenz/action-junit-report@0a8a5ba57593d67b2e45de2c543b438412382b7b # v4.0.1 - id: junit - with: - check_name: End-to-end test results - report_paths: junit.xml - - name: Publish HTML report - if: always() - uses: JamesIves/github-pages-deploy-action@22a6ee251d6f13c6ab1ecb200d974f1a6feb1b8d # v4 - with: - folder: playwright-report - target-folder: ${{ env.report-dir }} - - name: Output HTML report URL - id: html - if: always() - run: | - echo '[🎭 Playwright HTML Report](https://ministryofjustice.github.io/hmpps-probation-integration-services/${{ env.report-dir }})' | tee -a "$GITHUB_STEP_SUMMARY" - echo 'report-url=https://ministryofjustice.github.io/hmpps-probation-integration-services/${{ env.report-dir }}' | tee -a "$GITHUB_OUTPUT" - - name: Send message to Slack - uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0 - if: ${{ failure() && github.event_name == 'schedule' }} - with: - channel-id: probation-integration-notifications - payload: | - { - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "🎭 *Probation Integration Services* end-to-end test failure" - } - }, - { - "type": "context", - "elements": [ - { - "type": "mrkdwn", - "text": ">${{ steps.junit.outputs.total }} tests run, ${{ steps.junit.outputs.passed }} passed, ${{ steps.junit.outputs.skipped }} skipped, ${{ steps.junit.outputs.failed }} failed." - } - ] - }, - { - "type": "actions", - "elements": [ - { - "type": "button", - "text": { - "type": "plain_text", - "text": "📈 Report" - }, - "url": "https://ministryofjustice.github.io/hmpps-probation-integration-services/${{ env.report-dir }}" - }, - { - "type": "button", - "text": { - "type": "plain_text", - "text": "📝 Logs" - }, - "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" - } - ] - } - ] - } - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index e8cf92f77b..08dbf36bde 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -67,14 +67,15 @@ jobs: end-to-end-tests: name: Run end-to-end tests - uses: ./.github/workflows/end-to-end-tests.yml + uses: ministryofjustice/hmpps-probation-integration-e2e-tests/.github/workflows/test-remote.yml@main needs: - post-build - deploy-to-test - deploy-to-preprod with: projects: ${{ needs.post-build.outputs.changes }} - secrets: inherit + secrets: + token: ${{ secrets.BOT_GITHUB_TOKEN }} report-test-failures: name: Failed testing