@@ -49,7 +49,7 @@ export function combineSarifFiles(sarifFiles: string[]): string {
4949
5050// Upload the given payload.
5151// If the request fails then this will retry a small number of times.
52- async function uploadPayload ( payload ) {
52+ async function uploadPayload ( payload ) : Promise < boolean > {
5353 core . info ( 'Uploading results' ) ;
5454
5555 const githubToken = core . getInput ( 'token' ) ;
@@ -71,15 +71,15 @@ async function uploadPayload(payload) {
7171 const statusCode = res . message . statusCode ;
7272 if ( statusCode === 202 ) {
7373 core . info ( "Successfully uploaded results" ) ;
74- return ;
74+ return true ;
7575 }
7676
7777 const requestID = res . message . headers [ "x-github-request-id" ] ;
7878
7979 // On any other status code that's not 5xx mark the upload as failed
8080 if ( ! statusCode || statusCode < 500 || statusCode >= 600 ) {
8181 core . setFailed ( 'Upload failed (' + requestID + '): (' + statusCode + ') ' + await res . readBody ( ) ) ;
82- return ;
82+ return false ;
8383 }
8484
8585 // On a 5xx status code we may retry the request
@@ -97,35 +97,44 @@ async function uploadPayload(payload) {
9797 // and not an error that the user has caused or can fix.
9898 // We avoid marking the job as failed to avoid breaking CI workflows.
9999 core . error ( 'Upload failed (' + requestID + '): (' + statusCode + ') ' + await res . readBody ( ) ) ;
100- return ;
100+ return false ;
101101 }
102102 }
103+
104+ return false ;
103105}
104106
105107// Uploads a single sarif file or a directory of sarif files
106108// depending on what the path happens to refer to.
107- export async function upload ( input : string ) {
109+ // Returns true iff the upload occurred and succeeded
110+ export async function upload ( input : string ) : Promise < boolean > {
108111 if ( fs . lstatSync ( input ) . isDirectory ( ) ) {
109112 const sarifFiles = fs . readdirSync ( input )
110113 . filter ( f => f . endsWith ( ".sarif" ) )
111114 . map ( f => path . resolve ( input , f ) ) ;
112- await uploadFiles ( sarifFiles ) ;
115+ if ( sarifFiles . length === 0 ) {
116+ core . setFailed ( "No SARIF files found to upload in \"" + input + "\"." ) ;
117+ return false ;
118+ }
119+ return await uploadFiles ( sarifFiles ) ;
113120 } else {
114- await uploadFiles ( [ input ] ) ;
121+ return await uploadFiles ( [ input ] ) ;
115122 }
116123}
117124
118125// Uploads the given set of sarif files.
119- async function uploadFiles ( sarifFiles : string [ ] ) {
126+ // Returns true iff the upload occurred and succeeded
127+ async function uploadFiles ( sarifFiles : string [ ] ) : Promise < boolean > {
120128 core . startGroup ( "Uploading results" ) ;
129+ let succeeded = false ;
121130 try {
122131 // Check if an upload has happened before. If so then abort.
123132 // This is intended to catch when the finish and upload-sarif actions
124133 // are used together, and then the upload-sarif action is invoked twice.
125134 const sentinelFile = await getSentinelFilePath ( ) ;
126135 if ( fs . existsSync ( sentinelFile ) ) {
127136 core . info ( "Aborting as an upload has already happened from this job" ) ;
128- return ;
137+ return false ;
129138 }
130139
131140 const commitOid = util . getRequiredEnvParam ( 'GITHUB_SHA' ) ;
@@ -134,7 +143,7 @@ async function uploadFiles(sarifFiles: string[]) {
134143 const analysisName = util . getRequiredEnvParam ( 'GITHUB_WORKFLOW' ) ;
135144 const startedAt = process . env [ sharedEnv . CODEQL_ACTION_STARTED_AT ] ;
136145
137- core . debug ( "Uploading sarif files: " + JSON . stringify ( sarifFiles ) ) ;
146+ core . info ( "Uploading sarif files: " + JSON . stringify ( sarifFiles ) ) ;
138147 let sarifPayload = combineSarifFiles ( sarifFiles ) ;
139148 sarifPayload = fingerprints . addFingerprints ( sarifPayload ) ;
140149
@@ -145,7 +154,7 @@ async function uploadFiles(sarifFiles: string[]) {
145154
146155 if ( Number . isNaN ( workflowRunID ) ) {
147156 core . setFailed ( 'GITHUB_RUN_ID must define a non NaN workflow run ID' ) ;
148- return ;
157+ return false ;
149158 }
150159
151160 let matrix : string | undefined = core . getInput ( 'matrix' ) ;
@@ -168,7 +177,7 @@ async function uploadFiles(sarifFiles: string[]) {
168177 } ) ;
169178
170179 // Make the upload
171- await uploadPayload ( payload ) ;
180+ succeeded = await uploadPayload ( payload ) ;
172181
173182 // Mark that we have made an upload
174183 fs . writeFileSync ( sentinelFile , '' ) ;
@@ -177,4 +186,6 @@ async function uploadFiles(sarifFiles: string[]) {
177186 core . setFailed ( error . message ) ;
178187 }
179188 core . endGroup ( ) ;
189+
190+ return succeeded ;
180191}
0 commit comments