From 714da3ecc96e77077a91950324ac2e9cff0f1ba6 Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Thu, 13 Mar 2025 07:54:11 +0000 Subject: [PATCH] [AAE-30877] - fixed the unit test tasks --- .github/workflows/pull-request.yml | 69 +++++++++++++++++------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ba8fa23223..59e355aa25 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -64,7 +64,7 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Ensure SHA pinned actions - uses: zgosalvez/github-actions-ensure-sha-pinned-actions@4830be28ce81da52ec70d65c552a7403821d98d4 # v3.0.23 + uses: zgosalvez/github-actions-ensure-sha-pinned-actions@25ed13d0628a1601b4b44048e63cc4328ed03633 # v3.0.22 - name: Check package-lock.json version run: | @@ -84,10 +84,10 @@ jobs: fetch-depth: 0 - name: Get branch name - uses: Alfresco/alfresco-build-tools/.github/actions/get-branch-name@45bb8b664779b691f8a21d9fd49e360916726c11 # v8.18.1 + uses: Alfresco/alfresco-build-tools/.github/actions/get-branch-name@c1236aee36bb9b35c5972819fcf8a4d07572e6cd # v8.16.0 - name: Save commit message - uses: Alfresco/alfresco-build-tools/.github/actions/get-commit-message@45bb8b664779b691f8a21d9fd49e360916726c11 # v8.18.1 + uses: Alfresco/alfresco-build-tools/.github/actions/get-commit-message@c1236aee36bb9b35c5972819fcf8a4d07572e6cd # v8.16.0 - name: ci:force flag parser shell: bash @@ -172,39 +172,50 @@ jobs: npx nx run cli:bundle - uses: ./.github/actions/upload-node-modules-and-artifacts - unit-tests: - timeout-minutes: 30 - name: "Unit tests: ${{ matrix.unit-tests.name }}" + generate-affected-matrix: + name: "Generate affected matrix" runs-on: ubuntu-latest - needs: [setup] - strategy: - fail-fast: false - # max-parallel: 4 - matrix: - unit-tests: - - name: js-api - exclude: "core,insights,content-services,process-services,process-services-cloud,eslint-plugin-eslint-angular" - - name: content-services - exclude: "insights,core,extensions,process-services,process-services-cloud,eslint-plugin-eslint-angular,js-api" - - name: core - exclude: "insights,extensions,content-services,process-services,process-services-cloud,eslint-plugin-eslint-angular,js-api" - - name: insights - exclude: "core,extensions,content-services,process-services-cloud,process-services,eslint-plugin-eslint-angular,js-api" - - name: process-services - exclude: "core,extensions,content-services,process-services-cloud,insights,eslint-plugin-eslint-angular,js-api" - - name: process-services-cloud - exclude: "insights,core,extensions,content-services,process-services$,eslint-plugin-eslint-angular,js-api" + needs: [setup, build-libs, lint] + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - name: Checkout repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: - fetch-depth: 0 # Fetch all history for all tags and branches + fetch-depth: 0 + - name: Install dependencies + run: npm ci + - name: Generate affected projects matrix + id: set-matrix + run: | + BASE_REF="${{ github.event.pull_request.base.ref }}" + echo "Base ref is $BASE_REF" + AFFECTED=$(npx nx show projects --affected --target=test --base=origin/$BASE_REF --select=projects --plain --exclude=stories,eslint-angular) + echo "Affected projects: $AFFECTED" + MATRIX_JSON=$(echo $AFFECTED | xargs -n1 | jq -R -s -c 'split("\n")[:-1] | map({ "project": . })') + MATRIX_JSON=$(echo "$MATRIX_JSON" | tr -d '\n' | sed 's/"$//') + echo "Matrix JSON: $MATRIX_JSON" + core.setOutput('matrix', matrix); + unit-tests: + if: ${{ needs.generate-affected-matrix.outputs.matrix != '' }} + name: "Unit tests for affected project: ${{ matrix.project }}" + runs-on: ubuntu-latest + needs: [generate-affected-matrix] + strategy: + matrix: ${{ fromJson(needs.generate-affected-matrix.outputs.matrix) }} + max-parallel: 4 + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 - uses: ./.github/actions/setup - uses: ./.github/actions/download-node-modules-and-artifacts - - name: Run unit tests + - name: Run test for ${{ matrix.project }} + env: + NODE_OPTIONS: "--max-old-space-size=5120" run: | - /usr/bin/xvfb-run --auto-servernum npx nx affected:test --exclude=${{ matrix.unit-tests.exclude }} - + xvfb-run --auto-servernum npx nx run ${{ matrix.project }}:test lint: # long timeout required when cache has to be recreated timeout-minutes: 30