@@ -5,7 +5,7 @@ import YAML from 'js-yaml'
5
5
import {
6
6
getInput ,
7
7
getUserInfo ,
8
- Input ,
8
+ input ,
9
9
log ,
10
10
matchGitArgs ,
11
11
outputs ,
@@ -15,21 +15,25 @@ import {
15
15
16
16
const baseDir = path . join ( process . cwd ( ) , getInput ( 'cwd' ) || '' )
17
17
const git = simpleGit ( { baseDir } )
18
+
19
+ const exitErrors : Error [ ] = [ ]
20
+
18
21
core . info ( `Running in ${ baseDir } ` )
19
22
; ( async ( ) => {
20
23
await checkInputs ( ) . catch ( core . setFailed )
21
24
22
25
core . startGroup ( 'Internal logs' )
23
26
core . info ( '> Staging files...' )
24
27
28
+ const peh = getInput ( 'pathspec_error_handling' )
25
29
if ( getInput ( 'add' ) ) {
26
30
core . info ( '> Adding files...' )
27
- await add ( )
31
+ await add ( peh == 'ignore' ? 'pathspec' : 'none' )
28
32
} else core . info ( '> No files to add.' )
29
33
30
34
if ( getInput ( 'remove' ) ) {
31
35
core . info ( '> Removing files...' )
32
- await remove ( )
36
+ await remove ( peh == 'ignore' ? 'pathspec' : 'none' )
33
37
} else core . info ( '> No files to remove.' )
34
38
35
39
core . info ( '> Checking for uncommitted changes in the git working tree...' )
@@ -71,8 +75,8 @@ core.info(`Running in ${baseDir}`)
71
75
}
72
76
73
77
core . info ( '> Re-staging files...' )
74
- if ( getInput ( 'add' ) ) await add ( { ignoreErrors : true } )
75
- if ( getInput ( 'remove' ) ) await remove ( { ignoreErrors : true } )
78
+ if ( getInput ( 'add' ) ) await add ( 'all' )
79
+ if ( getInput ( 'remove' ) ) await remove ( 'all' )
76
80
77
81
core . info ( '> Creating commit...' )
78
82
await git . commit (
@@ -97,7 +101,7 @@ core.info(`Running in ${baseDir}`)
97
101
if ( getInput ( 'tag' ) ) {
98
102
core . info ( '> Tagging commit...' )
99
103
await git
100
- . tag ( matchGitArgs ( getInput ( 'tag' ) ) , ( err , data ?) => {
104
+ . tag ( matchGitArgs ( getInput ( 'tag' ) || '' ) , ( err , data ?) => {
101
105
if ( data ) setOutput ( 'tagged' , 'true' )
102
106
return log ( err , data )
103
107
} )
@@ -159,7 +163,7 @@ core.info(`Running in ${baseDir}`)
159
163
{
160
164
'--delete' : null ,
161
165
origin : null ,
162
- [ matchGitArgs ( getInput ( 'tag' ) ) . filter (
166
+ [ matchGitArgs ( getInput ( 'tag' ) || '' ) . filter (
163
167
( w ) => ! w . startsWith ( '-' )
164
168
) [ 0 ] ] : null
165
169
} ,
@@ -177,6 +181,14 @@ core.info(`Running in ${baseDir}`)
177
181
core . info ( '> Working tree clean. Nothing to commit.' )
178
182
}
179
183
} ) ( )
184
+ . then ( ( ) => {
185
+ // Check for exit errors
186
+ if ( exitErrors . length == 1 ) throw exitErrors [ 0 ]
187
+ else if ( exitErrors . length > 1 ) {
188
+ exitErrors . forEach ( ( e ) => core . error ( e ) )
189
+ throw 'There have been multiple runtime errors.'
190
+ }
191
+ } )
180
192
. then ( logOutputs )
181
193
. catch ( ( e ) => {
182
194
core . endGroup ( )
@@ -185,11 +197,11 @@ core.info(`Running in ${baseDir}`)
185
197
} )
186
198
187
199
async function checkInputs ( ) {
188
- function setInput ( input : Input , value : string | undefined ) {
200
+ function setInput ( input : input , value : string | undefined ) {
189
201
if ( value ) return ( process . env [ `INPUT_${ input . toUpperCase ( ) } ` ] = value )
190
202
else return delete process . env [ `INPUT_${ input . toUpperCase ( ) } ` ]
191
203
}
192
- function setDefault ( input : Input , value : string ) {
204
+ function setDefault ( input : input , value : string ) {
193
205
if ( ! getInput ( input ) ) setInput ( input , value )
194
206
return getInput ( input )
195
207
}
@@ -219,7 +231,7 @@ async function checkInputs() {
219
231
else core . setFailed ( 'Add input: array length < 1' )
220
232
}
221
233
if ( getInput ( 'remove' ) ) {
222
- const parsed = parseInputArray ( getInput ( 'remove' ) )
234
+ const parsed = parseInputArray ( getInput ( 'remove' ) || '' )
223
235
if ( parsed . length == 1 )
224
236
core . info (
225
237
'Remove input parsed as single string, running 1 git rm command.'
@@ -327,25 +339,16 @@ async function checkInputs() {
327
339
core . info ( `> Running for a PR, the action will use '${ branch } ' as ref.` )
328
340
// #endregion
329
341
330
- // #region signoff
331
- if ( getInput ( 'signoff' ) ) {
332
- const parsed = getInput ( 'signoff' , true )
333
-
334
- if ( parsed === undefined )
335
- throw new Error (
336
- `"${ getInput (
337
- 'signoff'
338
- ) } " is not a valid value for the 'signoff' input: only "true" and "false" are allowed.`
339
- )
340
-
341
- if ( ! parsed ) setInput ( 'signoff' , undefined )
342
-
343
- core . debug (
344
- `Current signoff option: ${ getInput ( 'signoff' ) } (${ typeof getInput (
345
- 'signoff'
346
- ) } )`
342
+ // #region pathspec_error_handling
343
+ const peh_valid = [ 'ignore' , 'exitImmediately' , 'exitAtEnd' ]
344
+ if ( ! peh_valid . includes ( getInput ( 'pathspec_error_handling' ) ) )
345
+ throw new Error (
346
+ `"${ getInput (
347
+ 'pathspec_error_handling'
348
+ ) } " is not a valid value for the 'pathspec_error_handling' input. Valid values are: ${ peh_valid . join (
349
+ ', '
350
+ ) } `
347
351
)
348
- }
349
352
// #endregion
350
353
351
354
// #region pull_strategy
@@ -368,6 +371,27 @@ async function checkInputs() {
368
371
}
369
372
// #endregion
370
373
374
+ // #region signoff
375
+ if ( getInput ( 'signoff' ) ) {
376
+ const parsed = getInput ( 'signoff' , true )
377
+
378
+ if ( parsed === undefined )
379
+ throw new Error (
380
+ `"${ getInput (
381
+ 'signoff'
382
+ ) } " is not a valid value for the 'signoff' input: only "true" and "false" are allowed.`
383
+ )
384
+
385
+ if ( ! parsed ) setInput ( 'signoff' , undefined )
386
+
387
+ core . debug (
388
+ `Current signoff option: ${ getInput ( 'signoff' ) } (${ typeof getInput (
389
+ 'signoff'
390
+ ) } )`
391
+ )
392
+ }
393
+ // #endregion
394
+
371
395
// #region github_token
372
396
if ( ! getInput ( 'github_token' ) )
373
397
core . warning (
@@ -376,9 +400,9 @@ async function checkInputs() {
376
400
// #endregion
377
401
}
378
402
379
- async function add ( { logWarning = true , ignoreErrors = false } = { } ) : Promise <
380
- ( void | Response < void > ) [ ]
381
- > {
403
+ async function add (
404
+ ignoreErrors : 'all' | 'pathspec' | 'none' = 'none'
405
+ ) : Promise < ( void | Response < void > ) [ ] > {
382
406
const input = getInput ( 'add' )
383
407
if ( ! input ) return [ ]
384
408
@@ -391,30 +415,36 @@ async function add({ logWarning = true, ignoreErrors = false } = {}): Promise<
391
415
// If any of them fails, the whole function will return a Promise rejection
392
416
await git
393
417
. add ( matchGitArgs ( args ) , ( err : any , data ?: any ) =>
394
- log ( ignoreErrors ? null : err , data )
418
+ log ( ignoreErrors == 'all' ? null : err , data )
395
419
)
396
420
. catch ( ( e : Error ) => {
397
- if ( ignoreErrors ) return
421
+ // if I should ignore every error, return
422
+ if ( ignoreErrors == 'all' ) return
423
+
424
+ // if it's a pathspec error...
398
425
if (
399
426
e . message . includes ( 'fatal: pathspec' ) &&
400
- e . message . includes ( 'did not match any files' ) &&
401
- logWarning
402
- )
403
- core . warning (
404
- `Add command did not match any file:\n git add ${ args } `
405
- )
406
- else throw e
427
+ e . message . includes ( 'did not match any files' )
428
+ ) {
429
+ if ( ignoreErrors == 'pathspec' ) return
430
+
431
+ const peh = getInput ( 'pathspec_error_handling' ) ,
432
+ err = new Error (
433
+ `Add command did not match any file: git add ${ args } `
434
+ )
435
+ if ( peh == 'exitImmediately' ) throw err
436
+ if ( peh == 'exitAtEnd' ) exitErrors . push ( err )
437
+ } else throw e
407
438
} )
408
439
)
409
440
}
410
441
411
442
return res
412
443
}
413
444
414
- async function remove ( {
415
- logWarning = true ,
416
- ignoreErrors = false
417
- } = { } ) : Promise < ( void | Response < void > ) [ ] > {
445
+ async function remove (
446
+ ignoreErrors : 'all' | 'pathspec' | 'none' = 'none'
447
+ ) : Promise < ( void | Response < void > ) [ ] > {
418
448
const input = getInput ( 'remove' )
419
449
if ( ! input ) return [ ]
420
450
@@ -427,19 +457,26 @@ async function remove({
427
457
// If any of them fails, the whole function will return a Promise rejection
428
458
await git
429
459
. rm ( matchGitArgs ( args ) , ( e : any , d ?: any ) =>
430
- log ( ignoreErrors ? null : e , d )
460
+ log ( ignoreErrors == 'all' ? null : e , d )
431
461
)
432
462
. catch ( ( e : Error ) => {
433
- if ( ignoreErrors ) return
463
+ // if I should ignore every error, return
464
+ if ( ignoreErrors == 'all' ) return
465
+
466
+ // if it's a pathspec error...
434
467
if (
435
468
e . message . includes ( 'fatal: pathspec' ) &&
436
469
e . message . includes ( 'did not match any files' )
437
- )
438
- logWarning &&
439
- core . warning (
470
+ ) {
471
+ if ( ignoreErrors == 'pathspec' ) return
472
+
473
+ const peh = getInput ( 'pathspec_error_handling' ) ,
474
+ err = new Error (
440
475
`Remove command did not match any file:\n git rm ${ args } `
441
476
)
442
- else throw e
477
+ if ( peh == 'exitImmediately' ) throw err
478
+ if ( peh == 'exitAtEnd' ) exitErrors . push ( err )
479
+ } else throw e
443
480
} )
444
481
)
445
482
}
0 commit comments