@@ -385,9 +385,26 @@ const generateConclusion = function (failureCount, warningCount, noticeCount) {
385
385
return conclusion
386
386
}
387
387
388
+ const booleanValue = function ( input ) {
389
+ return / ^ \s * ( t r u e | 1 ) \s * $ / i. test ( input )
390
+ }
391
+
392
+ const readAnnotationsFile = async function ( inputPath ) {
393
+ const ignoreMissingFileValue = core . getInput ( 'ignore-missing-file' , { required : false } ) || 'true'
394
+ const ignoreMissingFile = booleanValue ( ignoreMissingFileValue )
395
+ try {
396
+ const inputContent = await fs . readFile ( inputPath , 'utf8' )
397
+ return JSON . parse ( inputContent )
398
+ } catch ( err ) {
399
+ if ( err . code === 'ENOENT' && ignoreMissingFile ) {
400
+ core . info ( `Ignoring missing file at '${ inputPath } ' because \'ignore-missing-file\' is true` )
401
+ } else {
402
+ throw err
403
+ }
404
+ }
405
+ }
406
+
388
407
async function run ( ) {
389
- const ignoreUnauthorizedErrorValue = core . getInput ( 'ignore-unauthorized-error' , { required : false } ) || 'false'
390
- const ignoreUnauthorizedError = / ^ \s * ( t r u e | 1 ) \s * $ / i. test ( ignoreUnauthorizedErrorValue )
391
408
try {
392
409
const repoToken = core . getInput ( 'repo-token' , { required : true } )
393
410
const inputPath = core . getInput ( 'input' , { required : true } )
@@ -398,8 +415,7 @@ async function run () {
398
415
const owner = github . context . repo . owner
399
416
const repo = github . context . repo . repo
400
417
401
- const inputContent = await fs . readFile ( inputPath , 'utf8' )
402
- const annotations = JSON . parse ( inputContent )
418
+ const annotations = await readAnnotationsFile ( inputPath )
403
419
const checkRunId = await createCheck ( octokit , owner , repo , title , ref )
404
420
const { failureCount, warningCount, noticeCount } = stats ( annotations )
405
421
core . info ( `Found ${ failureCount } failure(s), ${ warningCount } warning(s) and ${ noticeCount } notice(s)` )
@@ -428,6 +444,8 @@ async function run () {
428
444
await updateCheck ( octokit , owner , repo , checkRunId , conclusion , title , summary , annotations )
429
445
}
430
446
} catch ( error ) {
447
+ const ignoreUnauthorizedErrorValue = core . getInput ( 'ignore-unauthorized-error' , { required : false } ) || 'false'
448
+ const ignoreUnauthorizedError = booleanValue ( ignoreUnauthorizedErrorValue )
431
449
if ( error . name === 'GitHubApiUnauthorizedError' && ignoreUnauthorizedError ) {
432
450
core . info ( `Ignoring the following unauthorized error because 'ignore-unauthorized-error' is true: ${ error } ` )
433
451
return
0 commit comments