@@ -6,6 +6,7 @@ import chalk from 'chalk';
6
6
import { PublicGalleryAPI } from './publicgalleryapi' ;
7
7
import { ISecurityRolesApi } from 'azure-devops-node-api/SecurityRolesApi' ;
8
8
import { Manifest } from './manifest' ;
9
+ import { EOL } from 'os' ;
9
10
10
11
const __read = promisify < _read . Options , string > ( _read ) ;
11
12
export function read ( prompt : string , options : _read . Options = { } ) : Promise < string > {
@@ -129,14 +130,31 @@ function _log(type: LogMessageType, msg: any, ...args: any[]): void {
129
130
args = [ LogPrefix [ type ] , msg , ...args ] ;
130
131
131
132
if ( type === LogMessageType . WARNING ) {
132
- console . warn ( ...args ) ;
133
+ process . env [ 'GITHUB_ACTIONS' ] ? logToGitHubActions ( 'warning' , msg ) : console . warn ( ...args ) ;
133
134
} else if ( type === LogMessageType . ERROR ) {
134
- console . error ( ...args ) ;
135
+ process . env [ 'GITHUB_ACTIONS' ] ? logToGitHubActions ( 'error' , msg ) : console . error ( ...args ) ;
135
136
} else {
136
- console . log ( ...args ) ;
137
+ process . env [ 'GITHUB_ACTIONS' ] ? logToGitHubActions ( 'info' , msg ) : console . log ( ...args ) ;
137
138
}
138
139
}
139
140
141
+ const EscapeCharacters = new Map ( [
142
+ [ '%' , '%25' ] ,
143
+ [ '\r' , '%0D' ] ,
144
+ [ '\n' , '%0A' ] ,
145
+ ] ) ;
146
+
147
+ const EscapeRegex = new RegExp ( `[${ [ ...EscapeCharacters . keys ( ) ] . join ( '' ) } ]` , 'g' ) ;
148
+
149
+ function escapeGitHubActionsMessage ( message : string ) : string {
150
+ return message . replace ( EscapeRegex , c => EscapeCharacters . get ( c ) ?? c ) ;
151
+ }
152
+
153
+ function logToGitHubActions ( type : string , message : string ) : void {
154
+ const command = type === 'info' ? message : `::${ type } ::${ escapeGitHubActionsMessage ( message ) } ` ;
155
+ process . stdout . write ( command + EOL ) ;
156
+ }
157
+
140
158
export interface LogFn {
141
159
( msg : any , ...args : any [ ] ) : void ;
142
160
}
0 commit comments