Skip to content

Commit ad9debf

Browse files
committed
feat(ci): use nx cache friendly output path for print-config command
1 parent 2135c9b commit ad9debf

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { rm } from 'node:fs/promises';
22
import path from 'node:path';
33
import {
44
executeProcess,
5-
generateRandomId,
65
isVerbose,
76
readJsonFile,
87
stringifyError,
@@ -13,11 +12,19 @@ export async function runPrintConfig({
1312
bin,
1413
config,
1514
directory,
15+
project,
1616
observer,
1717
}: CommandContext): Promise<unknown> {
18-
// random file name so command can be run in parallel
19-
const outputFile = `code-pushup.${generateRandomId()}.config.json`;
20-
const outputPath = path.resolve(directory, outputFile);
18+
// unique file name per project so command can be run in parallel
19+
const outputFile = ['code-pushup', 'config', project, 'json']
20+
.filter(Boolean)
21+
.join('.');
22+
const outputPath =
23+
project && directory === process.cwd()
24+
? // cache-friendly path for Nx projects (assuming {workspaceRoot}/.code-pushup/{projectName})
25+
path.join(process.cwd(), '.code-pushup', project, outputFile)
26+
: // absolute path
27+
path.resolve(directory, '.code-pushup', outputFile);
2128

2229
await executeProcess({
2330
command: bin,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Settings } from '../models.js';
44
import type { ProjectConfig } from '../monorepo/index.js';
55

66
export type CommandContext = Pick<Settings, 'bin' | 'config' | 'directory'> & {
7+
project?: string;
78
observer?: ProcessObserver;
89
};
910

@@ -15,6 +16,7 @@ export function createCommandContext(
1516
bin: project?.bin ?? bin,
1617
directory: project?.directory ?? directory,
1718
config,
19+
...(project?.name && { project: project.name }),
1820
observer: createExecutionObserver({ silent }),
1921
};
2022
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('createCommandContext', () => {
6363
bin: 'yarn code-pushup',
6464
directory: '/test/ui',
6565
config: null,
66+
project: 'ui',
6667
observer: expectedObserver,
6768
});
6869
});

packages/ci/src/lib/run.integration.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ describe('runInCI', () => {
132132
?.find(arg => arg.startsWith('--output='))
133133
?.split('=')[1];
134134
if (outputFile) {
135-
await writeFile(path.resolve(cwd as string, outputFile), content);
135+
const outputPath = path.resolve(cwd as string, outputFile);
136+
await mkdir(path.dirname(outputPath), { recursive: true });
137+
await writeFile(outputPath, content);
136138
} else {
137139
stdout = content;
138140
}

0 commit comments

Comments
 (0)