Skip to content

Commit 0c5185d

Browse files
authored
Merge pull request #3221 from github/mbg/code-quality/skip-db-upload
Always skip database upload if `AnalysisKind.CodeScanning` is not enabled
2 parents 8e53c48 + 79ed956 commit 0c5185d

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

lib/analyze-action.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/database-upload.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import test from "ava";
55
import * as sinon from "sinon";
66

77
import * as actionsUtil from "./actions-util";
8+
import { AnalysisKind } from "./analyses";
89
import { GitHubApiDetails } from "./api-client";
910
import * as apiClient from "./api-client";
1011
import { createStubCodeQL } from "./codeql";
@@ -108,6 +109,39 @@ test("Abort database upload if 'upload-database' input set to false", async (t)
108109
});
109110
});
110111

112+
test("Abort database upload if 'analysis-kinds: code-scanning' is not enabled", async (t) => {
113+
await withTmpDir(async (tmpDir) => {
114+
setupActionsVars(tmpDir, tmpDir);
115+
sinon
116+
.stub(actionsUtil, "getRequiredInput")
117+
.withArgs("upload-database")
118+
.returns("true");
119+
sinon.stub(gitUtils, "isAnalyzingDefaultBranch").resolves(true);
120+
121+
await mockHttpRequests(201);
122+
123+
const loggedMessages = [];
124+
await uploadDatabases(
125+
testRepoName,
126+
getCodeQL(),
127+
{
128+
...getTestConfig(tmpDir),
129+
analysisKinds: [AnalysisKind.CodeQuality],
130+
},
131+
testApiDetails,
132+
getRecordingLogger(loggedMessages),
133+
);
134+
t.assert(
135+
loggedMessages.find(
136+
(v: LoggedMessage) =>
137+
v.type === "debug" &&
138+
v.message ===
139+
"Not uploading database because 'analysis-kinds: code-scanning' is not enabled.",
140+
) !== undefined,
141+
);
142+
});
143+
});
144+
111145
test("Abort database upload if running against GHES", async (t) => {
112146
await withTmpDir(async (tmpDir) => {
113147
setupActionsVars(tmpDir, tmpDir);

src/database-upload.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from "fs";
22

33
import * as actionsUtil from "./actions-util";
4+
import { AnalysisKind } from "./analyses";
45
import { getApiClient, GitHubApiDetails } from "./api-client";
56
import { type CodeQL } from "./codeql";
67
import { Config } from "./config-utils";
@@ -22,6 +23,13 @@ export async function uploadDatabases(
2223
return;
2324
}
2425

26+
if (!config.analysisKinds.includes(AnalysisKind.CodeScanning)) {
27+
logger.debug(
28+
`Not uploading database because 'analysis-kinds: ${AnalysisKind.CodeScanning}' is not enabled.`,
29+
);
30+
return;
31+
}
32+
2533
if (util.isInTestMode()) {
2634
logger.debug("In test mode. Skipping database upload.");
2735
return;

0 commit comments

Comments
 (0)