[AAE-32905] - Moving matrix generation to the relative workflows

This commit is contained in:
VitoAlbano
2025-04-01 16:19:54 +01:00
parent 0a7ddda8fc
commit d6104ab8a0
4 changed files with 90 additions and 54 deletions

View File

@@ -29,6 +29,28 @@ runs:
uses: Alfresco/alfresco-build-tools/.github/actions/git-latest-tag@a3d5beb67a8b8d96398435e01686a9a9185380ab # v8.18.0
- name: load "NPM TAG"
uses: ./.github/actions/set-npm-tag
- name: pip cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
if: ${{ inputs.enable-cache == 'true' }}
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-
restore-keys: |
${{ runner.os }}
- name: Cache node modules
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Cache nx cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
path: nxcache
key: ${{ runner.os }}-nxcache-${{ hashFiles('nx.json') }}
restore-keys: |
${{ runner.os }}-nxcache-
- name: before install script
uses: ./.github/actions/before-install
with:

View File

@@ -1,31 +1,48 @@
name: "Build Lib Workflow"
on:
workflow_call:
inputs:
matrix:
description: 'JSON Matrix of projects'
required: true
type: string
workflow_call: {}
jobs:
build:
generate-affected-matrix:
name: "Generate affected matrix"
runs-on: ubuntu-latest
strategy:
matrix:
include: ${{ fromJson(inputs.matrix) }}
outputs:
buildMatrix: ${{ steps.set-matrix.outputs.buildMatrix }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
- name: Cache node modules
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
- name: Setup environment
uses: ./.github/actions/setup
- 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_BUILD=$(npx nx show projects --affected --target=test --base=origin/$BASE_REF --select=projects --plain --exclude=stories)
AFFECTED_UNIT=$(npx nx show projects --affected --target=test --base=origin/$BASE_REF --select=projects --plain --exclude=cli,stories,eslint-angular)
echo "Affected projects for BUILD : $AFFECTED_BUILD"
BUILD_MATRIX_JSON=$(echo $AFFECTED_BUILD | xargs -n1 | jq -R -s -c 'split("\n")[:-1] | map({ "project": . })')
BUILD_MATRIX_JSON=$(echo "$BUILD_MATRIX_JSON" | tr -d '\n' | sed 's/"$//')
echo "Matrix BUILD: $BUILD_MATRIX_JSON"
echo "buildMatrix=$BUILD_MATRIX_JSON" >> $GITHUB_OUTPUT
build:
needs: generate-affected-matrix
runs-on: ubuntu-latest
strategy:
matrix:
include: ${{ fromJson(needs.generate-affected-matrix.outputs.buildMatrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
fetch-depth: 0
- name: Setup environment
uses: ./.github/actions/setup
- name: Run build for ${{ matrix.project }}

View File

@@ -227,45 +227,29 @@ jobs:
lint:
name: "Lint"
runs-on: ubuntu-latest
needs: ["generate-affected-matrix"]
needs: [pre-checks, check-if-pr-is-approved]
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Cache node modules
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- uses: ./.github/actions/setup
- run: npx nx affected --target=lint --base=origin/develop --head=HEAD
trigger-build:
name: "Build Libs"
needs: [generate-affected-matrix]
needs: [pre-checks, check-if-pr-is-approved]
uses: ./.github/workflows/build-lib-workflow.yml
with:
matrix: ${{ needs.generate-affected-matrix.outputs.buildMatrix }}
build-storybook:
name: "Build Storybook"
needs: [generate-affected-matrix]
needs: [pre-checks, check-if-pr-is-approved]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
- name: Cache node modules
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Setup environment
uses: ./.github/actions/setup
- name: Build Storybook
@@ -274,10 +258,8 @@ jobs:
trigger-unit-tests:
name: "Unit Tests"
needs: [generate-affected-matrix]
needs: [pre-checks, check-if-pr-is-approved]
uses: ./.github/workflows/unit-test-workflow.yml
with:
matrix: ${{ needs.generate-affected-matrix.outputs.unitMatrix }}
finalize:
if: ${{ always() }}

View File

@@ -1,31 +1,46 @@
name: "Unit Tests Workflow"
on:
workflow_call:
inputs:
matrix:
description: 'JSON Matrix of projects'
required: true
type: string
workflow_call: {}
jobs:
unit-tests:
generate-affected-matrix:
name: "Generate affected matrix"
runs-on: ubuntu-latest
strategy:
matrix:
include: ${{ fromJson(inputs.matrix) }}
outputs:
unitMatrix: ${{ steps.set-matrix.outputs.unitMatrix }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
- name: Cache node modules
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
- name: Setup environment
uses: ./.github/actions/setup
- 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_UNIT=$(npx nx show projects --affected --target=test --base=origin/$BASE_REF --select=projects --plain --exclude=cli,stories,eslint-angular)
echo "Affected projects for UNIT : $AFFECTED_UNIT"
UNIT_MATRIX_JSON=$(echo $AFFECTED_UNIT | xargs -n1 | jq -R -s -c 'split("\n")[:-1] | map({ "project": . })')
UNIT_MATRIX_JSON=$(echo "$UNIT_MATRIX_JSON" | tr -d '\n' | sed 's/"$//')
echo "Matrix UNIT: $UNIT_MATRIX_JSON"
echo "unitMatrix=$UNIT_MATRIX_JSON" >> $GITHUB_OUTPUT
unit-tests:
runs-on: ubuntu-latest
needs: generate-affected-matrix
strategy:
matrix:
include: ${{ fromJson(needs.generate-affected-matrix.outputs.unitMatrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
fetch-depth: 0
- name: Setup environment
uses: ./.github/actions/setup
- name: Run unit tests for ${{ matrix.project }}