Revert "Upload CodeQL databases"
This commit is contained in:
parent
f6d1bad81b
commit
d893508e3a
10 changed files with 4 additions and 213 deletions
|
|
@ -691,30 +691,3 @@ export function getRelativeScriptPath(): string {
|
|||
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
||||
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,
|
||||
runCleanup,
|
||||
} from "./analyze";
|
||||
import { getApiClient, GitHubApiDetails } from "./api-client";
|
||||
import { getCodeQL } from "./codeql";
|
||||
import { Config, getConfig } from "./config-utils";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
|
||||
|
|
@ -52,73 +49,6 @@ async function sendStatusReport(
|
|||
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() {
|
||||
const startedAt = new Date();
|
||||
let stats: AnalysisStatusReport | undefined = undefined;
|
||||
|
|
@ -186,11 +116,6 @@ async function run() {
|
|||
logger.info("Not uploading results");
|
||||
stats = { ...queriesStats };
|
||||
}
|
||||
|
||||
const repositoryNwo = parseRepositoryNwo(
|
||||
util.getRequiredEnvParam("GITHUB_REPOSITORY")
|
||||
);
|
||||
await uploadDatabases(repositoryNwo, config, apiDetails, logger);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
|
|
|
|||
|
|
@ -99,10 +99,6 @@ export interface CodeQL {
|
|||
* Run 'codeql database cleanup'.
|
||||
*/
|
||||
databaseCleanup(databasePath: string, cleanupLevel: string): Promise<void>;
|
||||
/**
|
||||
* Run 'codeql database bundle'.
|
||||
*/
|
||||
databaseBundle(databasePath: string, outputFilePath: string): Promise<void>;
|
||||
/**
|
||||
* Run 'codeql database run-queries'.
|
||||
*/
|
||||
|
|
@ -516,7 +512,6 @@ export function setCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
|
|||
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
||||
packDownload: resolveFunction(partialCodeql, "packDownload"),
|
||||
databaseCleanup: resolveFunction(partialCodeql, "databaseCleanup"),
|
||||
databaseBundle: resolveFunction(partialCodeql, "databaseBundle"),
|
||||
databaseRunQueries: resolveFunction(partialCodeql, "databaseRunQueries"),
|
||||
databaseInterpretResults: resolveFunction(
|
||||
partialCodeql,
|
||||
|
|
@ -834,18 +829,6 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
];
|
||||
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