Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github actions logging #752

Merged
merged 6 commits into from Jul 19, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/util.ts
Expand Up @@ -6,6 +6,7 @@ import chalk from 'chalk';
import { PublicGalleryAPI } from './publicgalleryapi';
import { ISecurityRolesApi } from 'azure-devops-node-api/SecurityRolesApi';
import { Manifest } from './manifest';
import { EOL } from 'os';

const __read = promisify<_read.Options, string>(_read);
export function read(prompt: string, options: _read.Options = {}): Promise<string> {
Expand Down Expand Up @@ -129,14 +130,24 @@ function _log(type: LogMessageType, msg: any, ...args: any[]): void {
args = [LogPrefix[type], msg, ...args];

if (type === LogMessageType.WARNING) {
console.warn(...args);
process.env['GITHUB_ACTIONS'] ? logToGitHubActions('warning', msg) : console.warn(...args);
} else if (type === LogMessageType.ERROR) {
console.error(...args);
process.env['GITHUB_ACTIONS'] ? logToGitHubActions('error', msg) : console.error(...args);
} else {
console.log(...args);
process.env['GITHUB_ACTIONS'] ? logToGitHubActions('info', msg) : console.log(...args);
}
}

function logToGitHubActions(type: string, message: string): void {
const escape = (message: string) => {
return message.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
};

const command = type === 'info' ? message : `::${type}::${escape(message)}`;

process.stdout.write(command + EOL);
}

nhedger marked this conversation as resolved.
Show resolved Hide resolved
export interface LogFn {
(msg: any, ...args: any[]): void;
}
Expand Down