From 713e0697619ea7e007d26bac953eece84eaa41ab Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Sat, 9 Nov 2024 01:31:12 +0100 Subject: [PATCH 1/4] feature: add new --print-log-file-paths parameter --- .../cli/scriptActions/PhasedScriptAction.ts | 8 +++++++- .../OperationResultSummarizerPlugin.ts | 20 +++++++++++++++---- .../test/OperationExecutionManager.test.ts | 10 +++++----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts b/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts index 6eed33d9d00..0e2de297a66 100644 --- a/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts +++ b/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts @@ -144,6 +144,7 @@ export class PhasedScriptAction extends BaseScriptAction { private readonly _changedProjectsOnly: CommandLineFlagParameter | undefined; private readonly _selectionParameters: SelectionParameterSet; + private readonly _printLogFilePathsParameter: CommandLineFlagParameter; private readonly _verboseParameter: CommandLineFlagParameter; private readonly _parallelismParameter: CommandLineStringParameter | undefined; private readonly _ignoreHooksParameter: CommandLineFlagParameter; @@ -220,6 +221,11 @@ export class PhasedScriptAction extends BaseScriptAction { includeSubspaceSelector: false }); + this._printLogFilePathsParameter = this.defineFlagParameter({ + parameterLongName: '--print-log-file-paths', + description: 'Display log file paths for projects that failed to build' + }); + this._verboseParameter = this.defineFlagParameter({ parameterLongName: '--verbose', parameterShortName: '-v', @@ -367,7 +373,7 @@ export class PhasedScriptAction extends BaseScriptAction { } // Enable the standard summary - new OperationResultSummarizerPlugin(terminal).apply(this.hooks); + new OperationResultSummarizerPlugin(terminal, this._printLogFilePathsParameter.value).apply(this.hooks); const { hooks: sessionHooks } = this.rushSession; if (sessionHooks.runAnyPhasedCommand.isUsed()) { diff --git a/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts b/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts index ec9a3cde168..7dd6a791063 100644 --- a/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts +++ b/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts @@ -28,16 +28,18 @@ type IOperationsByStatus = Map; */ export class OperationResultSummarizerPlugin implements IPhasedCommandPlugin { private readonly _terminal: ITerminal; + private readonly _shouldPrintLogFilePaths: boolean; - public constructor(terminal: ITerminal) { + public constructor(terminal: ITerminal, shouldPrintLogFilePaths: boolean) { this._terminal = terminal; + this._shouldPrintLogFilePaths = shouldPrintLogFilePaths; } public apply(hooks: PhasedCommandHooks): void { hooks.afterExecuteOperations.tap( PLUGIN_NAME, (result: IExecutionResult, context: ICreateOperationsContext): void => { - _printOperationStatus(this._terminal, result); + _printOperationStatus(this._terminal, this._shouldPrintLogFilePaths, result); } ); } @@ -47,7 +49,7 @@ export class OperationResultSummarizerPlugin implements IPhasedCommandPlugin { * Prints out a report of the status of each project * @internal */ -export function _printOperationStatus(terminal: ITerminal, result: IExecutionResult): void { +export function _printOperationStatus(terminal: ITerminal, shouldPrintLogFilePaths: boolean, result: IExecutionResult): void { const { operationResults } = result; const operationsByStatus: IOperationsByStatus = new Map(); @@ -119,6 +121,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes writeDetailedSummary( terminal, + shouldPrintLogFilePaths, OperationStatus.SuccessWithWarning, operationsByStatus, Colorize.yellow, @@ -133,7 +136,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes 'These operations were blocked by dependencies that failed:' ); - writeDetailedSummary(terminal, OperationStatus.Failure, operationsByStatus, Colorize.red); + writeDetailedSummary(terminal, shouldPrintLogFilePaths, OperationStatus.Failure, operationsByStatus, Colorize.red); terminal.writeLine(''); @@ -196,6 +199,7 @@ function writeCondensedSummary( function writeDetailedSummary( terminal: ITerminal, + shouldPrintLogFilePaths: boolean, status: OperationStatus, operationsByStatus: IOperationsByStatus, headingColor: (text: string) => string, @@ -253,6 +257,14 @@ function writeDetailedSummary( terminal.write(details); } + if (shouldPrintLogFilePaths) { + if (operationResult.status === OperationStatus.Failure && operationResult.logFilePaths !== undefined) { + terminal.writeLine(''); + terminal.writeLine(Colorize.gray(`stdout: ${operationResult.logFilePaths.text}`)); + terminal.writeLine(Colorize.gray(`stderr: ${operationResult.logFilePaths.error}`)); + } + } + terminal.writeLine(''); } } diff --git a/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts b/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts index c994c801158..f3b0901cc95 100644 --- a/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts +++ b/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts @@ -88,7 +88,7 @@ describe(OperationExecutionManager.name, () => { ); const result: IExecutionResult = await executionManager.executeAsync(); - _printOperationStatus(mockTerminal, result); + _printOperationStatus(mockTerminal, false, result); expect(result.status).toEqual(OperationStatus.Failure); expect(result.operationResults.size).toEqual(1); const firstResult: IOperationExecutionResult = result.operationResults.values().next().value; @@ -110,7 +110,7 @@ describe(OperationExecutionManager.name, () => { ); const result: IExecutionResult = await executionManager.executeAsync(); - _printOperationStatus(mockTerminal, result); + _printOperationStatus(mockTerminal, false, result); expect(result.status).toEqual(OperationStatus.Failure); expect(result.operationResults.size).toEqual(1); const firstResult: IOperationExecutionResult = result.operationResults.values().next().value; @@ -184,7 +184,7 @@ describe(OperationExecutionManager.name, () => { ); const result: IExecutionResult = await executionManager.executeAsync(); - _printOperationStatus(mockTerminal, result); + _printOperationStatus(mockTerminal, false, result); expect(result.status).toEqual(OperationStatus.SuccessWithWarning); expect(result.operationResults.size).toEqual(1); const firstResult: IOperationExecutionResult = result.operationResults.values().next().value; @@ -223,7 +223,7 @@ describe(OperationExecutionManager.name, () => { ); const result: IExecutionResult = await executionManager.executeAsync(); - _printOperationStatus(mockTerminal, result); + _printOperationStatus(mockTerminal, false, result); expect(result.status).toEqual(OperationStatus.Success); expect(result.operationResults.size).toEqual(1); const firstResult: IOperationExecutionResult = result.operationResults.values().next().value; @@ -250,7 +250,7 @@ describe(OperationExecutionManager.name, () => { const result: IExecutionResult = await executionManager.executeAsync(); _printTimeline({ terminal: mockTerminal, result, cobuildConfiguration: undefined }); - _printOperationStatus(mockTerminal, result); + _printOperationStatus(mockTerminal, false, result); const allMessages: string = mockWritable.getAllOutput(); expect(allMessages).toContain('Build step 1'); expect(allMessages).toContain('Warning: step 1 succeeded with warnings'); From cb6ea32b2fe8424ba5a4be696258cdc6f9909feb Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Sat, 9 Nov 2024 01:31:39 +0100 Subject: [PATCH 2/4] chore: rush change --- ...improvements-vscode1-proposal_2024-11-09-00-30.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/summarizer-improvements-vscode1-proposal_2024-11-09-00-30.json diff --git a/common/changes/@microsoft/rush/summarizer-improvements-vscode1-proposal_2024-11-09-00-30.json b/common/changes/@microsoft/rush/summarizer-improvements-vscode1-proposal_2024-11-09-00-30.json new file mode 100644 index 00000000000..9a4d2509d43 --- /dev/null +++ b/common/changes/@microsoft/rush/summarizer-improvements-vscode1-proposal_2024-11-09-00-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Add new --print-log-file-paths parameter for rush commands that prints log file paths after failed action summaries", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file From 14cf2afe8876ed6d6457b9e0c9e342f54926b459 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Sat, 9 Nov 2024 01:38:31 +0100 Subject: [PATCH 3/4] chore: rush test --update-snapshots --- .../RushCommandLine.test.ts.snap | 24 +++++++++++++++++++ .../CommandLineHelp.test.ts.snap | 22 ++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap index f36ce6efc6f..425465293b5 100644 --- a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap @@ -1228,6 +1228,14 @@ Object { "required": false, "shortName": undefined, }, + Object { + "description": "Display log file paths for projects that failed to build", + "environmentVariable": undefined, + "kind": "Flag", + "longName": "--print-log-file-paths", + "required": false, + "shortName": undefined, + }, Object { "description": "Display the logs during the build, rather than just displaying the build status summary", "environmentVariable": undefined, @@ -1358,6 +1366,14 @@ Object { "required": false, "shortName": undefined, }, + Object { + "description": "Display log file paths for projects that failed to build", + "environmentVariable": undefined, + "kind": "Flag", + "longName": "--print-log-file-paths", + "required": false, + "shortName": undefined, + }, Object { "description": "Display the logs during the build, rather than just displaying the build status summary", "environmentVariable": undefined, @@ -1491,6 +1507,14 @@ Object { "required": false, "shortName": undefined, }, + Object { + "description": "Display log file paths for projects that failed to build", + "environmentVariable": undefined, + "kind": "Flag", + "longName": "--print-log-file-paths", + "required": false, + "shortName": undefined, + }, Object { "description": "Display the logs during the build, rather than just displaying the build status summary", "environmentVariable": undefined, diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 007ff234fc5..355dfd6e832 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -154,8 +154,9 @@ exports[`CommandLineHelp prints the help for each action: build 1`] = ` [-t PROJECT] [-T PROJECT] [-f PROJECT] [-o PROJECT] [-i PROJECT] [-I PROJECT] [--to-version-policy VERSION_POLICY_NAME] - [--from-version-policy VERSION_POLICY_NAME] [-v] [-c] - [--ignore-hooks] [-s] [-m] + [--from-version-policy VERSION_POLICY_NAME] + [--print-log-file-paths] [-v] [-c] [--ignore-hooks] [-s] + [-m] This command is similar to \\"rush rebuild\\", except that \\"rush build\\" performs @@ -267,6 +268,9 @@ Optional arguments: each of the projects belonging to VERSION_POLICY_NAME. For details, refer to the website article \\"Selecting subsets of projects\\". + --print-log-file-paths + Display log file paths for projects that failed to + build -v, --verbose Display the logs during the build, rather than just displaying the build status summary -c, --changed-projects-only @@ -431,8 +435,8 @@ exports[`CommandLineHelp prints the help for each action: import-strings 1`] = ` [-t PROJECT] [-T PROJECT] [-f PROJECT] [-o PROJECT] [-i PROJECT] [-I PROJECT] [--to-version-policy VERSION_POLICY_NAME] - [--from-version-policy VERSION_POLICY_NAME] [-v] - [--ignore-hooks] + [--from-version-policy VERSION_POLICY_NAME] + [--print-log-file-paths] [-v] [--ignore-hooks] [--locale {en-us,fr-fr,es-es,zh-cn}] @@ -536,6 +540,9 @@ Optional arguments: each of the projects belonging to VERSION_POLICY_NAME. For details, refer to the website article \\"Selecting subsets of projects\\". + --print-log-file-paths + Display log file paths for projects that failed to + build -v, --verbose Display the logs during the build, rather than just displaying the build status summary --ignore-hooks Skips execution of the \\"eventHooks\\" scripts defined @@ -1029,8 +1036,8 @@ exports[`CommandLineHelp prints the help for each action: rebuild 1`] = ` [-t PROJECT] [-T PROJECT] [-f PROJECT] [-o PROJECT] [-i PROJECT] [-I PROJECT] [--to-version-policy VERSION_POLICY_NAME] - [--from-version-policy VERSION_POLICY_NAME] [-v] - [--ignore-hooks] [-s] [-m] + [--from-version-policy VERSION_POLICY_NAME] + [--print-log-file-paths] [-v] [--ignore-hooks] [-s] [-m] This command assumes that the package.json file for each project contains a @@ -1139,6 +1146,9 @@ Optional arguments: each of the projects belonging to VERSION_POLICY_NAME. For details, refer to the website article \\"Selecting subsets of projects\\". + --print-log-file-paths + Display log file paths for projects that failed to + build -v, --verbose Display the logs during the build, rather than just displaying the build status summary --ignore-hooks Skips execution of the \\"eventHooks\\" scripts defined From e8fd1ebe985690b9dbc335aa8dda5ba2c3c97626 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Sat, 9 Nov 2024 18:57:42 +0100 Subject: [PATCH 4/4] feature: print only main log file path as it contains both stdout and stderr --- .../src/logic/operations/OperationResultSummarizerPlugin.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts b/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts index 7dd6a791063..1ebd44adc2c 100644 --- a/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts +++ b/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts @@ -260,8 +260,7 @@ function writeDetailedSummary( if (shouldPrintLogFilePaths) { if (operationResult.status === OperationStatus.Failure && operationResult.logFilePaths !== undefined) { terminal.writeLine(''); - terminal.writeLine(Colorize.gray(`stdout: ${operationResult.logFilePaths.text}`)); - terminal.writeLine(Colorize.gray(`stderr: ${operationResult.logFilePaths.error}`)); + terminal.writeLine(Colorize.gray(`log file: ${operationResult.logFilePaths.text}`)); } }