Skip to content

Commit dbc4fda

Browse files
Merge pull request #577 from github/revert-573-upload-database
Revert "Upload CodeQL databases"
2 parents f6d1bad + d893508 commit dbc4fda

10 files changed

+4
-213
lines changed

analyze/action.yml

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ inputs:
3434
category:
3535
description: String used by Code Scanning for matching the analyses
3636
required: false
37-
upload-database:
38-
description: Whether to upload the resulting CodeQL database
39-
required: false
40-
default: "true"
4137
token:
4238
default: ${{ github.token }}
4339
matrix:

lib/actions-util.js

-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js

-52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js

-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.ts

-27
Original file line numberDiff line numberDiff line change
@@ -691,30 +691,3 @@ export function getRelativeScriptPath(): string {
691691
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
692692
return path.relative(actionsDirectory, __filename);
693693
}
694-
695-
// Reads the contents of GITHUB_EVENT_PATH as a JSON object
696-
function getWorkflowEvent(): any {
697-
const eventJsonFile = getRequiredEnvParam("GITHUB_EVENT_PATH");
698-
try {
699-
return JSON.parse(fs.readFileSync(eventJsonFile, "utf-8"));
700-
} catch (e) {
701-
throw new Error(
702-
`Unable to read workflow event JSON from ${eventJsonFile}: ${e}`
703-
);
704-
}
705-
}
706-
707-
// Is the version of the repository we are currently analyzing from the default branch,
708-
// or alternatively from another branch or a pull request.
709-
export async function isAnalyzingDefaultBranch(): Promise<boolean> {
710-
// Get the current ref and trim and refs/heads/ prefix
711-
let currentRef = await getRef();
712-
currentRef = currentRef.startsWith("refs/heads/")
713-
? currentRef.substr("refs/heads/".length)
714-
: currentRef;
715-
716-
const event = getWorkflowEvent();
717-
const defaultBranch = event?.repository?.default_branch;
718-
719-
return currentRef === defaultBranch;
720-
}

src/analyze-action.ts

+1-76
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import {
1010
QueriesStatusReport,
1111
runCleanup,
1212
} from "./analyze";
13-
import { getApiClient, GitHubApiDetails } from "./api-client";
14-
import { getCodeQL } from "./codeql";
1513
import { Config, getConfig } from "./config-utils";
16-
import { getActionsLogger, Logger } from "./logging";
17-
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
14+
import { getActionsLogger } from "./logging";
1815
import * as upload_lib from "./upload-lib";
1916
import * as util from "./util";
2017

@@ -52,73 +49,6 @@ async function sendStatusReport(
5249
await actionsUtil.sendStatusReport(statusReport);
5350
}
5451

55-
async function uploadDatabases(
56-
repositoryNwo: RepositoryNwo,
57-
config: Config,
58-
apiDetails: GitHubApiDetails,
59-
logger: Logger
60-
): Promise<void> {
61-
if (actionsUtil.getRequiredInput("upload-database") !== "true") {
62-
logger.debug("Database upload disabled in workflow. Skipping upload.");
63-
return;
64-
}
65-
66-
// Do nothing when not running against github.com
67-
if (config.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
68-
logger.debug("Not running against github.com. Skipping upload.");
69-
return;
70-
}
71-
72-
if (!(await actionsUtil.isAnalyzingDefaultBranch())) {
73-
// We only want to upload a database if we are analyzing the default branch.
74-
logger.debug("Not analyzing default branch. Skipping upload.");
75-
return;
76-
}
77-
78-
const client = getApiClient(apiDetails);
79-
const optInResponse = await client.request(
80-
"GET /repos/:owner/:repo/code-scanning/databases",
81-
{
82-
owner: repositoryNwo.owner,
83-
repo: repositoryNwo.repo,
84-
}
85-
);
86-
if (optInResponse.status !== 204) {
87-
// Repository is not opted in to database uploads.
88-
logger.debug(
89-
"Repository is not opted in to database uploads. Skipping upload."
90-
);
91-
return;
92-
}
93-
94-
const codeql = getCodeQL(config.codeQLCmd);
95-
for (const language of config.languages) {
96-
// Bundle the database up into a single zip file
97-
const databasePath = util.getCodeQLDatabasePath(config, language);
98-
const databaseBundlePath = `${databasePath}.zip`;
99-
await codeql.databaseBundle(databasePath, databaseBundlePath);
100-
101-
// Upload the database bundle
102-
const payload = fs.readFileSync(databaseBundlePath);
103-
const uploadResponse = await client.request(
104-
`PUT /repos/:owner/:repo/code-scanning/databases/${language}`,
105-
{
106-
owner: repositoryNwo.owner,
107-
repo: repositoryNwo.repo,
108-
data: payload,
109-
}
110-
);
111-
if (uploadResponse.status === 201) {
112-
logger.debug(`Successfully uploaded database for ${language}`);
113-
} else {
114-
// Log a warning but don't fail the workflow
115-
logger.warning(
116-
`Failed to upload database for ${language}. ${uploadResponse.data}`
117-
);
118-
}
119-
}
120-
}
121-
12252
async function run() {
12353
const startedAt = new Date();
12454
let stats: AnalysisStatusReport | undefined = undefined;
@@ -186,11 +116,6 @@ async function run() {
186116
logger.info("Not uploading results");
187117
stats = { ...queriesStats };
188118
}
189-
190-
const repositoryNwo = parseRepositoryNwo(
191-
util.getRequiredEnvParam("GITHUB_REPOSITORY")
192-
);
193-
await uploadDatabases(repositoryNwo, config, apiDetails, logger);
194119
} catch (error) {
195120
core.setFailed(error.message);
196121
console.log(error);

0 commit comments

Comments
 (0)