From b22e6fa5d69592ada3e3dc4cc16643ef4ab2aded Mon Sep 17 00:00:00 2001 From: Ash Davies <3853061+DrizzlyOwl@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:50:25 +0000 Subject: [PATCH] Combine reports into single artifact (cypress workflow) --- .github/workflows/cypress.yml | 111 +++++++++++++++++----------------- 1 file changed, 54 insertions(+), 57 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 7d5b4001a..fe2559d47 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -39,6 +39,15 @@ jobs: browser: [ "edge" ] + project: [ + "conversions", + "transfers" + ] + include: + - project: "transfers" + working_dir: "./Dfe.PrepareConversions/Dfe.PrepareTransfers.CypressTests" + - project: "conversions" + working_dir: "./Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests" container: image: cypress/browsers:22.12.0 steps: @@ -46,13 +55,17 @@ jobs: with: ref: ${{ github.ref }} - # Step 1: Install Cypress for Transfers Tests - - name: Install Cypress for Transfers - run: npm install cypress - working-directory: ./Dfe.PrepareConversions/Dfe.PrepareTransfers.CypressTests + - run: | + INPUT=${{ github.event.inputs.environment }} + ENVIRONMENT=${INPUT:-"development"} + if [[ $ENVIRONMENT == 'development' ]] + then + echo "GREP=-dao" >> $GITHUB_ENV + else + echo "GREP=" >> $GITHUB_ENV + fi - - name: Run Transfers Tests (${{ inputs.environment }}) - if: inputs.environment == 'staging' || inputs.environment == 'dev' + - name: Run (${{ inputs.environment }}) uses: cypress-io/github-action@v6 env: CYPRESS_db: ${{ secrets.DB_CONNECTION_STRING }} @@ -60,79 +73,63 @@ jobs: CYPRESS_cypressTestSecret: ${{ secrets.CYPRESS_TEST_SECRET }} CYPRESS_academisationApiUrl: ${{ secrets.CYPRESS_ACADEMISATION_API_URL }} CYPRESS_academisationApiKey: ${{ secrets.CYPRESS_ACADEMISATION_API_KEY }} + CYPRESS_grep: ${{ env.GREP }} with: - browser: edge - working-directory: ./Dfe.PrepareConversions/Dfe.PrepareTransfers.CypressTests + browser: ${{ matrix.browser }} + working-directory: ${{ matrix.working_dir }} wait-on: ${{ secrets.AZURE_ENDPOINT }} - install: false - - name: Upload screenshots (Transfers) + - name: Upload screenshots if: ${{ failure() }} uses: actions/upload-artifact@v4 with: - name: screenshots-transfers-${{ inputs.environment }}-${{ matrix.browser }} - path: Dfe.PrepareConversions/Dfe.PrepareTransfers.CypressTests/cypress/screenshots + name: screenshots-${{ matrix.project }}-${{ inputs.environment }}-${{ matrix.browser }} + path: ${{ matrix.working_dir }}/cypress/screenshots - # Step 2: Install Cypress for Conversions Tests - - name: Install Cypress for Conversions - run: npm install cypress - working-directory: ./Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests + - name: Upload reports + if: ${{ always() }} + uses: actions/upload-artifact@v4 + with: + name: reports-${{ inputs.environment }}-${{ matrix.project }}-${{ matrix.browser }} + path: ${{ matrix.working_dir }}/cypress/reports - - name: Run Conversions (dev) - if: inputs.environment == 'dev' - uses: cypress-io/github-action@v6 - env: - CYPRESS_db: ${{ secrets.DB_CONNECTION_STRING }} - CYPRESS_url: ${{ secrets.AZURE_ENDPOINT }} - CYPRESS_cypressTestSecret: ${{ secrets.CYPRESS_TEST_SECRET }} - CYPRESS_academisationApiUrl: ${{ secrets.CYPRESS_ACADEMISATION_API_URL }} - CYPRESS_academisationApiKey: ${{ secrets.CYPRESS_ACADEMISATION_API_KEY }} + build-reports: + name: Build combined reports + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + needs: cypress-tests + env: + working_dir: "./Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests" + steps: + - uses: actions/checkout@v4 with: - browser: ${{ matrix.browser }} - working-directory: ./Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests - wait-on: ${{ secrets.AZURE_ENDPOINT }} - install: false + ref: ${{ github.ref }} - - name: Run Conversions (staging) - if: inputs.environment == 'staging' - uses: cypress-io/github-action@v6 - env: - CYPRESS_db: ${{ secrets.DB_CONNECTION_STRING }} - CYPRESS_url: ${{ secrets.AZURE_ENDPOINT }} - CYPRESS_cypressTestSecret: ${{ secrets.CYPRESS_TEST_SECRET }} - CYPRESS_academisationApiUrl: ${{ secrets.CYPRESS_ACADEMISATION_API_URL }} - CYPRESS_academisationApiKey: ${{ secrets.CYPRESS_ACADEMISATION_API_KEY }} - CYPRESS_grep: '-dao' + - uses: actions/setup-node@v4 with: - browser: ${{ matrix.browser }} - working-directory: ./Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests - wait-on: ${{ secrets.AZURE_ENDPOINT }} - install: false + node-version: 20 - - name: Upload screenshots (Conversions) - if: ${{ failure() }} - uses: actions/upload-artifact@v4 + - run: npm ci + working-directory: ${{ env.working_dir }} + + - name: Download reports + uses: actions/download-artifact@v4 with: - name: screenshots-conversions-${{ inputs.environment }}-${{ matrix.browser }} - path: Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/screenshots + pattern: reports-${{ inputs.environment }}-* + path: ${{ env.working_dir }}/reports + merge-multiple: true - # Step 3: Generate Combined Report - name: Generate combined report - if: always() + working-directory: ${{ env.working_dir }} run: | mkdir mochareports - npm run generate:html:report --prefix Dfe.PrepareConversions/Dfe.PrepareTransfers.CypressTests - npm run generate:html:report --prefix Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests - mv Dfe.PrepareConversions/Dfe.PrepareTransfers.CypressTests/mochareports/*.html mochareports/ - mv Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/mochareports/*.html mochareports/ - echo "Combined reports generated" - npx mochawesome-merge mochareports/*.html > mochareports/combined-reports-${{ inputs.environment }}-${{ matrix.browser }}.html + npm run generate:html:report - name: Upload combined report if: always() uses: actions/upload-artifact@v4 with: - name: combined-reports-${{ inputs.environment }}-${{ matrix.browser }} + name: combined-reports-${{ inputs.environment }} path: mochareports - name: Report results to Slack