Skip to content

Commit 89a62e4

Browse files
committed
Merge remote-tracking branch 'origin/main' into setup-pkg-new
# Conflicts: # packages/create-cli/package.json
2 parents e54b74a + ae52e3b commit 89a62e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+300
-162
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.73.0 (2025-08-08)
2+
3+
### 🚀 Features
4+
5+
- **ci:** add searchCommits option to extend portal cache range ([0b14111f](https://github.com/code-pushup/cli/commit/0b14111f))
6+
7+
### ❤️ Thank You
8+
9+
- Matěj Chalk
10+
111
## 0.72.1 (2025-08-06)
212

313
### 🩹 Fixes

eslint.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import nxEslintPlugin from '@nx/eslint-plugin';
2+
import jestExtendedPlugin from 'eslint-plugin-jest-extended';
23
import jsoncParser from 'jsonc-eslint-parser';
34
import tseslint from 'typescript-eslint';
45
import node from '@code-pushup/eslint-config/node.js';
@@ -84,13 +85,19 @@ export default tseslint.config(
8485
},
8586
{
8687
files: ['**/*.test.ts', '**/*.spec.ts'],
88+
plugins: { 'jest-extended': jestExtendedPlugin },
8789
rules: {
8890
'vitest/consistent-test-filename': [
8991
'warn',
9092
{
9193
pattern: String.raw`.*\.(bench|type|unit|int|e2e)\.test\.[tj]sx?$`,
9294
},
9395
],
96+
'jest-extended/prefer-to-be-array': 'warn',
97+
'jest-extended/prefer-to-be-false': 'warn',
98+
'jest-extended/prefer-to-be-object': 'warn',
99+
'jest-extended/prefer-to-be-true': 'warn',
100+
'jest-extended/prefer-to-have-been-called-once': 'warn',
94101
},
95102
},
96103
{

package-lock.json

Lines changed: 47 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"node": ">=22.14"
2323
},
2424
"dependencies": {
25-
"@code-pushup/portal-client": "^0.14.3",
25+
"@code-pushup/portal-client": "^0.15.0",
2626
"@isaacs/cliui": "^8.0.2",
2727
"@nx/devkit": "19.8.13",
2828
"@poppinss/cliui": "6.4.1",
@@ -89,6 +89,7 @@
8989
"eslint-import-resolver-typescript": "^3.6.1",
9090
"eslint-plugin-functional": "^7.1.0",
9191
"eslint-plugin-import": "^2.31.0",
92+
"eslint-plugin-jest-extended": "^3.0.0",
9293
"eslint-plugin-jest-formatting": "^3.1.0",
9394
"eslint-plugin-n": "^17.15.0",
9495
"eslint-plugin-promise": "^7.2.1",
@@ -99,6 +100,7 @@
99100
"globals": "^15.13.0",
100101
"husky": "^8.0.0",
101102
"inquirer": "^9.3.7",
103+
"jest-extended": "^6.0.0",
102104
"jsdom": "~24.0.0",
103105
"jsonc-eslint-parser": "^2.4.0",
104106
"knip": "^5.33.3",

packages/ci/README.md

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Optionally, you can override default options for further customization:
109109
| `logger` | `Logger` | `console` | Logger for reporting progress and encountered problems |
110110
| `skipComment` | `boolean` | `false` | Toggles if comparison comment is posted to PR |
111111
| `configPatterns` | `ConfigPatterns \| null` | `null` | Additional configuration which enables [faster CI runs](#faster-ci-runs-with-configpatterns) |
112+
| `searchCommits` | `boolean \| number` | `false` | If base branch has no cached report in portal, [extends search up to 100 recent commits](#search-latest-commits-for-previous-report) |
112113

113114
[^1]: By default, the `code-pushup.config` file is autodetected as described in [`@code-pushup/cli` docs](../cli/README.md#configuration).
114115

@@ -217,32 +218,6 @@ await runInCI(refs, api, {
217218
});
218219
```
219220

220-
### Faster CI runs with `configPatterns`
221-
222-
By default, the `print-config` command is run sequentially for each project in order to reliably detect how `code-pushup` is configured - specifically, where to read output files from (`persist` config) and whether portal may be used as a cache (`upload` config). This allows for each project to be configured in its own way without breaking anything, but for large monorepos these extra `code-pushup print-config` executions can accumulate and significantly slow down CI pipelines.
223-
224-
As a more scalable alternative, `configPatterns` may be provided. A user declares upfront how every project is configured, which allows `print-config` to be skipped. It's the user's responsibility to ensure this configuration holds for every project (it won't be checked). The `configPatterns` support string interpolation, substituting `{projectName}` with each project's name. Other than that, each project's `code-pushup.config` must have exactly the same `persist` and `upload` configurations.
225-
226-
```ts
227-
await runInCI(refs, api, {
228-
monorepo: true,
229-
configPatterns: {
230-
persist: {
231-
outputDir: '.code-pushup/{projectName}',
232-
filename: 'report',
233-
format: ['json', 'md'],
234-
},
235-
// optional: will use portal as cache when comparing reports in PRs
236-
upload: {
237-
server: 'https://api.code-pushup.example.com/graphql',
238-
apiKey: 'cp_...',
239-
organization: 'example',
240-
project: '{projectName}',
241-
},
242-
},
243-
});
244-
```
245-
246221
### Monorepo result
247222

248223
In monorepo mode, the resolved object includes the merged diff at the top-level, as well as a list of projects.
@@ -273,3 +248,48 @@ if (result.mode === 'monorepo') {
273248
}
274249
}
275250
```
251+
252+
## Advanced usage
253+
254+
### Faster CI runs with `configPatterns`
255+
256+
By default, the `print-config` command is run sequentially for each project in order to reliably detect how `code-pushup` is configured - specifically, where to read output files from (`persist` config) and whether portal may be used as a cache (`upload` config). This allows for each project to be configured in its own way without breaking anything, but for large monorepos these extra `code-pushup print-config` executions can accumulate and significantly slow down CI pipelines.
257+
258+
As a more scalable alternative, `configPatterns` may be provided. A user declares upfront how every project is configured, which allows `print-config` to be skipped. It's the user's responsibility to ensure this configuration holds for every project (it won't be checked). The `configPatterns` support string interpolation, substituting `{projectName}` with each project's name. Other than that, each project's `code-pushup.config` must have exactly the same `persist` and `upload` configurations.
259+
260+
```ts
261+
await runInCI(refs, api, {
262+
monorepo: true,
263+
configPatterns: {
264+
persist: {
265+
outputDir: '.code-pushup/{projectName}',
266+
filename: 'report',
267+
format: ['json', 'md'],
268+
},
269+
// optional: will use portal as cache when comparing reports in PRs
270+
upload: {
271+
server: 'https://api.code-pushup.example.com/graphql',
272+
apiKey: 'cp_...',
273+
organization: 'example',
274+
project: '{projectName}',
275+
},
276+
},
277+
});
278+
```
279+
280+
### Search latest commits for previous report
281+
282+
When comparing reports, the report for the base branch can be cached. If a project has an `upload` configuration, then the Portal API is queried for a report matching that commit. If no such report was uploaded, then the report is looked up in CI artifacts (implemented in `downloadReportArtifact` in [`ProviderApiClient`](#provider-api-client)). If there's no report to be found, then the base branch is checked and the previous report is collected.
283+
284+
In some scenarios, there may not be a report for the latest commit in main branch, but some other recent commit may have a usable report - e.g. if `nxProjectsFilter` is used with `--affected` flag. In that case, the `searchCommits` option can be enabled. Then a limited number of recent commits in the main branch will be checked, but.
285+
286+
```ts
287+
await runInCI(refs, api, {
288+
monorepo: 'nx',
289+
nxProjectsFilter: '--with-target=code-pushup --affected',
290+
// checks 10 most recent commits by default
291+
searchCommits: true,
292+
// optionally, number of searched commits may be extended up to 100
293+
// searchCommits: 30
294+
});
295+
```

packages/ci/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code-pushup/ci",
3-
"version": "0.72.1",
3+
"version": "0.73.0",
44
"description": "CI automation logic for Code PushUp (provider-agnostic)",
55
"license": "MIT",
66
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/ci#readme",
@@ -26,9 +26,9 @@
2626
},
2727
"type": "module",
2828
"dependencies": {
29-
"@code-pushup/models": "0.72.1",
30-
"@code-pushup/portal-client": "^0.14.3",
31-
"@code-pushup/utils": "0.72.1",
29+
"@code-pushup/models": "0.73.0",
30+
"@code-pushup/portal-client": "^0.15.0",
31+
"@code-pushup/utils": "0.73.0",
3232
"glob": "^11.0.1",
3333
"simple-git": "^3.20.0",
3434
"yaml": "^2.5.1",

packages/ci/src/lib/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ export const DEFAULT_SETTINGS: Settings = {
1515
nxProjectsFilter: '--with-target={task}',
1616
skipComment: false,
1717
configPatterns: null,
18+
searchCommits: false,
1819
};
20+
21+
export const MIN_SEARCH_COMMITS = 1;
22+
export const MAX_SEARCH_COMMITS = 100;

packages/ci/src/lib/issues.unit.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('issues comparison', () => {
3131
},
3232
},
3333
),
34-
).toBe(true);
34+
).toBeTrue();
3535
});
3636

3737
it('should not match issues from different audits', () => {
@@ -63,7 +63,7 @@ describe('issues comparison', () => {
6363
},
6464
},
6565
),
66-
).toBe(false);
66+
).toBeFalse();
6767
});
6868

6969
it('should match issues based on adjusted line', () => {
@@ -97,7 +97,7 @@ describe('issues comparison', () => {
9797
},
9898
},
9999
),
100-
).toBe(true);
100+
).toBeTrue();
101101
});
102102

103103
it('should match issues from renamed files', () => {
@@ -124,7 +124,7 @@ describe('issues comparison', () => {
124124
},
125125
},
126126
),
127-
).toBe(true);
127+
).toBeTrue();
128128
});
129129

130130
it('should match issues based on adjusted line range', () => {
@@ -165,7 +165,7 @@ describe('issues comparison', () => {
165165
},
166166
},
167167
),
168-
).toBe(true);
168+
).toBeTrue();
169169
});
170170
});
171171

packages/ci/src/lib/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type Options = {
2121
logger?: Logger;
2222
skipComment?: boolean;
2323
configPatterns?: ConfigPatterns | null;
24+
searchCommits?: boolean | number;
2425
};
2526

2627
/**

packages/ci/src/lib/monorepo/handlers/npm.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('npmHandler', () => {
3030
},
3131
MEMFS_VOLUME,
3232
);
33-
await expect(npmHandler.isConfigured(options)).resolves.toBe(true);
33+
await expect(npmHandler.isConfigured(options)).resolves.toBeTrue();
3434
});
3535

3636
it('should NOT detect NPM workspaces when "workspaces" not set in package.json', async () => {
@@ -41,7 +41,7 @@ describe('npmHandler', () => {
4141
},
4242
MEMFS_VOLUME,
4343
);
44-
await expect(npmHandler.isConfigured(options)).resolves.toBe(false);
44+
await expect(npmHandler.isConfigured(options)).resolves.toBeFalse();
4545
});
4646

4747
it("should NOT detect NPM workspaces when package-lock.json doesn't exist", async () => {
@@ -55,7 +55,7 @@ describe('npmHandler', () => {
5555
},
5656
MEMFS_VOLUME,
5757
);
58-
await expect(npmHandler.isConfigured(options)).resolves.toBe(false);
58+
await expect(npmHandler.isConfigured(options)).resolves.toBeFalse();
5959
});
6060
});
6161

0 commit comments

Comments
 (0)