11import * as core from '@actions/core' ;
22import * as http from '@actions/http-client' ;
33import * as auth from '@actions/http-client/auth' ;
4- import * as io from '@actions/io' ;
54import fileUrl from 'file-url' ;
65import * as fs from 'fs' ;
76import * as path from 'path' ;
@@ -11,19 +10,6 @@ import * as fingerprints from './fingerprints';
1110import * as sharedEnv from './shared-environment' ;
1211import * as util from './util' ;
1312
14- // Construct the location of the sentinel file for detecting multiple uploads.
15- // The returned location should be writable.
16- async function getSentinelFilePath ( ) : Promise < string > {
17- // Use the temp dir instead of placing next to the sarif file because of
18- // issues with docker actions. The directory containing the sarif file
19- // may not be writable by us.
20- const uploadsTmpDir = path . join ( process . env [ 'RUNNER_TEMP' ] || '/tmp/codeql-action' , 'uploads' ) ;
21- await io . mkdirP ( uploadsTmpDir ) ;
22- // Hash the absolute path so we'll behave correctly in the unlikely
23- // scenario a file is referenced twice with different paths.
24- return path . join ( uploadsTmpDir , 'codeql-action-upload-sentinel' ) ;
25- }
26-
2713// Takes a list of paths to sarif files and combines them together,
2814// returning the contents of the combined sarif file.
2915export function combineSarifFiles ( sarifFiles : string [ ] ) : string {
@@ -134,14 +120,12 @@ async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
134120 core . startGroup ( "Uploading results" ) ;
135121 let succeeded = false ;
136122 try {
137- // Check if an upload has happened before. If so then abort.
138- // This is intended to catch when the finish and upload-sarif actions
139- // are used together, and then the upload-sarif action is invoked twice.
140- const sentinelFile = await getSentinelFilePath ( ) ;
141- if ( fs . existsSync ( sentinelFile ) ) {
142- core . info ( "Aborting as an upload has already happened from this job" ) ;
123+ const sentinelEnvVar = "CODEQL_UPLOAD_SARIF" ;
124+ if ( process . env [ sentinelEnvVar ] ) {
125+ core . error ( "Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job" ) ;
143126 return false ;
144127 }
128+ core . exportVariable ( sentinelEnvVar , sentinelEnvVar ) ;
145129
146130 const commitOid = util . getRequiredEnvParam ( 'GITHUB_SHA' ) ;
147131 const workflowRunIDStr = util . getRequiredEnvParam ( 'GITHUB_RUN_ID' ) ;
@@ -187,9 +171,6 @@ async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
187171 // Make the upload
188172 succeeded = await uploadPayload ( payload ) ;
189173
190- // Mark that we have made an upload
191- fs . writeFileSync ( sentinelFile , '' ) ;
192-
193174 } catch ( error ) {
194175 core . setFailed ( error . message ) ;
195176 }
0 commit comments