@code-pushup/ci 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@code-pushup/ci",
3
+ "version": "0.52.0",
4
+ "description": "CI automation logic for Code PushUp (provider-agnostic)",
5
+ "dependencies": {
6
+ "@code-pushup/models": "0.52.0",
7
+ "@code-pushup/utils": "0.52.0",
8
+ "glob": "^10.4.5",
9
+ "simple-git": "^3.20.0",
10
+ "yaml": "^2.5.1"
11
+ },
12
+ "license": "MIT",
13
+ "homepage": "https://github.com/code-pushup/cli/tree/main/packages/ci#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/code-pushup/cli/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/code-pushup/cli.git",
20
+ "directory": "packages/ci"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "type": "module",
26
+ "main": "./index.js",
27
+ "types": "./src/index.d.ts"
28
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type * from './lib/models';
2
+ export { runInCI } from './lib/run';
@@ -0,0 +1,3 @@
1
+ import type { CommandContext } from '../context';
2
+ import { type PersistedCliFiles } from '../persist';
3
+ export declare function runCollect({ bin, config, directory, silent, project, }: CommandContext): Promise<PersistedCliFiles>;
@@ -0,0 +1,9 @@
1
+ import type { CommandContext } from '../context';
2
+ import { type PersistedCliFiles } from '../persist';
3
+ type CompareOptions = {
4
+ before: string;
5
+ after: string;
6
+ label?: string;
7
+ };
8
+ export declare function runCompare({ before, after, label }: CompareOptions, { bin, config, directory, silent, project }: CommandContext): Promise<PersistedCliFiles>;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { CommandContext } from '../context';
2
+ import { type PersistedCliFiles } from '../persist';
3
+ export declare function runMergeDiffs(files: string[], { bin, config, directory, silent }: CommandContext): Promise<PersistedCliFiles<'md'>>;
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from '../context';
2
+ export declare function runPrintConfig({ bin, config, directory, silent, }: CommandContext): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import type { Settings } from '../models';
2
+ import type { ProjectConfig } from '../monorepo';
3
+ export type CommandContext = Pick<Settings, 'bin' | 'config' | 'directory' | 'silent'> & {
4
+ project?: string;
5
+ };
6
+ export declare function createCommandContext(settings: Settings, project: ProjectConfig | null | undefined): CommandContext;
@@ -0,0 +1,6 @@
1
+ export { runCollect } from './commands/collect';
2
+ export { runCompare } from './commands/compare';
3
+ export { runMergeDiffs } from './commands/merge-diffs';
4
+ export { runPrintConfig } from './commands/print-config';
5
+ export { createCommandContext, type CommandContext } from './context';
6
+ export { findPersistedFiles, type PersistedCliFiles } from './persist';
@@ -0,0 +1,21 @@
1
+ import { type Format } from '@code-pushup/models';
2
+ export type PersistedCliFiles<T extends Format = Format> = PersistedCliFilesFormats<T> & {
3
+ artifactData: {
4
+ rootDir: string;
5
+ files: string[];
6
+ };
7
+ };
8
+ export type PersistedCliFilesFormats<T extends Format = Format> = {
9
+ [F in T as `${F}FilePath`]: string;
10
+ };
11
+ export declare function persistCliOptions({ directory, project, }: {
12
+ directory: string;
13
+ project?: string;
14
+ }): string[];
15
+ export declare function persistedCliFiles<TFormat extends Format = Format>({ directory, isDiff, project, formats, }: {
16
+ directory: string;
17
+ isDiff?: boolean;
18
+ project?: string;
19
+ formats?: TFormat[];
20
+ }): PersistedCliFiles<TFormat>;
21
+ export declare function findPersistedFiles(rootDir: string, files: string[], project?: string): PersistedCliFiles;
@@ -0,0 +1,2 @@
1
+ import type { Logger, ProviderAPIClient } from './models';
2
+ export declare function commentOnPR(mdPath: string, api: ProviderAPIClient, logger: Logger): Promise<number>;
@@ -0,0 +1,2 @@
1
+ import type { Settings } from './models';
2
+ export declare const DEFAULT_SETTINGS: Settings;
@@ -0,0 +1,23 @@
1
+ export type ChangedFiles = Record<string, ChangedFile>;
2
+ type ChangedFile = {
3
+ originalFile?: string;
4
+ lineChanges: LineChange[];
5
+ };
6
+ type LineChange = {
7
+ prev: {
8
+ line: number;
9
+ count: number;
10
+ };
11
+ curr: {
12
+ line: number;
13
+ count: number;
14
+ };
15
+ };
16
+ export declare function listChangedFiles(refs: {
17
+ base: string;
18
+ head: string;
19
+ }, git?: import("simple-git").SimpleGit): Promise<ChangedFiles>;
20
+ export declare function isFileChanged(changedFiles: ChangedFiles, file: string): boolean;
21
+ export declare function adjustFileName(changedFiles: ChangedFiles, file: string): string;
22
+ export declare function adjustLine(changedFiles: ChangedFiles, file: string, line: number): number;
23
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { Audit, Issue, PluginMeta, Report, ReportsDiff } from '@code-pushup/models';
2
+ import { type ChangedFiles } from './git';
3
+ export type SourceFileIssue = Required<Issue> & IssueContext;
4
+ type IssueContext = {
5
+ audit: Pick<Audit, 'slug' | 'title'>;
6
+ plugin: Pick<PluginMeta, 'slug' | 'title'>;
7
+ };
8
+ export declare function filterRelevantIssues({ currReport, prevReport, reportsDiff, changedFiles, }: {
9
+ currReport: Report;
10
+ prevReport: Report;
11
+ reportsDiff: ReportsDiff;
12
+ changedFiles: ChangedFiles;
13
+ }): SourceFileIssue[];
14
+ export declare function issuesMatch(prev: SourceFileIssue, curr: SourceFileIssue, changedFiles: ChangedFiles): boolean;
15
+ export declare function getAuditImpactValue({ audit, plugin }: IssueContext, report: Report): number;
16
+ export {};
@@ -0,0 +1,102 @@
1
+ import type { SourceFileIssue } from './issues';
2
+ import type { MonorepoTool } from './monorepo';
3
+ /**
4
+ * Customization options for {@link runInCI}
5
+ * @see https://github.com/code-pushup/cli/tree/main/packages/ci#options
6
+ */
7
+ export type Options = {
8
+ monorepo?: boolean | MonorepoTool;
9
+ projects?: string[] | null;
10
+ task?: string;
11
+ bin?: string;
12
+ config?: string | null;
13
+ directory?: string;
14
+ silent?: boolean;
15
+ debug?: boolean;
16
+ detectNewIssues?: boolean;
17
+ logger?: Logger;
18
+ };
19
+ /**
20
+ * {@link Options} with filled-in defaults.
21
+ */
22
+ export type Settings = Required<Options>;
23
+ /**
24
+ * Branches/commits for {@link runInCI}
25
+ */
26
+ export type GitRefs = {
27
+ head: GitBranch;
28
+ base?: GitBranch;
29
+ };
30
+ /**
31
+ * API client for {@link runInCI} - adapter for CI provider
32
+ * @see https://github.com/code-pushup/cli/tree/main/packages/ci#provider-api-client
33
+ */
34
+ export type ProviderAPIClient = {
35
+ maxCommentChars: number;
36
+ downloadReportArtifact?: () => Promise<string | null>;
37
+ listComments: () => Promise<Comment[]>;
38
+ updateComment: (id: number, body: string) => Promise<Comment>;
39
+ createComment: (body: string) => Promise<Comment>;
40
+ };
41
+ /**
42
+ * PR comment from {@link ProviderAPIClient}
43
+ */
44
+ export type Comment = {
45
+ id: number;
46
+ body: string;
47
+ url: string;
48
+ };
49
+ /**
50
+ * Git ref (e.g. 'main') and commit sha (e.g. '9d7568265bd5b17d1bb51a6eb6407e0d387058d2')
51
+ */
52
+ export type GitBranch = {
53
+ ref: string;
54
+ sha: string;
55
+ };
56
+ /**
57
+ * Logger instance (e.g. `console`) for reporting progress and problems
58
+ */
59
+ export type Logger = {
60
+ error: (message: string) => void;
61
+ warn: (message: string) => void;
62
+ info: (message: string) => void;
63
+ debug: (message: string) => void;
64
+ };
65
+ /**
66
+ * Resolved return value of {@link runInCI}
67
+ */
68
+ export type RunResult = StandaloneRunResult | MonorepoRunResult;
69
+ /**
70
+ * Resolved return value of {@link runInCI} in standalone mode
71
+ */
72
+ export type StandaloneRunResult = Omit<ProjectRunResult, 'name'> & {
73
+ mode: 'standalone';
74
+ commentId?: number;
75
+ };
76
+ /**
77
+ * Resolved return value of {@link runInCI} in monorepo mode
78
+ */
79
+ export type MonorepoRunResult = {
80
+ mode: 'monorepo';
81
+ projects: ProjectRunResult[];
82
+ commentId?: number;
83
+ diffArtifact?: ArtifactData;
84
+ };
85
+ /**
86
+ * Result of {@link runInCI} for a single project
87
+ */
88
+ export type ProjectRunResult = {
89
+ name: string;
90
+ artifacts: {
91
+ report: ArtifactData;
92
+ diff?: ArtifactData;
93
+ };
94
+ newIssues?: SourceFileIssue[];
95
+ };
96
+ /**
97
+ * Paths to output files from {@link runInCI}, for uploading as job artifact
98
+ */
99
+ export type ArtifactData = {
100
+ rootDir: string;
101
+ files: string[];
102
+ };
@@ -0,0 +1,2 @@
1
+ import type { MonorepoHandlerOptions, MonorepoTool } from './tools';
2
+ export declare function detectMonorepoTool(options: MonorepoHandlerOptions): Promise<MonorepoTool | null>;
@@ -0,0 +1,3 @@
1
+ import type { MonorepoTool, MonorepoToolHandler } from '../tools';
2
+ export declare const MONOREPO_TOOL_HANDLERS: MonorepoToolHandler[];
3
+ export declare function getToolHandler(tool: MonorepoTool): MonorepoToolHandler;
@@ -0,0 +1,2 @@
1
+ import type { MonorepoToolHandler } from '../tools';
2
+ export declare const npmHandler: MonorepoToolHandler;
@@ -0,0 +1,2 @@
1
+ import type { MonorepoToolHandler } from '../tools';
2
+ export declare const nxHandler: MonorepoToolHandler;
@@ -0,0 +1,2 @@
1
+ import type { MonorepoToolHandler } from '../tools';
2
+ export declare const pnpmHandler: MonorepoToolHandler;
@@ -0,0 +1,2 @@
1
+ import type { MonorepoToolHandler } from '../tools';
2
+ export declare const turboHandler: MonorepoToolHandler;
@@ -0,0 +1,2 @@
1
+ import type { MonorepoToolHandler } from '../tools';
2
+ export declare const yarnHandler: MonorepoToolHandler;
@@ -0,0 +1,2 @@
1
+ export { listMonorepoProjects } from './list-projects';
2
+ export { MONOREPO_TOOLS, type MonorepoTool, type ProjectConfig } from './tools';
@@ -0,0 +1,3 @@
1
+ import type { Settings } from '../models';
2
+ import type { ProjectConfig } from './tools';
3
+ export declare function listMonorepoProjects(settings: Settings): Promise<ProjectConfig[]>;
@@ -0,0 +1,17 @@
1
+ import type { PackageJson } from 'type-fest';
2
+ type WorkspacePackage = {
3
+ name: string;
4
+ directory: string;
5
+ packageJson: PackageJson;
6
+ };
7
+ export declare function listPackages(cwd: string, patterns?: string[]): Promise<WorkspacePackage[]>;
8
+ export declare function listWorkspaces(cwd: string): Promise<{
9
+ workspaces: WorkspacePackage[];
10
+ rootPackageJson: PackageJson;
11
+ }>;
12
+ export declare function hasWorkspacesEnabled(cwd: string): Promise<boolean>;
13
+ export declare function readRootPackageJson(cwd: string): Promise<PackageJson>;
14
+ export declare function hasDependency(packageJson: PackageJson, name: string): boolean;
15
+ export declare function hasScript(packageJson: PackageJson, script: string): boolean;
16
+ export declare function hasCodePushUpDependency(packageJson: PackageJson): boolean;
17
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { ProcessObserver } from '@code-pushup/utils';
2
+ export declare const MONOREPO_TOOLS: readonly ["nx", "turbo", "yarn", "pnpm", "npm"];
3
+ export type MonorepoTool = (typeof MONOREPO_TOOLS)[number];
4
+ export type MonorepoToolHandler = {
5
+ tool: MonorepoTool;
6
+ isConfigured: (options: MonorepoHandlerOptions) => Promise<boolean>;
7
+ listProjects: (options: MonorepoHandlerOptions) => Promise<ProjectConfig[]>;
8
+ };
9
+ export type MonorepoHandlerOptions = {
10
+ task: string;
11
+ cwd: string;
12
+ observer?: ProcessObserver;
13
+ };
14
+ export type ProjectConfig = {
15
+ name: string;
16
+ bin: string;
17
+ directory?: string;
18
+ };
@@ -0,0 +1,11 @@
1
+ import { type SimpleGit } from 'simple-git';
2
+ import type { GitRefs, Options, ProviderAPIClient, RunResult } from './models';
3
+ /**
4
+ * Runs Code PushUp in CI environment.
5
+ * @param refs Git branches (head and optional base)
6
+ * @param api API client for given provider
7
+ * @param options Additional options (e.g. monorepo mode)
8
+ * @param git instance of simple-git - useful for testing
9
+ * @returns result of run (standalone or monorepo)
10
+ */
11
+ export declare function runInCI(refs: GitRefs, api: ProviderAPIClient, options?: Options, git?: SimpleGit): Promise<RunResult>;