Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,33 @@ env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

jobs:
list-packages:
name: List packages
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- name: Install dependencies
run: npm ci
- name: List packages using Nx CLI
id: list-packages
run: |
matrix=$(node tools/scripts/create-codecov-matrix.js)
echo "matrix=$matrix" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.list-packages.outputs.matrix }}

coverage:
needs: [list-packages]
strategy:
fail-fast: false
matrix:
lib:
- cli
- core
- models
- utils
- plugin-eslint
- plugin-coverage
- plugin-js-packages
- plugin-lighthouse
scope: [unit, int]
name: Update code coverage
matrix: ${{ fromJson(needs.list-packages.outputs.matrix) }}
name: Collect code coverage
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
Expand All @@ -35,13 +47,13 @@ jobs:
cache: npm
- name: Install dependencies
run: npm ci
- name: Execute all tests and generate coverage reports
run: npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
- name: Execute tests with coverage
run: npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
directory: coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests/
directory: coverage/${{ matrix.project }}/${{ matrix.target }}s/
files: ./lcov.info
flags: ${{ matrix.lib }}-${{ matrix.scope }}
flags: ${{ matrix.project }}-${{ matrix.target }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
25 changes: 25 additions & 0 deletions tools/scripts/create-codecov-matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-check
import { createProjectGraphAsync } from '@nx/devkit';

const graph = await createProjectGraphAsync({
exitOnError: true,
resetDaemonClient: true,
});

const projects = Object.values(graph.nodes)
.filter(project => project.data.root === `packages/${project.name}`)
.sort((a, b) => a.name.localeCompare(b.name));
const targets = ['unit-test', 'int-test'];
const excludes = targets.flatMap(target =>
projects
.filter(project => project.data.targets?.[target] == null)
.map(project => ({ project: project.name, target })),
);

const matrix = {
project: projects.map(project => project.name),
target: targets,
exclude: excludes,
};

console.info(JSON.stringify(matrix));
Loading