Revert "Upload CodeQL databases"
This commit is contained in:
parent
f6d1bad81b
commit
d893508e3a
10 changed files with 4 additions and 213 deletions
|
|
@ -34,10 +34,6 @@ inputs:
|
||||||
category:
|
category:
|
||||||
description: String used by Code Scanning for matching the analyses
|
description: String used by Code Scanning for matching the analyses
|
||||||
required: false
|
required: false
|
||||||
upload-database:
|
|
||||||
description: Whether to upload the resulting CodeQL database
|
|
||||||
required: false
|
|
||||||
default: "true"
|
|
||||||
token:
|
token:
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
matrix:
|
matrix:
|
||||||
|
|
|
||||||
24
lib/actions-util.js
generated
24
lib/actions-util.js
generated
|
|
@ -540,28 +540,4 @@ function getRelativeScriptPath() {
|
||||||
return path.relative(actionsDirectory, __filename);
|
return path.relative(actionsDirectory, __filename);
|
||||||
}
|
}
|
||||||
exports.getRelativeScriptPath = getRelativeScriptPath;
|
exports.getRelativeScriptPath = getRelativeScriptPath;
|
||||||
// Reads the contents of GITHUB_EVENT_PATH as a JSON object
|
|
||||||
function getWorkflowEvent() {
|
|
||||||
const eventJsonFile = util_1.getRequiredEnvParam("GITHUB_EVENT_PATH");
|
|
||||||
try {
|
|
||||||
return JSON.parse(fs.readFileSync(eventJsonFile, "utf-8"));
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
throw new Error(`Unable to read workflow event JSON from ${eventJsonFile}: ${e}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Is the version of the repository we are currently analyzing from the default branch,
|
|
||||||
// or alternatively from another branch or a pull request.
|
|
||||||
async function isAnalyzingDefaultBranch() {
|
|
||||||
var _a, _b;
|
|
||||||
// Get the current ref and trim and refs/heads/ prefix
|
|
||||||
let currentRef = await getRef();
|
|
||||||
currentRef = currentRef.startsWith("refs/heads/")
|
|
||||||
? currentRef.substr("refs/heads/".length)
|
|
||||||
: currentRef;
|
|
||||||
const event = getWorkflowEvent();
|
|
||||||
const defaultBranch = (_b = (_a = event) === null || _a === void 0 ? void 0 : _a.repository) === null || _b === void 0 ? void 0 : _b.default_branch;
|
|
||||||
return currentRef === defaultBranch;
|
|
||||||
}
|
|
||||||
exports.isAnalyzingDefaultBranch = isAnalyzingDefaultBranch;
|
|
||||||
//# sourceMappingURL=actions-util.js.map
|
//# sourceMappingURL=actions-util.js.map
|
||||||
File diff suppressed because one or more lines are too long
52
lib/analyze-action.js
generated
52
lib/analyze-action.js
generated
|
|
@ -12,11 +12,8 @@ const path = __importStar(require("path"));
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const actionsUtil = __importStar(require("./actions-util"));
|
const actionsUtil = __importStar(require("./actions-util"));
|
||||||
const analyze_1 = require("./analyze");
|
const analyze_1 = require("./analyze");
|
||||||
const api_client_1 = require("./api-client");
|
|
||||||
const codeql_1 = require("./codeql");
|
|
||||||
const config_utils_1 = require("./config-utils");
|
const config_utils_1 = require("./config-utils");
|
||||||
const logging_1 = require("./logging");
|
const logging_1 = require("./logging");
|
||||||
const repository_1 = require("./repository");
|
|
||||||
const upload_lib = __importStar(require("./upload-lib"));
|
const upload_lib = __importStar(require("./upload-lib"));
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
// eslint-disable-next-line import/no-commonjs
|
// eslint-disable-next-line import/no-commonjs
|
||||||
|
|
@ -33,53 +30,6 @@ async function sendStatusReport(startedAt, stats, error) {
|
||||||
};
|
};
|
||||||
await actionsUtil.sendStatusReport(statusReport);
|
await actionsUtil.sendStatusReport(statusReport);
|
||||||
}
|
}
|
||||||
async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
|
|
||||||
if (actionsUtil.getRequiredInput("upload-database") !== "true") {
|
|
||||||
logger.debug("Database upload disabled in workflow. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Do nothing when not running against github.com
|
|
||||||
if (config.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
|
|
||||||
logger.debug("Not running against github.com. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(await actionsUtil.isAnalyzingDefaultBranch())) {
|
|
||||||
// We only want to upload a database if we are analyzing the default branch.
|
|
||||||
logger.debug("Not analyzing default branch. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const client = api_client_1.getApiClient(apiDetails);
|
|
||||||
const optInResponse = await client.request("GET /repos/:owner/:repo/code-scanning/databases", {
|
|
||||||
owner: repositoryNwo.owner,
|
|
||||||
repo: repositoryNwo.repo,
|
|
||||||
});
|
|
||||||
if (optInResponse.status !== 204) {
|
|
||||||
// Repository is not opted in to database uploads.
|
|
||||||
logger.debug("Repository is not opted in to database uploads. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
|
||||||
for (const language of config.languages) {
|
|
||||||
// Bundle the database up into a single zip file
|
|
||||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
|
||||||
const databaseBundlePath = `${databasePath}.zip`;
|
|
||||||
await codeql.databaseBundle(databasePath, databaseBundlePath);
|
|
||||||
// Upload the database bundle
|
|
||||||
const payload = fs.readFileSync(databaseBundlePath);
|
|
||||||
const uploadResponse = await client.request(`PUT /repos/:owner/:repo/code-scanning/databases/${language}`, {
|
|
||||||
owner: repositoryNwo.owner,
|
|
||||||
repo: repositoryNwo.repo,
|
|
||||||
data: payload,
|
|
||||||
});
|
|
||||||
if (uploadResponse.status === 201) {
|
|
||||||
logger.debug(`Successfully uploaded database for ${language}`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Log a warning but don't fail the workflow
|
|
||||||
logger.warning(`Failed to upload database for ${language}. ${uploadResponse.data}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const startedAt = new Date();
|
const startedAt = new Date();
|
||||||
let stats = undefined;
|
let stats = undefined;
|
||||||
|
|
@ -116,8 +66,6 @@ async function run() {
|
||||||
logger.info("Not uploading results");
|
logger.info("Not uploading results");
|
||||||
stats = { ...queriesStats };
|
stats = { ...queriesStats };
|
||||||
}
|
}
|
||||||
const repositoryNwo = repository_1.parseRepositoryNwo(util.getRequiredEnvParam("GITHUB_REPOSITORY"));
|
|
||||||
await uploadDatabases(repositoryNwo, config, apiDetails, logger);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
10
lib/codeql.js
generated
10
lib/codeql.js
generated
|
|
@ -287,7 +287,6 @@ function setCodeQL(partialCodeql) {
|
||||||
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
||||||
packDownload: resolveFunction(partialCodeql, "packDownload"),
|
packDownload: resolveFunction(partialCodeql, "packDownload"),
|
||||||
databaseCleanup: resolveFunction(partialCodeql, "databaseCleanup"),
|
databaseCleanup: resolveFunction(partialCodeql, "databaseCleanup"),
|
||||||
databaseBundle: resolveFunction(partialCodeql, "databaseBundle"),
|
|
||||||
databaseRunQueries: resolveFunction(partialCodeql, "databaseRunQueries"),
|
databaseRunQueries: resolveFunction(partialCodeql, "databaseRunQueries"),
|
||||||
databaseInterpretResults: resolveFunction(partialCodeql, "databaseInterpretResults"),
|
databaseInterpretResults: resolveFunction(partialCodeql, "databaseInterpretResults"),
|
||||||
};
|
};
|
||||||
|
|
@ -536,15 +535,6 @@ function getCodeQLForCmd(cmd) {
|
||||||
];
|
];
|
||||||
await runTool(cmd, codeqlArgs);
|
await runTool(cmd, codeqlArgs);
|
||||||
},
|
},
|
||||||
async databaseBundle(databasePath, outputFilePath) {
|
|
||||||
const args = [
|
|
||||||
"database",
|
|
||||||
"bundle",
|
|
||||||
databasePath,
|
|
||||||
`--output=${outputFilePath}`,
|
|
||||||
];
|
|
||||||
await new toolrunner.ToolRunner(cmd, args).exec();
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function packWithVersionToString(pack) {
|
function packWithVersionToString(pack) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -691,30 +691,3 @@ export function getRelativeScriptPath(): string {
|
||||||
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
||||||
return path.relative(actionsDirectory, __filename);
|
return path.relative(actionsDirectory, __filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads the contents of GITHUB_EVENT_PATH as a JSON object
|
|
||||||
function getWorkflowEvent(): any {
|
|
||||||
const eventJsonFile = getRequiredEnvParam("GITHUB_EVENT_PATH");
|
|
||||||
try {
|
|
||||||
return JSON.parse(fs.readFileSync(eventJsonFile, "utf-8"));
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(
|
|
||||||
`Unable to read workflow event JSON from ${eventJsonFile}: ${e}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is the version of the repository we are currently analyzing from the default branch,
|
|
||||||
// or alternatively from another branch or a pull request.
|
|
||||||
export async function isAnalyzingDefaultBranch(): Promise<boolean> {
|
|
||||||
// Get the current ref and trim and refs/heads/ prefix
|
|
||||||
let currentRef = await getRef();
|
|
||||||
currentRef = currentRef.startsWith("refs/heads/")
|
|
||||||
? currentRef.substr("refs/heads/".length)
|
|
||||||
: currentRef;
|
|
||||||
|
|
||||||
const event = getWorkflowEvent();
|
|
||||||
const defaultBranch = event?.repository?.default_branch;
|
|
||||||
|
|
||||||
return currentRef === defaultBranch;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@ import {
|
||||||
QueriesStatusReport,
|
QueriesStatusReport,
|
||||||
runCleanup,
|
runCleanup,
|
||||||
} from "./analyze";
|
} from "./analyze";
|
||||||
import { getApiClient, GitHubApiDetails } from "./api-client";
|
|
||||||
import { getCodeQL } from "./codeql";
|
|
||||||
import { Config, getConfig } from "./config-utils";
|
import { Config, getConfig } from "./config-utils";
|
||||||
import { getActionsLogger, Logger } from "./logging";
|
import { getActionsLogger } from "./logging";
|
||||||
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
|
|
||||||
import * as upload_lib from "./upload-lib";
|
import * as upload_lib from "./upload-lib";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
|
|
@ -52,73 +49,6 @@ async function sendStatusReport(
|
||||||
await actionsUtil.sendStatusReport(statusReport);
|
await actionsUtil.sendStatusReport(statusReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadDatabases(
|
|
||||||
repositoryNwo: RepositoryNwo,
|
|
||||||
config: Config,
|
|
||||||
apiDetails: GitHubApiDetails,
|
|
||||||
logger: Logger
|
|
||||||
): Promise<void> {
|
|
||||||
if (actionsUtil.getRequiredInput("upload-database") !== "true") {
|
|
||||||
logger.debug("Database upload disabled in workflow. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do nothing when not running against github.com
|
|
||||||
if (config.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
|
|
||||||
logger.debug("Not running against github.com. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(await actionsUtil.isAnalyzingDefaultBranch())) {
|
|
||||||
// We only want to upload a database if we are analyzing the default branch.
|
|
||||||
logger.debug("Not analyzing default branch. Skipping upload.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = getApiClient(apiDetails);
|
|
||||||
const optInResponse = await client.request(
|
|
||||||
"GET /repos/:owner/:repo/code-scanning/databases",
|
|
||||||
{
|
|
||||||
owner: repositoryNwo.owner,
|
|
||||||
repo: repositoryNwo.repo,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (optInResponse.status !== 204) {
|
|
||||||
// Repository is not opted in to database uploads.
|
|
||||||
logger.debug(
|
|
||||||
"Repository is not opted in to database uploads. Skipping upload."
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const codeql = getCodeQL(config.codeQLCmd);
|
|
||||||
for (const language of config.languages) {
|
|
||||||
// Bundle the database up into a single zip file
|
|
||||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
|
||||||
const databaseBundlePath = `${databasePath}.zip`;
|
|
||||||
await codeql.databaseBundle(databasePath, databaseBundlePath);
|
|
||||||
|
|
||||||
// Upload the database bundle
|
|
||||||
const payload = fs.readFileSync(databaseBundlePath);
|
|
||||||
const uploadResponse = await client.request(
|
|
||||||
`PUT /repos/:owner/:repo/code-scanning/databases/${language}`,
|
|
||||||
{
|
|
||||||
owner: repositoryNwo.owner,
|
|
||||||
repo: repositoryNwo.repo,
|
|
||||||
data: payload,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (uploadResponse.status === 201) {
|
|
||||||
logger.debug(`Successfully uploaded database for ${language}`);
|
|
||||||
} else {
|
|
||||||
// Log a warning but don't fail the workflow
|
|
||||||
logger.warning(
|
|
||||||
`Failed to upload database for ${language}. ${uploadResponse.data}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const startedAt = new Date();
|
const startedAt = new Date();
|
||||||
let stats: AnalysisStatusReport | undefined = undefined;
|
let stats: AnalysisStatusReport | undefined = undefined;
|
||||||
|
|
@ -186,11 +116,6 @@ async function run() {
|
||||||
logger.info("Not uploading results");
|
logger.info("Not uploading results");
|
||||||
stats = { ...queriesStats };
|
stats = { ...queriesStats };
|
||||||
}
|
}
|
||||||
|
|
||||||
const repositoryNwo = parseRepositoryNwo(
|
|
||||||
util.getRequiredEnvParam("GITHUB_REPOSITORY")
|
|
||||||
);
|
|
||||||
await uploadDatabases(repositoryNwo, config, apiDetails, logger);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,6 @@ export interface CodeQL {
|
||||||
* Run 'codeql database cleanup'.
|
* Run 'codeql database cleanup'.
|
||||||
*/
|
*/
|
||||||
databaseCleanup(databasePath: string, cleanupLevel: string): Promise<void>;
|
databaseCleanup(databasePath: string, cleanupLevel: string): Promise<void>;
|
||||||
/**
|
|
||||||
* Run 'codeql database bundle'.
|
|
||||||
*/
|
|
||||||
databaseBundle(databasePath: string, outputFilePath: string): Promise<void>;
|
|
||||||
/**
|
/**
|
||||||
* Run 'codeql database run-queries'.
|
* Run 'codeql database run-queries'.
|
||||||
*/
|
*/
|
||||||
|
|
@ -516,7 +512,6 @@ export function setCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
|
||||||
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
||||||
packDownload: resolveFunction(partialCodeql, "packDownload"),
|
packDownload: resolveFunction(partialCodeql, "packDownload"),
|
||||||
databaseCleanup: resolveFunction(partialCodeql, "databaseCleanup"),
|
databaseCleanup: resolveFunction(partialCodeql, "databaseCleanup"),
|
||||||
databaseBundle: resolveFunction(partialCodeql, "databaseBundle"),
|
|
||||||
databaseRunQueries: resolveFunction(partialCodeql, "databaseRunQueries"),
|
databaseRunQueries: resolveFunction(partialCodeql, "databaseRunQueries"),
|
||||||
databaseInterpretResults: resolveFunction(
|
databaseInterpretResults: resolveFunction(
|
||||||
partialCodeql,
|
partialCodeql,
|
||||||
|
|
@ -834,18 +829,6 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
||||||
];
|
];
|
||||||
await runTool(cmd, codeqlArgs);
|
await runTool(cmd, codeqlArgs);
|
||||||
},
|
},
|
||||||
async databaseBundle(
|
|
||||||
databasePath: string,
|
|
||||||
outputFilePath: string
|
|
||||||
): Promise<void> {
|
|
||||||
const args = [
|
|
||||||
"database",
|
|
||||||
"bundle",
|
|
||||||
databasePath,
|
|
||||||
`--output=${outputFilePath}`,
|
|
||||||
];
|
|
||||||
await new toolrunner.ToolRunner(cmd, args).exec();
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue