feat(core): add log lines grouping for GH Actions (#21357)
This commit is contained in:
parent
6e4bf8cbf2
commit
7739ce013b
@ -223,8 +223,7 @@ export async function createRunOneDynamicOutputRenderer({
|
||||
|
||||
lifeCycle.printTaskTerminalOutput = (task, cacheStatus, terminalOutput) => {
|
||||
if (task.target.project === initiatingProject) {
|
||||
output.logCommand(task.id, cacheStatus);
|
||||
process.stdout.write(terminalOutput);
|
||||
output.logCommandOutput(task.id, cacheStatus, terminalOutput);
|
||||
} else {
|
||||
tasksToTerminalOutputs[task.id] = terminalOutput;
|
||||
}
|
||||
@ -254,8 +253,11 @@ export async function createRunOneDynamicOutputRenderer({
|
||||
clearRenderInterval();
|
||||
renderDependentTargets(false);
|
||||
output.addVerticalSeparator('red');
|
||||
output.logCommand(t.task.id, t.status);
|
||||
process.stdout.write(tasksToTerminalOutputs[t.task.id]);
|
||||
output.logCommandOutput(
|
||||
t.task.id,
|
||||
t.status,
|
||||
tasksToTerminalOutputs[t.task.id]
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -15,8 +15,7 @@ export class EmptyTerminalOutputLifeCycle implements LifeCycle {
|
||||
cacheStatus === 'skipped'
|
||||
) {
|
||||
const args = getPrintableCommandArgsForTask(task);
|
||||
output.logCommand(args.join(' '), cacheStatus);
|
||||
process.stdout.write(terminalOutput);
|
||||
output.logCommandOutput(args.join(' '), cacheStatus, terminalOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,6 @@ export class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle {
|
||||
terminalOutput: string
|
||||
) {
|
||||
const args = getPrintableCommandArgsForTask(task);
|
||||
output.logCommand(args.join(' '), cacheStatus);
|
||||
process.stdout.write(terminalOutput);
|
||||
output.logCommandOutput(args.join(' '), cacheStatus, terminalOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +149,6 @@ export class StaticRunManyTerminalOutputLifeCycle implements LifeCycle {
|
||||
terminalOutput: string
|
||||
) {
|
||||
const args = getPrintableCommandArgsForTask(task);
|
||||
output.logCommand(args.join(' '), cacheStatus);
|
||||
process.stdout.write(terminalOutput);
|
||||
output.logCommandOutput(args.join(' '), cacheStatus, terminalOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,8 +116,7 @@ export class StaticRunOneTerminalOutputLifeCycle implements LifeCycle {
|
||||
task.target.project === this.initiatingProject
|
||||
) {
|
||||
const args = getPrintableCommandArgsForTask(task);
|
||||
output.logCommand(args.join(' '), status);
|
||||
process.stdout.write(terminalOutput);
|
||||
output.logCommandOutput(args.join(' '), status, terminalOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ import * as readline from 'readline';
|
||||
import { isCI } from './is-ci';
|
||||
import { TaskStatus } from '../tasks-runner/tasks-runner';
|
||||
|
||||
const GH_GROUP_PREFIX = '::group::';
|
||||
const GH_GROUP_SUFFIX = '::endgroup::';
|
||||
|
||||
export interface CLIErrorMessageConfig {
|
||||
title: string;
|
||||
bodyLines?: string[];
|
||||
@ -228,15 +231,54 @@ class CLIOutput {
|
||||
|
||||
logCommand(message: string, taskStatus?: TaskStatus) {
|
||||
this.addNewline();
|
||||
const commandOutput =
|
||||
chalk.dim('> ') + this.formatCommand(this.normalizeMessage(message));
|
||||
const commandOutputWithStatus = this.addTaskStatus(
|
||||
taskStatus,
|
||||
commandOutput
|
||||
this.writeToStdOut(this.getCommandWithStatus(message, taskStatus));
|
||||
this.addNewline();
|
||||
this.addNewline();
|
||||
}
|
||||
|
||||
logCommandOutput(message: string, taskStatus: TaskStatus, output: string) {
|
||||
let commandOutputWithStatus = this.getCommandWithStatus(
|
||||
message,
|
||||
taskStatus
|
||||
);
|
||||
if (process.env.GITHUB_ACTIONS) {
|
||||
const icon = this.getStatusIcon(taskStatus);
|
||||
commandOutputWithStatus = `${GH_GROUP_PREFIX}${icon} ${commandOutputWithStatus}`;
|
||||
}
|
||||
|
||||
this.addNewline();
|
||||
this.writeToStdOut(commandOutputWithStatus);
|
||||
this.addNewline();
|
||||
this.addNewline();
|
||||
this.writeToStdOut(output);
|
||||
|
||||
if (process.env.GITHUB_ACTIONS) {
|
||||
this.writeToStdOut(GH_GROUP_SUFFIX);
|
||||
}
|
||||
}
|
||||
|
||||
private getCommandWithStatus(
|
||||
message: string,
|
||||
taskStatus: TaskStatus
|
||||
): string {
|
||||
const commandOutput =
|
||||
chalk.dim('> ') + this.formatCommand(this.normalizeMessage(message));
|
||||
return this.addTaskStatus(taskStatus, commandOutput);
|
||||
}
|
||||
|
||||
private getStatusIcon(taskStatus: TaskStatus) {
|
||||
switch (taskStatus) {
|
||||
case 'success':
|
||||
return '✔️';
|
||||
case 'failure':
|
||||
return '❌';
|
||||
case 'skipped':
|
||||
case 'local-cache-kept-existing':
|
||||
return '⏩';
|
||||
case 'local-cache':
|
||||
case 'remote-cache':
|
||||
return '🔁';
|
||||
}
|
||||
}
|
||||
|
||||
private normalizeMessage(message: string) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user