Skip to content

Commit 5b4069a

Browse files
committed
ci: fix codecov workflow - projects and targets inferred from nx graph
1 parent 163f67f commit 5b4069a

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

.github/workflows/code-coverage.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,33 @@ env:
99
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
1010

1111
jobs:
12+
list-packages:
13+
name: List packages
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout the repository
17+
uses: actions/checkout@v4
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version-file: .nvmrc
22+
cache: npm
23+
- name: Install dependencies
24+
run: npm ci
25+
- name: List packages using Nx CLI
26+
id: list-packages
27+
run: |
28+
matrix=$(node tools/scripts/create-codecov-matrix.js)
29+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
30+
outputs:
31+
matrix: ${{ steps.list-packages.outputs.matrix }}
32+
1233
coverage:
34+
needs: [list-packages]
1335
strategy:
1436
fail-fast: false
15-
matrix:
16-
lib:
17-
- cli
18-
- core
19-
- models
20-
- utils
21-
- plugin-eslint
22-
- plugin-coverage
23-
- plugin-js-packages
24-
- plugin-lighthouse
25-
scope: [unit, int]
26-
name: Update code coverage
37+
matrix: ${{ fromJson(needs.list-packages.outputs.matrix) }}
38+
name: Collect code coverage
2739
runs-on: ubuntu-latest
2840
steps:
2941
- name: Checkout the repository
@@ -35,13 +47,13 @@ jobs:
3547
cache: npm
3648
- name: Install dependencies
3749
run: npm ci
38-
- name: Execute all tests and generate coverage reports
39-
run: npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
50+
- name: Execute tests with coverage
51+
run: npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
4052
- name: Upload coverage reports to Codecov
4153
uses: codecov/codecov-action@v4
4254
with:
43-
directory: coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests/
55+
directory: coverage/${{ matrix.project }}/${{ matrix.target }}s/
4456
files: ./lcov.info
45-
flags: ${{ matrix.lib }}-${{ matrix.scope }}
57+
flags: ${{ matrix.project }}-${{ matrix.target }}
4658
token: ${{ secrets.CODECOV_TOKEN }}
4759
fail_ci_if_error: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @ts-check
2+
import { createProjectGraphAsync } from '@nx/devkit';
3+
4+
const graph = await createProjectGraphAsync({
5+
exitOnError: true,
6+
resetDaemonClient: true,
7+
});
8+
9+
const projects = Object.values(graph.nodes)
10+
.filter(project => project.data.root === `packages/${project.name}`)
11+
.sort((a, b) => a.name.localeCompare(b.name));
12+
const targets = ['unit-test', 'int-test'];
13+
const excludes = targets.flatMap(target =>
14+
projects
15+
.filter(project => project.data.targets?.[target] == null)
16+
.map(project => ({ project: project.name, target })),
17+
);
18+
19+
const matrix = {
20+
project: projects.map(project => project.name),
21+
target: targets,
22+
exclude: excludes,
23+
};
24+
25+
console.info(JSON.stringify(matrix));

0 commit comments

Comments
 (0)