Merge pull request #40 from github/upload_twice
Emit an error if upload happens twice
This commit is contained in:
commit
63f52e71c0
3 changed files with 9 additions and 45 deletions
25
lib/upload-lib.js
generated
25
lib/upload-lib.js
generated
|
|
@ -13,7 +13,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const http = __importStar(require("@actions/http-client"));
|
const http = __importStar(require("@actions/http-client"));
|
||||||
const auth = __importStar(require("@actions/http-client/auth"));
|
const auth = __importStar(require("@actions/http-client/auth"));
|
||||||
const io = __importStar(require("@actions/io"));
|
|
||||||
const file_url_1 = __importDefault(require("file-url"));
|
const file_url_1 = __importDefault(require("file-url"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
|
|
@ -21,18 +20,6 @@ const zlib_1 = __importDefault(require("zlib"));
|
||||||
const fingerprints = __importStar(require("./fingerprints"));
|
const fingerprints = __importStar(require("./fingerprints"));
|
||||||
const sharedEnv = __importStar(require("./shared-environment"));
|
const sharedEnv = __importStar(require("./shared-environment"));
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
// Construct the location of the sentinel file for detecting multiple uploads.
|
|
||||||
// The returned location should be writable.
|
|
||||||
async function getSentinelFilePath() {
|
|
||||||
// Use the temp dir instead of placing next to the sarif file because of
|
|
||||||
// issues with docker actions. The directory containing the sarif file
|
|
||||||
// may not be writable by us.
|
|
||||||
const uploadsTmpDir = path.join(process.env['RUNNER_TEMP'] || '/tmp/codeql-action', 'uploads');
|
|
||||||
await io.mkdirP(uploadsTmpDir);
|
|
||||||
// Hash the absolute path so we'll behave correctly in the unlikely
|
|
||||||
// scenario a file is referenced twice with different paths.
|
|
||||||
return path.join(uploadsTmpDir, 'codeql-action-upload-sentinel');
|
|
||||||
}
|
|
||||||
// Takes a list of paths to sarif files and combines them together,
|
// Takes a list of paths to sarif files and combines them together,
|
||||||
// returning the contents of the combined sarif file.
|
// returning the contents of the combined sarif file.
|
||||||
function combineSarifFiles(sarifFiles) {
|
function combineSarifFiles(sarifFiles) {
|
||||||
|
|
@ -140,14 +127,12 @@ async function uploadFiles(sarifFiles) {
|
||||||
core.startGroup("Uploading results");
|
core.startGroup("Uploading results");
|
||||||
let succeeded = false;
|
let succeeded = false;
|
||||||
try {
|
try {
|
||||||
// Check if an upload has happened before. If so then abort.
|
const sentinelEnvVar = "CODEQL_UPLOAD_SARIF";
|
||||||
// This is intended to catch when the finish and upload-sarif actions
|
if (process.env[sentinelEnvVar]) {
|
||||||
// are used together, and then the upload-sarif action is invoked twice.
|
core.error("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job");
|
||||||
const sentinelFile = await getSentinelFilePath();
|
|
||||||
if (fs.existsSync(sentinelFile)) {
|
|
||||||
core.info("Aborting as an upload has already happened from this job");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
core.exportVariable(sentinelEnvVar, sentinelEnvVar);
|
||||||
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
||||||
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
||||||
const ref = util.getRef();
|
const ref = util.getRef();
|
||||||
|
|
@ -188,8 +173,6 @@ async function uploadFiles(sarifFiles) {
|
||||||
core.debug("Number of results in upload: " + countResultsInSarif(sarifPayload));
|
core.debug("Number of results in upload: " + countResultsInSarif(sarifPayload));
|
||||||
// Make the upload
|
// Make the upload
|
||||||
succeeded = await uploadPayload(payload);
|
succeeded = await uploadPayload(payload);
|
||||||
// Mark that we have made an upload
|
|
||||||
fs.writeFileSync(sentinelFile, '');
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,6 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as http from '@actions/http-client';
|
import * as http from '@actions/http-client';
|
||||||
import * as auth from '@actions/http-client/auth';
|
import * as auth from '@actions/http-client/auth';
|
||||||
import * as io from '@actions/io';
|
|
||||||
import fileUrl from 'file-url';
|
import fileUrl from 'file-url';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
@ -11,19 +10,6 @@ import * as fingerprints from './fingerprints';
|
||||||
import * as sharedEnv from './shared-environment';
|
import * as sharedEnv from './shared-environment';
|
||||||
import * as util from './util';
|
import * as util from './util';
|
||||||
|
|
||||||
// Construct the location of the sentinel file for detecting multiple uploads.
|
|
||||||
// The returned location should be writable.
|
|
||||||
async function getSentinelFilePath(): Promise<string> {
|
|
||||||
// Use the temp dir instead of placing next to the sarif file because of
|
|
||||||
// issues with docker actions. The directory containing the sarif file
|
|
||||||
// may not be writable by us.
|
|
||||||
const uploadsTmpDir = path.join(process.env['RUNNER_TEMP'] || '/tmp/codeql-action', 'uploads');
|
|
||||||
await io.mkdirP(uploadsTmpDir);
|
|
||||||
// Hash the absolute path so we'll behave correctly in the unlikely
|
|
||||||
// scenario a file is referenced twice with different paths.
|
|
||||||
return path.join(uploadsTmpDir, 'codeql-action-upload-sentinel');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Takes a list of paths to sarif files and combines them together,
|
// Takes a list of paths to sarif files and combines them together,
|
||||||
// returning the contents of the combined sarif file.
|
// returning the contents of the combined sarif file.
|
||||||
export function combineSarifFiles(sarifFiles: string[]): string {
|
export function combineSarifFiles(sarifFiles: string[]): string {
|
||||||
|
|
@ -143,14 +129,12 @@ async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
|
||||||
core.startGroup("Uploading results");
|
core.startGroup("Uploading results");
|
||||||
let succeeded = false;
|
let succeeded = false;
|
||||||
try {
|
try {
|
||||||
// Check if an upload has happened before. If so then abort.
|
const sentinelEnvVar = "CODEQL_UPLOAD_SARIF";
|
||||||
// This is intended to catch when the finish and upload-sarif actions
|
if (process.env[sentinelEnvVar]) {
|
||||||
// are used together, and then the upload-sarif action is invoked twice.
|
core.error("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job");
|
||||||
const sentinelFile = await getSentinelFilePath();
|
|
||||||
if (fs.existsSync(sentinelFile)) {
|
|
||||||
core.info("Aborting as an upload has already happened from this job");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
core.exportVariable(sentinelEnvVar, sentinelEnvVar);
|
||||||
|
|
||||||
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
||||||
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
||||||
|
|
@ -201,9 +185,6 @@ async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
|
||||||
// Make the upload
|
// Make the upload
|
||||||
succeeded = await uploadPayload(payload);
|
succeeded = await uploadPayload(payload);
|
||||||
|
|
||||||
// Mark that we have made an upload
|
|
||||||
fs.writeFileSync(sentinelFile, '');
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue