@@ -27,6 +27,10 @@ type ExpandWith = {
2727} ;
2828
2929export class Utils {
30+ static bashMulti ( scripts : string [ ] , cwd = process . cwd ( ) ) : Promise < { stdout : string ; stderr : string ; exitCode : number } > {
31+ return execa ( scripts . join ( " && \\" ) , { shell : "bash" , cwd} ) ;
32+ }
33+
3034 static bash ( shellScript : string , cwd = process . cwd ( ) ) : Promise < { stdout : string ; stderr : string ; exitCode : number } > {
3135 return execa ( shellScript , { shell : "bash" , cwd} ) ;
3236 }
@@ -225,16 +229,19 @@ export class Utils {
225229 }
226230 const _rhs = JSON . stringify ( rhs ) ; // JSON.stringify for escaping `"`
227231 const containsNonEscapedSlash = / (?< ! \\ ) \/ / . test ( _rhs ) ;
228- assert ( ! containsNonEscapedSlash , `Error attempting to evaluate the following rules:
229- rules:
230- - if: '${ expandedEvalStr } '
231- as rhs contains unescaped \`/\`` ) ;
232+ const assertMsg = [
233+ "Error attempting to evaluate the following rules:" ,
234+ " rules:" ,
235+ ` - if: '${ expandedEvalStr } '` ,
236+ "as rhs contains unescaped quote" ,
237+ ] ;
238+ assert ( ! containsNonEscapedSlash , assertMsg . join ( "\n" ) ) ;
232239 return `.match(new RE2(${ _rhs } , "${ flags } ")) ${ _operator } null${ remainingTokens } ` ;
233240 } ) ;
234241
235242 // Scenario when RHS is surrounded by single/double-quotes
236243 // https://regexr.com/85t0g
237- const pattern2 = / \s * (?< operator > = ~ | ! ~ ) \s * (?< quote_type > [ " ' ] ) (?< rhs > (?: \\ .| [ ^ \\ ] ) * ?) \2/ g;
244+ const pattern2 = / \s * (?< operator > = ~ | ! ~ ) \s * ( [ " ' ] ) (?< rhs > (?: \\ .| [ ^ \\ ] ) * ?) \2/ g;
238245 evalStr = evalStr . replace ( pattern2 , ( _ , operator , __ , rhs ) => {
239246 let _operator ;
240247 switch ( operator ) {
@@ -248,8 +255,11 @@ as rhs contains unescaped \`/\``);
248255 throw operator ;
249256 }
250257
251- assert ( ( / \/ ( .* ) \/ ( \w * ) / . test ( rhs ) ) , ( `RHS (${ rhs } ) must be a regex pattern. Do not rely on this behavior!
252- Refer to https://docs.gitlab.com/ee/ci/jobs/job_rules.html#unexpected-behavior-from-regular-expression-matching-with- for more info...` ) ) ;
258+ const assertMsg = [
259+ "RHS (${rhs}) must be a regex pattern. Do not rely on this behavior!" ,
260+ "Refer to https://docs.gitlab.com/ee/ci/jobs/job_rules.html#unexpected-behavior-from-regular-expression-matching-with- for more info..." ,
261+ ] ;
262+ assert ( ( / \/ ( .* ) \/ ( \w * ) / . test ( rhs ) ) , assertMsg . join ( "\n" ) ) ;
253263
254264 const regex = / \/ (?< pattern > .* ) \/ (?< flags > [ i g m s u y ] * ) / ;
255265 const _rhs = rhs . replace ( regex , ( _ : string , pattern : string , flags : string ) => {
@@ -270,15 +280,16 @@ Refer to https://docs.gitlab.com/ee/ci/jobs/job_rules.html#unexpected-behavior-f
270280 res = ( 0 , eval ) ( evalStr ) ; // https://esbuild.github.io/content-types/#direct-eval
271281 delete ( global as any ) . RE2 ; // Cleanup
272282 } catch ( err ) {
273- assert ( false , ( `
274- Error attempting to evaluate the following rules:
275- rules:
276- - if: '${ expandedEvalStr } '
277- as
278- \`\`\`javascript
279- ${ evalStr }
280- \`\`\`
281- ` ) ) ;
283+ const assertMsg = [
284+ "Error attempting to evaluate the following rules:" ,
285+ " rules:" ,
286+ ` - if: '${ expandedEvalStr } '` ,
287+ "as" ,
288+ "```javascript" ,
289+ `${ evalStr } ` ,
290+ "```" ,
291+ ] ;
292+ assert ( false , assertMsg . join ( "\n" ) ) ;
282293 }
283294 return Boolean ( res ) ;
284295 }
@@ -303,8 +314,8 @@ ${evalStr}
303314 if ( ! Array . isArray ( ruleChanges ) ) ruleChanges = ruleChanges . paths ;
304315
305316 // NOTE: https://docs.gitlab.com/ee/ci/yaml/#ruleschanges
306- // Glob patterns are interpreted with Ruby's [File.fnmatch](https://docs.ruby-lang.org/en/master/File.html#method-c-fnmatch)
307- // with the flags File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB.
317+ // Glob patterns are interpreted with Ruby's [File.fnmatch](https://docs.ruby-lang.org/en/master/File.html#method-c-fnmatch)
318+ // with the flags File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB.
308319 return micromatch . some ( GitData . changedFiles ( `origin/${ defaultBranch } ` ) , ruleChanges , {
309320 nonegate : true ,
310321 noextglob : true ,
0 commit comments