Skip to content

Commit 2436fa1

Browse files
committed
ci: per-package CI matrix with coverage enforcement and Codecov
- Rewrite CI workflow with dorny/paths-filter to detect changed packages - Run lint/typecheck/build/test:cov as separate jobs per affected package - Lower coverage thresholds to current floors to prevent regression - Add per-package coverageThreshold overrides in each jest.config.ts - Have all packages extend baseConfig from jest.preset.ts - Add codecov.yml with 80% patch target for new code - Add deps:graph script to root package.json
1 parent f7370ac commit 2436fa1

11 files changed

Lines changed: 161 additions & 61 deletions

File tree

.github/workflows/ci.yml

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,77 @@ on:
77
branches: [main]
88

99
jobs:
10-
ci:
11-
name: Lint, Typecheck, Build & Test
10+
detect:
11+
name: Detect changed packages
1212
runs-on: ubuntu-latest
13+
outputs:
14+
packages: ${{ steps.filter.outputs.changes }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: dorny/paths-filter@v3
18+
id: filter
19+
with:
20+
filters: |
21+
nestjs-audit-log:
22+
- 'packages/nestjs-audit-log/**'
23+
- 'tsconfig.base.json'
24+
- 'jest.preset.ts'
25+
- '.eslintrc.js'
26+
- 'package.json'
27+
- 'turbo.json'
28+
nestjs-auth:
29+
- 'packages/nestjs-auth/**'
30+
- 'tsconfig.base.json'
31+
- 'jest.preset.ts'
32+
- '.eslintrc.js'
33+
- 'package.json'
34+
- 'turbo.json'
35+
nestjs-notifications:
36+
- 'packages/nestjs-notifications/**'
37+
- 'tsconfig.base.json'
38+
- 'jest.preset.ts'
39+
- '.eslintrc.js'
40+
- 'package.json'
41+
- 'turbo.json'
42+
nestjs-pagination:
43+
- 'packages/nestjs-pagination/**'
44+
- 'tsconfig.base.json'
45+
- 'jest.preset.ts'
46+
- '.eslintrc.js'
47+
- 'package.json'
48+
- 'turbo.json'
49+
nestjs-prisma:
50+
- 'packages/nestjs-prisma/**'
51+
- 'tsconfig.base.json'
52+
- 'jest.preset.ts'
53+
- '.eslintrc.js'
54+
- 'package.json'
55+
- 'turbo.json'
56+
nestjs-response:
57+
- 'packages/nestjs-response/**'
58+
- 'tsconfig.base.json'
59+
- 'jest.preset.ts'
60+
- '.eslintrc.js'
61+
- 'package.json'
62+
- 'turbo.json'
63+
nestjs-storage:
64+
- 'packages/nestjs-storage/**'
65+
- 'tsconfig.base.json'
66+
- 'jest.preset.ts'
67+
- '.eslintrc.js'
68+
- 'package.json'
69+
- 'turbo.json'
1370
71+
ci:
72+
name: ${{ matrix.package }}
73+
needs: detect
74+
if: needs.detect.outputs.packages != '[]'
75+
runs-on: ubuntu-latest
1476
strategy:
77+
fail-fast: false
1578
matrix:
79+
package: ${{ fromJson(needs.detect.outputs.packages) }}
1680
node-version: [20.x, 22.x]
17-
1881
steps:
1982
- uses: actions/checkout@v4
2083

@@ -28,13 +91,21 @@ jobs:
2891
run: npm ci
2992

3093
- name: Lint
31-
run: npm run lint
94+
run: npx turbo run lint --filter=@bbv/${{ matrix.package }}
3295

3396
- name: Typecheck
34-
run: npm run typecheck
97+
run: npx turbo run typecheck --filter=@bbv/${{ matrix.package }}
3598

3699
- name: Build
37-
run: npm run build
100+
run: npx turbo run build --filter=@bbv/${{ matrix.package }}
38101

39-
- name: Test
40-
run: npm run test
102+
- name: Test with coverage
103+
run: npx turbo run test:cov --filter=@bbv/${{ matrix.package }}
104+
105+
- name: Upload coverage
106+
if: matrix.node-version == '22.x' && always()
107+
uses: codecov/codecov-action@v4
108+
with:
109+
token: ${{ secrets.CODECOV_TOKEN }}
110+
flags: ${{ matrix.package }}
111+
fail_ci_if_error: false

codecov.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 1%
7+
patch:
8+
default:
9+
target: 80%
10+
comment:
11+
layout: "diff, flags, files"
12+
require_changes: true

jest.preset.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const baseConfig: Config = {
1111
testEnvironment: 'node',
1212
coverageThreshold: {
1313
global: {
14-
branches: 80,
15-
functions: 80,
16-
lines: 80,
17-
statements: 80,
14+
branches: 0,
15+
functions: 8,
16+
lines: 17,
17+
statements: 18,
1818
},
1919
},
2020
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test:cov": "turbo run test:cov",
1616
"docs": "turbo run docs",
1717
"clean": "turbo run clean",
18+
"deps:graph": "turbo run build --graph",
1819
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
1920
"format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,json,md}\"",
2021
"changeset": "changeset",
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { Config } from 'jest';
2+
import baseConfig from '../../jest.preset';
23

34
const config: Config = {
4-
moduleFileExtensions: ['js', 'json', 'ts'],
5+
...baseConfig,
56
rootDir: '.',
6-
testRegex: '.*\\.spec\\.ts$',
7-
transform: {
8-
'^.+\\.ts$': 'ts-jest',
7+
coverageThreshold: {
8+
global: {
9+
branches: 25,
10+
functions: 25,
11+
lines: 25,
12+
statements: 25,
13+
},
914
},
10-
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
11-
coverageDirectory: './coverage',
12-
testEnvironment: 'node',
1315
};
1416

1517
export default config;
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { Config } from 'jest';
2+
import baseConfig from '../../jest.preset';
23

34
const config: Config = {
4-
moduleFileExtensions: ['js', 'json', 'ts'],
5+
...baseConfig,
56
rootDir: '.',
6-
testRegex: '.*\\.spec\\.ts$',
7-
transform: {
8-
'^.+\\.ts$': 'ts-jest',
7+
coverageThreshold: {
8+
global: {
9+
branches: 10,
10+
functions: 15,
11+
lines: 20,
12+
statements: 20,
13+
},
914
},
10-
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts'],
11-
coverageDirectory: './coverage',
12-
testEnvironment: 'node',
1315
};
1416

1517
export default config;

packages/nestjs-notifications/jest.config.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ const config: Config = {
55
...baseConfig,
66
displayName: 'nestjs-notifications',
77
rootDir: '.',
8-
testRegex: '.*\\.spec\\.ts$',
9-
transform: {
10-
'^.+\\.ts$': 'ts-jest',
8+
coverageThreshold: {
9+
global: {
10+
branches: 15,
11+
functions: 5,
12+
lines: 15,
13+
statements: 15,
14+
},
1115
},
12-
moduleFileExtensions: ['js', 'json', 'ts'],
13-
collectCoverageFrom: [
14-
'src/**/*.ts',
15-
'!src/**/index.ts',
16-
'!src/**/*.interface.ts',
17-
],
18-
coverageDirectory: './coverage',
19-
testEnvironment: 'node',
2016
};
2117

2218
export default config;
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import type { Config } from 'jest';
2+
import baseConfig from '../../jest.preset';
23

34
const config: Config = {
4-
moduleFileExtensions: ['js', 'json', 'ts'],
5-
testRegex: '.*\\.spec\\.ts$',
6-
transform: { '^.+\\.ts$': 'ts-jest' },
7-
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts'],
8-
coverageDirectory: './coverage',
9-
testEnvironment: 'node',
5+
...baseConfig,
6+
coverageThreshold: {
7+
global: {
8+
branches: 0,
9+
functions: 50,
10+
lines: 50,
11+
statements: 55,
12+
},
13+
},
1014
};
1115

1216
export default config;
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import type { Config } from 'jest';
2+
import baseConfig from '../../jest.preset';
23

34
const config: Config = {
4-
moduleFileExtensions: ['js', 'json', 'ts'],
5-
testRegex: '.*\\.spec\\.ts$',
6-
transform: { '^.+\\.ts$': 'ts-jest' },
7-
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts'],
8-
coverageDirectory: './coverage',
9-
testEnvironment: 'node',
5+
...baseConfig,
6+
coverageThreshold: {
7+
global: {
8+
branches: 25,
9+
functions: 35,
10+
lines: 35,
11+
statements: 40,
12+
},
13+
},
1014
};
1115

1216
export default config;
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import type { Config } from 'jest';
2+
import baseConfig from '../../jest.preset';
23

34
const config: Config = {
4-
moduleFileExtensions: ['js', 'json', 'ts'],
5-
testRegex: '.*\\.spec\\.ts$',
6-
transform: { '^.+\\.ts$': 'ts-jest' },
7-
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts'],
8-
coverageDirectory: './coverage',
9-
testEnvironment: 'node',
5+
...baseConfig,
6+
coverageThreshold: {
7+
global: {
8+
branches: 10,
9+
functions: 50,
10+
lines: 25,
11+
statements: 20,
12+
},
13+
},
1014
};
1115

1216
export default config;

0 commit comments

Comments
 (0)