1- import { error , info , notice , setFailed , setOutput , warning } from '@actions/core' ;
1+ import * as core from '@actions/core' ;
22import { context } from '@actions/github' ;
33import { IClone , IOptions } from '@jscpd/core' ;
44import { Octokit } from '@octokit/rest' ;
@@ -34,12 +34,12 @@ export async function duplicatedCheck(
3434 fs . writeFileSync ( markdownReport , message ) ;
3535 await git . UploadReportToArtifacts ( [ markdownReport , jsonReport ] , REPORT_ARTIFACT_NAME ) ;
3636 const isOverThreshold = checkThreshold ( jsonReport , options . threshold || 0 ) ;
37- jscpdCheckAsError && isOverThreshold ? setFailed ( '❌ DUPLICATED CODE FOUND' ) : warning ( 'DUPLICATED CODE FOUND' , ANNOTATION_OPTIONS ) ;
37+ jscpdCheckAsError && isOverThreshold ? core . setFailed ( '❌ DUPLICATED CODE FOUND' ) : core . warning ( 'DUPLICATED CODE FOUND' , ANNOTATION_OPTIONS ) ;
3838 showAnnotation ( clones , cwd , jscpdCheckAsError && isOverThreshold ) ;
39- setOutput ( 'hasDuplicates' , `${ isOverThreshold } ` ) ;
39+ core . setOutput ( 'hasDuplicates' , `${ isOverThreshold } ` ) ;
4040 } else {
41- setOutput ( 'hasDuplicates' , 'false' ) ;
42- notice ( '✅ NO DUPLICATED CODE FOUND' , ANNOTATION_OPTIONS ) ;
41+ core . setOutput ( 'hasDuplicates' , 'false' ) ;
42+ core . notice ( '✅ NO DUPLICATED CODE FOUND' , ANNOTATION_OPTIONS ) ;
4343 }
4444 await execute ( `rm -rf ${ cwd } /${ REPORT_ARTIFACT_NAME } ` ) ;
4545}
@@ -52,19 +52,21 @@ function getOptions(jscpdConfigPath: string, workspace: string, cwd: string): Pa
5252 output : `${ cwd } /${ REPORT_ARTIFACT_NAME } `
5353 } ;
5454 const options = { ...configOptions , ...defaultOptions } ;
55- info ( `loaded options: ${ inspect ( options ) } ` ) ;
55+ core . startGroup ( '🔎 loaded options' ) ;
56+ core . info ( `${ inspect ( options ) } ` ) ;
57+ core . endGroup ( ) ;
5658 return options ;
5759}
5860
5961function getReportFiles ( cwd : string ) : string [ ] {
6062 const files = fs . readdirSync ( `${ cwd } /${ REPORT_ARTIFACT_NAME } ` ) ;
6163 const filePaths = files . map ( file => `${ cwd } /${ REPORT_ARTIFACT_NAME } /${ file } ` ) ;
62- info ( `reportFiles: ${ filePaths . join ( ',' ) } ` ) ;
64+ core . info ( `reportFiles: ${ filePaths . join ( ',' ) } ` ) ;
6365 return filePaths ;
6466}
6567
6668function checkWorkspace ( workspace : string ) : string {
67- info ( `workspace: ${ workspace } ` ) ;
69+ core . info ( `workspace: ${ workspace } ` ) ;
6870 //check if workspace path is a file
6971 const isFile = fs . existsSync ( workspace ) && fs . lstatSync ( workspace ) . isFile ( ) ;
7072 if ( isFile ) {
@@ -75,7 +77,7 @@ function checkWorkspace(workspace: string): string {
7577}
7678
7779function showAnnotation ( clones : IClone [ ] , cwd : string , isError : boolean ) : void {
78- const show = isError ? error : warning ;
80+ const show = isError ? core . error : core . warning ;
7981 for ( const clone of clones ) {
8082 show (
8183 `${ clone . duplicationA . sourceId . replace ( cwd , '' ) } (${ clone . duplicationA . start . line } -${ clone . duplicationA . end . line } )
@@ -137,7 +139,7 @@ function checkThreshold(jsonReport: string, threshold: number): boolean {
137139 // read json report
138140 const report = JSON . parse ( fs . readFileSync ( jsonReport , 'utf8' ) ) as IJsonReport ;
139141 if ( report . statistics . total . percentage > threshold ) {
140- error ( `DUPLICATED CODE FOUND ${ report . statistics . total . percentage } % IS OVER THRESHOLD ${ threshold } %` , ANNOTATION_OPTIONS ) ;
142+ core . error ( `DUPLICATED CODE FOUND ${ report . statistics . total . percentage } % IS OVER THRESHOLD ${ threshold } %` , ANNOTATION_OPTIONS ) ;
141143 return true ;
142144 }
143145 return false ;
0 commit comments