Skip to content

Commit ff0fc01

Browse files
committed
ci: fix codecov workflow - projects and targets inferred from nx graph
1 parent d6ba73c commit ff0fc01

File tree

2 files changed

+58
-19
lines changed

2 files changed

+58
-19
lines changed
Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
name: Code Coverage
22

3-
on:
4-
push:
5-
branches: [main]
3+
# TODO: revert
4+
on: push
5+
# on:
6+
# push:
7+
# branches: [main]
68

79
env:
810
NX_NON_NATIVE_HASHER: true
911
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
1012

1113
jobs:
14+
list-packages:
15+
name: List packages
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout the repository
19+
uses: actions/checkout@v4
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version-file: .nvmrc
24+
cache: npm
25+
- name: Install dependencies
26+
run: npm ci
27+
- name: List packages using Nx CLI
28+
id: list-packages
29+
run: |
30+
matrix=$(node tools/scripts/create-codecov-matrix.js)
31+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
32+
outputs:
33+
matrix: ${{ steps.list-packages.outputs.matrix }}
34+
1235
coverage:
36+
needs: [list-packages]
1337
strategy:
1438
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
39+
matrix: ${{ fromJson(needs.list-packages.outputs.matrix) }}
40+
name: Collect code coverage
2741
runs-on: ubuntu-latest
2842
steps:
2943
- name: Checkout the repository
@@ -35,13 +49,13 @@ jobs:
3549
cache: npm
3650
- name: Install dependencies
3751
run: npm ci
38-
- name: Execute all tests and generate coverage reports
39-
run: npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
52+
- name: Execute tests with coverage
53+
run: npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
4054
- name: Upload coverage reports to Codecov
4155
uses: codecov/codecov-action@v4
4256
with:
43-
directory: coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests/
57+
directory: coverage/${{ matrix.project }}/${{ matrix.target }}s/
4458
files: ./lcov.info
45-
flags: ${{ matrix.lib }}-${{ matrix.scope }}
59+
flags: ${{ matrix.project }}-${{ matrix.target }}
4660
token: ${{ secrets.CODECOV_TOKEN }}
4761
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)