From 234a985e7a9146e2b99e57c8c467cdeb87670e62 Mon Sep 17 00:00:00 2001 From: Adel Bensaad Date: Tue, 14 May 2024 07:22:44 +0100 Subject: [PATCH] chore: enhance parallel test execution setup in CI --- .github/workflows/dhis2-verify-app.yml | 15 +++++++++-- cypress/support/generateTestMatrix.js | 35 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 cypress/support/generateTestMatrix.js diff --git a/.github/workflows/dhis2-verify-app.yml b/.github/workflows/dhis2-verify-app.yml index aede8e66aa..6a08c9a796 100644 --- a/.github/workflows/dhis2-verify-app.yml +++ b/.github/workflows/dhis2-verify-app.yml @@ -21,6 +21,16 @@ env: D2_VERBOSE: true jobs: + setup-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.specs }} + steps: + - uses: actions/checkout@v3 + - name: Generate test matrix + id: set-matrix + run: echo "::set-output name=specs::$(node cypress/support/generateTestMatrix.js)" + build: runs-on: ubuntu-latest steps: @@ -83,10 +93,11 @@ jobs: call-workflow-e2e-prod: if: "!contains(github.event.head_commit.message, '[skip ci]')" - needs: [build, lint, test] - uses: dhis2/workflows/.github/workflows/analytics-e2e-tests-prod.yml@master + needs: [build, lint, test, setup-matrix] + uses: dhis2/workflows/.github/workflows/analytics-e2e-tests-prod.yml@update-cypress-setup with: should_record: ${{ contains(github.event.head_commit.message, '[e2e record]') || contains(join(github.event.pull_request.labels.*.name), 'e2e record')}} + spec-group: ${{ needs.setup-matrix.outputs.matrix }} secrets: username: ${{ secrets.CYPRESS_DHIS2_USERNAME }} password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }} diff --git a/cypress/support/generateTestMatrix.js b/cypress/support/generateTestMatrix.js new file mode 100644 index 0000000000..90b16397da --- /dev/null +++ b/cypress/support/generateTestMatrix.js @@ -0,0 +1,35 @@ +const fs = require('fs') +const path = require('path') + +const getAllFiles = (dirPath, arrayOfFiles = []) => { + const files = fs.readdirSync(dirPath) + + files.forEach((file) => { + if (fs.statSync(path.join(dirPath, file)).isDirectory()) { + arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles) + } else if (path.extname(file) === '.js') { + arrayOfFiles.push(path.join(dirPath, file)) + } + }) + + return arrayOfFiles +} + +const createGroups = (files, numberOfGroups = 7) => { + const groups = [] + for (let i = 0; i < numberOfGroups; i++) { + groups.push([]) + } + + files.forEach((file, index) => { + groups[index % numberOfGroups].push(file) + }) + + return groups.map((group, index) => ({ id: index + 1, tests: group })) +} + +const cypressSpecsPath = './cypress/integration' +const specs = getAllFiles(cypressSpecsPath) +const groupedSpecs = createGroups(specs) + +console.log(JSON.stringify(groupedSpecs))