Skip to content

Commit aeb6260

Browse files
committed
fix(ci): always show execute process errors and log stdout if verbose
1 parent ebb4ed5 commit aeb6260

File tree

10 files changed

+193
-61
lines changed

10 files changed

+193
-61
lines changed

packages/ci/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Optionally, you can override default options for further customization:
103103
| `nxProjectsFilter` | `string \| string[]` | `'--with-target={task}'` | Arguments passed to [`nx show projects`](https://nx.dev/nx-api/nx/documents/show#projects), only relevant for Nx in [monorepo mode](#monorepo-mode) [^2] |
104104
| `directory` | `string` | `process.cwd()` | Directory in which Code PushUp CLI should run |
105105
| `config` | `string \| null` | `null` [^1] | Path to config file (`--config` option) |
106-
| `silent` | `boolean` | `false` | Toggles if logs from CLI commands are printed |
106+
| `silent` | `boolean` | `false` | Hides logs from CLI commands are printed |
107107
| `bin` | `string` | `'npx --no-install code-pushup'` | Command for executing Code PushUp CLI |
108108
| `detectNewIssues` | `boolean` | `true` | Toggles if new issues should be detected and returned in `newIssues` property |
109109
| `logger` | `Logger` | `console` | Logger for reporting progress and encountered problems |
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { DEFAULT_PERSIST_FORMAT } from '@code-pushup/models';
2-
import { executeProcess } from '@code-pushup/utils';
2+
import { executeProcess, isVerbose } from '@code-pushup/utils';
33
import type { CommandContext } from '../context.js';
44

55
export async function runCollect({
66
bin,
77
config,
88
directory,
9-
silent,
9+
observer,
1010
}: CommandContext): Promise<void> {
11-
const { stdout } = await executeProcess({
11+
await executeProcess({
1212
command: bin,
1313
args: [
14+
...(isVerbose() ? ['--verbose'] : []),
15+
'--no-progress',
1416
...(config ? [`--config=${config}`] : []),
1517
...DEFAULT_PERSIST_FORMAT.map(format => `--persist.format=${format}`),
1618
],
1719
cwd: directory,
20+
observer,
1821
});
19-
if (!silent) {
20-
console.info(stdout);
21-
}
2222
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_PERSIST_FORMAT } from '@code-pushup/models';
2-
import { executeProcess } from '@code-pushup/utils';
2+
import { executeProcess, isVerbose } from '@code-pushup/utils';
33
import type { CommandContext } from '../context.js';
44

55
type CompareOptions = {
@@ -10,21 +10,21 @@ type CompareOptions = {
1010

1111
export async function runCompare(
1212
{ before, after, label }: CompareOptions,
13-
{ bin, config, directory, silent }: CommandContext,
13+
{ bin, config, directory, observer }: CommandContext,
1414
): Promise<void> {
15-
const { stdout } = await executeProcess({
15+
await executeProcess({
1616
command: bin,
1717
args: [
1818
'compare',
19+
...(isVerbose() ? ['--verbose'] : []),
20+
'--no-progress',
1921
`--before=${before}`,
2022
`--after=${after}`,
2123
...(label ? [`--label=${label}`] : []),
2224
...(config ? [`--config=${config}`] : []),
2325
...DEFAULT_PERSIST_FORMAT.map(format => `--persist.format=${format}`),
2426
],
2527
cwd: directory,
28+
observer,
2629
});
27-
if (!silent) {
28-
console.info(stdout);
29-
}
3030
}

packages/ci/src/lib/cli/commands/merge-diffs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ import {
33
DEFAULT_PERSIST_FILENAME,
44
DEFAULT_PERSIST_OUTPUT_DIR,
55
} from '@code-pushup/models';
6-
import { executeProcess } from '@code-pushup/utils';
6+
import { executeProcess, isVerbose } from '@code-pushup/utils';
77
import type { CommandContext } from '../context.js';
88

99
export async function runMergeDiffs(
1010
files: string[],
11-
{ bin, config, directory, silent }: CommandContext,
11+
{ bin, config, directory, observer }: CommandContext,
1212
): Promise<string> {
1313
const outputDir = path.join(directory, DEFAULT_PERSIST_OUTPUT_DIR);
1414
const filename = `merged-${DEFAULT_PERSIST_FILENAME}`;
1515

16-
const { stdout } = await executeProcess({
16+
await executeProcess({
1717
command: bin,
1818
args: [
1919
'merge-diffs',
20+
...(isVerbose() ? ['--verbose'] : []),
21+
'--no-progress',
2022
...files.map(file => `--files=${file}`),
2123
...(config ? [`--config=${config}`] : []),
2224
`--persist.outputDir=${outputDir}`,
2325
`--persist.filename=${filename}`,
2426
],
2527
cwd: directory,
28+
observer,
2629
});
27-
if (!silent) {
28-
console.info(stdout);
29-
}
3030

3131
return path.join(outputDir, `${filename}-diff.md`);
3232
}

packages/ci/src/lib/cli/commands/print-config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import {
44
executeProcess,
55
generateRandomId,
6+
isVerbose,
67
readJsonFile,
78
stringifyError,
89
} from '@code-pushup/utils';
@@ -12,24 +13,24 @@ export async function runPrintConfig({
1213
bin,
1314
config,
1415
directory,
15-
silent,
16+
observer,
1617
}: CommandContext): Promise<unknown> {
1718
// random file name so command can be run in parallel
1819
const outputFile = `code-pushup.${generateRandomId()}.config.json`;
1920
const outputPath = path.join(directory, outputFile);
2021

21-
const { stdout } = await executeProcess({
22+
await executeProcess({
2223
command: bin,
2324
args: [
2425
...(config ? [`--config=${config}`] : []),
2526
'print-config',
27+
...(isVerbose() ? ['--verbose'] : []),
28+
'--no-progress',
2629
`--output=${outputFile}`,
2730
],
2831
cwd: directory,
32+
observer,
2933
});
30-
if (!silent) {
31-
console.info(stdout);
32-
}
3334

3435
try {
3536
const content = await readJsonFile(outputPath);

packages/ci/src/lib/cli/context.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { type ProcessObserver, isVerbose } from '@code-pushup/utils';
12
import type { Settings } from '../models.js';
23
import type { ProjectConfig } from '../monorepo/index.js';
34

4-
export type CommandContext = Pick<
5-
Settings,
6-
'bin' | 'config' | 'directory' | 'silent'
7-
>;
5+
export type CommandContext = Pick<Settings, 'bin' | 'config' | 'directory'> & {
6+
observer?: ProcessObserver;
7+
};
88

99
export function createCommandContext(
1010
settings: Settings,
@@ -14,6 +14,15 @@ export function createCommandContext(
1414
bin: project?.bin ?? settings.bin,
1515
directory: project?.directory ?? settings.directory,
1616
config: settings.config,
17-
silent: settings.silent,
17+
observer: {
18+
onStderr: stderr => {
19+
console.warn(stderr);
20+
},
21+
...(isVerbose() && {
22+
onStdout: stdout => {
23+
console.info(stdout);
24+
},
25+
}),
26+
},
1827
};
1928
}

packages/ci/src/lib/monorepo/handlers/nx.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,23 @@ export const nxHandler: MonorepoToolHandler = {
2525
);
2626
},
2727

28-
async listProjects(options) {
28+
async listProjects({ cwd, task, nxProjectsFilter, observer }) {
2929
const { stdout } = await executeProcess({
3030
command: 'npx',
3131
args: [
3232
'nx',
3333
'show',
3434
'projects',
35-
...toArray(options.nxProjectsFilter).map(arg =>
36-
arg.replaceAll('{task}', options.task),
37-
),
35+
...toArray(nxProjectsFilter).map(arg => arg.replaceAll('{task}', task)),
3836
'--json',
3937
],
40-
cwd: options.cwd,
41-
observer: options.observer,
38+
cwd,
39+
observer,
4240
});
4341
const projects = parseProjects(stdout);
4442
return projects.toSorted().map(project => ({
4543
name: project,
46-
bin: `npx nx run ${project}:${options.task} --skip-nx-cache --`,
44+
bin: `npx nx run ${project}:${task} --skip-nx-cache --`,
4745
}));
4846
},
4947

packages/ci/src/lib/monorepo/list-projects.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { glob } from 'glob';
22
import path from 'node:path';
3+
import { isVerbose } from '@code-pushup/utils';
34
import type { Logger, Settings } from '../models.js';
45
import { detectMonorepoTool } from './detect-tool.js';
56
import { getToolHandler } from './handlers/index.js';
@@ -95,16 +96,16 @@ function createMonorepoHandlerOptions(
9596
cwd: settings.directory,
9697
parallel: settings.parallel,
9798
nxProjectsFilter: settings.nxProjectsFilter,
98-
...(!settings.silent && {
99-
observer: {
99+
observer: {
100+
onStderr: stderr => {
101+
console.warn(stderr);
102+
},
103+
...(isVerbose() && {
100104
onStdout: stdout => {
101105
console.info(stdout);
102106
},
103-
onStderr: stderr => {
104-
console.warn(stderr);
105-
},
106-
},
107-
}),
107+
}),
108+
},
108109
};
109110
}
110111

packages/ci/src/lib/run-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import type { SimpleGit } from 'simple-git';
44
import type { CoreConfig, Report, ReportsDiff } from '@code-pushup/models';
55
import {
6+
isVerbose,
67
removeUndefinedAndEmptyProps,
78
stringifyError,
89
} from '@code-pushup/utils';
@@ -69,6 +70,10 @@ export async function createRunEnv(
6970
options: Options | undefined,
7071
git: SimpleGit,
7172
): Promise<RunEnv> {
73+
console.log(isVerbose());
74+
// eslint-disable-next-line functional/immutable-data
75+
process.env['CP_VERBOSE'] = options?.silent ? 'false' : 'true';
76+
console.log(isVerbose());
7277
const [head, base] = await Promise.all([
7378
normalizeGitRef(refs.head, git),
7479
refs.base && normalizeGitRef(refs.base, git),

0 commit comments

Comments
 (0)