Skip to content

Commit f7d62e6

Browse files
committed
CCM-10981: add matrix for workspaces
1 parent 75f4945 commit f7d62e6

File tree

2 files changed

+67
-26
lines changed

2 files changed

+67
-26
lines changed

.github/workflows/stage-2-test.yaml

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ jobs:
5454
node_version: "${{ inputs.nodejs_version }}"
5555
skip_restore: true
5656

57+
discover-workspaces:
58+
runs-on: ubuntu-latest
59+
outputs:
60+
matrix: ${{ steps.get-workspaces.outputs.matrix }}
61+
steps:
62+
- name: "Checkout code"
63+
uses: actions/[email protected]
64+
- name: "Get workspaces"
65+
id: "get-workspaces"
66+
run: |
67+
echo "matrix=$(jq '.workspaces' package.json)" >> "$GITHUB_OUTPUT"
68+
5769
check-generated-dependencies:
5870
name: "Check generated dependencies"
5971
runs-on: ubuntu-latest
@@ -75,7 +87,9 @@ jobs:
7587
name: "Unit tests"
7688
runs-on: ubuntu-latest
7789
timeout-minutes: 5
78-
needs: [install-dependencies]
90+
needs: [install-dependencies, discover-workspaces]
91+
strategy:
92+
matrix: ${{ fromJSON(needs.discover-workspaces.outputs.matrix) }}
7993
steps:
8094
- name: "Checkout code"
8195
uses: actions/[email protected]
@@ -88,21 +102,51 @@ jobs:
88102
npm run generate-dependencies --workspaces --if-present
89103
- name: "Run unit test suite"
90104
run: |
91-
make test-unit
92-
- name: "Save the result of fast test suite"
105+
WORKSPACE=${{ matrix.workspace }} make test-unit
106+
- name: "Save the result of test suite"
93107
uses: actions/upload-artifact@v4
94108
with:
95-
name: unit-tests
96-
path: "**/.reports/unit"
109+
name: unit-tests-${{ matrix.workspace }}
110+
path: " ${{ matrix.workspace }}/.reports/unit"
97111
include-hidden-files: true
98112
if: always()
99113
- name: "Save the result of code coverage"
100114
uses: actions/upload-artifact@v4
101115
with:
102-
name: code-coverage-report
103-
path: ".reports/lcov.info"
116+
name: code-coverage-${{ matrix.workspace }}
117+
path: "${{ matrix.workspace }}/.reports/unit/coverage/lcov.info"
104118
if: always()
105119

120+
merge-coverage:
121+
name: "Merge coverage"
122+
runs-on: ubuntu-latest
123+
needs: [test-unit]
124+
steps:
125+
- uses: actions/checkout@v5
126+
127+
- name: Download coverage artifacts
128+
uses: actions/download-artifact@v4
129+
with:
130+
pattern: code-coverage-*
131+
merge-multiple: false
132+
path: ./_cov_parts
133+
134+
- name: Merge LCOV files
135+
run: |
136+
set -euo pipefail
137+
mkdir -p .reports
138+
npx --yes lcov-result-merger \
139+
"./_cov_parts/**/lcov.info" \
140+
".reports/lcov.info" \
141+
--ignore "node_modules" \
142+
--prepend-source-files
143+
144+
- name: Upload merged LCOV
145+
uses: actions/upload-artifact@v4
146+
with:
147+
name: code-coverage-merged
148+
path: .reports/lcov.info
149+
106150
test-lint:
107151
name: "Linting"
108152
runs-on: ubuntu-latest
@@ -141,21 +185,6 @@ jobs:
141185
run: |
142186
make test-typecheck
143187
144-
test-coverage:
145-
name: "Test coverage"
146-
needs: [test-unit]
147-
runs-on: ubuntu-latest
148-
timeout-minutes: 5
149-
steps:
150-
- name: "Checkout code"
151-
uses: actions/[email protected]
152-
- name: "Run test coverage check"
153-
run: |
154-
make test-coverage
155-
- name: "Save the coverage check result"
156-
run: |
157-
echo "Nothing to save"
158-
159188
perform-static-analysis:
160189
name: "Perform static analysis"
161190
needs: [test-unit]

scripts/tests/unit.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set -euo pipefail
44

55
cd "$(git rev-parse --show-toplevel)"
66

7+
# read optional first arg; empty means "run all workspaces"
8+
WORKSPACE="${WORKSPACE:-}"
9+
710
# This file is for you! Edit it to call your unit test suite. Note that the same
811
# file will be called if you run it locally as if you run it on CI.
912

@@ -18,8 +21,17 @@ cd "$(git rev-parse --show-toplevel)"
1821
# tasks in scripts/test.mk.
1922

2023
# run tests
21-
npm run test:unit --workspaces
24+
if [[ -n "$WORKSPACE" ]]; then
25+
npm run test:unit --workspace="$WORKSPACE"
26+
else
27+
npm run test:unit --workspaces
2228

23-
# merge coverage reports
24-
mkdir -p .reports
25-
TMPDIR="./.reports" ./node_modules/.bin/lcov-result-merger "**/.reports/unit/coverage/lcov.info" ".reports/lcov.info" --ignore "node_modules" --prepend-source-files --prepend-path-fix "../../.."
29+
# merge coverage reports
30+
mkdir -p .reports
31+
TMPDIR="./.reports" ./node_modules/.bin/lcov-result-merger \
32+
"**/.reports/unit/coverage/lcov.info" \
33+
".reports/lcov.info" \
34+
--ignore "node_modules" \
35+
--prepend-source-files \
36+
--prepend-path-fix "../../.."
37+
fi

0 commit comments

Comments
 (0)