Skip to content

Commit 02fb8cc

Browse files
authored
Propagate Config to combineSarifFilesUsingCLI
1 parent 6e9aec6 commit 02fb8cc

8 files changed

Lines changed: 52 additions & 15 deletions

‎lib/entry-points.js‎

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

‎src/analyze-action.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
361361
uploadResults = await postProcessAndUploadSarif(
362362
logger,
363363
features,
364+
config,
364365
uploadKind,
365366
checkoutPath,
366367
outputDir,

‎src/init-action-post-helper.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ async function testFailedSarifUpload(
793793
}
794794
t.true(
795795
uploadFiles.calledOnceWith(
796+
config,
796797
sinon.match.string,
797798
sinon.match.string,
798799
category,

‎src/init-action-post-helper.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ async function maybeUploadFailedSarif(
226226

227227
logger.info(`Uploading failed SARIF file ${failedSarif.sarifFile}`);
228228
const uploadResult = await uploadLib.uploadFiles(
229+
config,
229230
failedSarif.sarifFile,
230231
failedSarif.checkoutPath,
231232
failedSarif.category,

‎src/upload-lib.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as analyses from "./analyses";
1212
import * as api from "./api-client";
1313
import { getGitHubVersion, wrapApiConfigurationError } from "./api-client";
1414
import { CodeQL, getCodeQL } from "./codeql";
15-
import { getConfig } from "./config-utils";
15+
import type { ActionConfig } from "./config/action-config";
1616
import { readDiffRangesJsonFile } from "./diff-informed-analysis-utils";
1717
import { ActionsEnvVars, EnvVar, exportEnvVar } from "./environment";
1818
import { FeatureEnablement } from "./feature-flags";
@@ -94,15 +94,19 @@ async function shouldDisableCombineSarifFiles(
9494
return true;
9595
}
9696

97-
// Takes a list of paths to sarif files and combines them together using the
98-
// CLI `github merge-results` command when all SARIF files are produced by
99-
// CodeQL. Otherwise, it will fall back to combining the files in the action.
100-
// Returns the contents of the combined sarif file.
97+
/**
98+
* Takes a list of paths to sarif files and combines them together using the
99+
* CLI `github merge-results` command when all SARIF files are produced by
100+
* CodeQL. Otherwise, it will fall back to combining the files in the action.
101+
*
102+
* @returns The contents of the combined sarif file.
103+
*/
101104
async function combineSarifFilesUsingCLI(
102105
sarifFiles: string[],
103106
gitHubVersion: GitHubVersion,
104107
features: FeatureEnablement,
105108
logger: Logger,
109+
config: ActionConfig<"codeQLCmd" | "tempDir"> | undefined,
106110
): Promise<Partial<sarif.Log>> {
107111
const env = util.getEnv();
108112

@@ -140,7 +144,6 @@ async function combineSarifFilesUsingCLI(
140144
let codeQL: CodeQL;
141145
let tempDir: string = actionsUtil.getTemporaryDirectory();
142146

143-
const config = await getConfig(tempDir, logger);
144147
if (config !== undefined) {
145148
codeQL = await getCodeQL(logger, config.codeQLCmd);
146149
tempDir = config.tempDir;
@@ -599,6 +602,7 @@ export interface PostProcessingResults {
599602
export async function postProcessSarifFiles(
600603
logger: Logger,
601604
features: FeatureEnablement,
605+
config: ActionConfig<"codeQLCmd" | "tempDir"> | undefined,
602606
checkoutPath: string,
603607
sarifPaths: string[],
604608
category: string | undefined,
@@ -623,6 +627,7 @@ export async function postProcessSarifFiles(
623627
gitHubVersion,
624628
features,
625629
logger,
630+
config,
626631
);
627632
} else {
628633
const sarifPath = sarifPaths[0];
@@ -683,6 +688,7 @@ export async function writePostProcessedFiles(
683688
* to.
684689
*/
685690
export async function uploadFiles(
691+
config: ActionConfig<"codeQLCmd" | "tempDir"> | undefined,
686692
inputSarifPath: string,
687693
checkoutPath: string,
688694
category: string | undefined,
@@ -697,6 +703,7 @@ export async function uploadFiles(
697703

698704
return uploadSpecifiedFiles(
699705
sarifPaths,
706+
config,
700707
checkoutPath,
701708
category,
702709
features,
@@ -710,6 +717,7 @@ export async function uploadFiles(
710717
*/
711718
async function uploadSpecifiedFiles(
712719
sarifPaths: string[],
720+
config: ActionConfig<"codeQLCmd" | "tempDir"> | undefined,
713721
checkoutPath: string,
714722
category: string | undefined,
715723
features: FeatureEnablement,
@@ -719,6 +727,7 @@ async function uploadSpecifiedFiles(
719727
const processingResults: PostProcessingResults = await postProcessSarifFiles(
720728
logger,
721729
features,
730+
config,
722731
checkoutPath,
723732
sarifPaths,
724733
category,

‎src/upload-sarif-action.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as actionsUtil from "./actions-util";
55
import { getActionVersion, getTemporaryDirectory } from "./actions-util";
66
import * as analyses from "./analyses";
77
import { getGitHubVersion } from "./api-client";
8+
import { getConfig } from "./config-utils";
89
import { initFeatures } from "./feature-flags";
910
import { Logger } from "./logging";
1011
import { getRepositoryNwo } from "./repository";
@@ -66,11 +67,12 @@ async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
6667
// Make inputs accessible in the `post` step.
6768
actionsUtil.persistInputs();
6869

70+
const tempDir = getTemporaryDirectory();
6971
const repositoryNwo = getRepositoryNwo();
7072
const features = initFeatures(
7173
gitHubVersion,
7274
repositoryNwo,
73-
getTemporaryDirectory(),
75+
tempDir,
7476
logger,
7577
);
7678

@@ -91,9 +93,15 @@ async function run({ startedAt, logger }: ActionState<["Base", "Logger"]>) {
9193
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
9294
const category = actionsUtil.getOptionalInput("category");
9395

96+
// Although we wouldn't typically expect there to be a configuration since we don't expect another
97+
// CodeQL Action step to have come before `upload-sarif`, this has previously been the behaviour
98+
// when `combineSarifFilesUsingCLI` called `getConfig` directly. Since the only effect of this would
99+
// be that an existing CLI that was installed gets re-used, we maintain this behaviour.
100+
const maybeConfig = await getConfig(tempDir, logger);
94101
const uploadResults = await postProcessAndUploadSarif(
95102
logger,
96103
features,
104+
maybeConfig,
97105
"always",
98106
checkoutPath,
99107
sarifPath,

‎src/upload-sarif.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function mockPostProcessSarifFiles() {
2626
const analysisConfig = getAnalysisConfig(analysisKind);
2727
postProcessSarifFiles
2828
.withArgs(
29+
sinon.match.object,
2930
sinon.match.any,
3031
sinon.match.any,
3132
sinon.match.any,
@@ -75,9 +76,11 @@ const postProcessAndUploadSarifMacro = makeMacro({
7576
fs.writeFileSync(sarifFile, "");
7677
}
7778

79+
const config = undefined;
7880
const actual = await postProcessAndUploadSarif(
7981
logger,
8082
features,
83+
config,
8184
"always",
8285
"",
8386
testPath,
@@ -94,6 +97,7 @@ const postProcessAndUploadSarifMacro = makeMacro({
9497
postProcessSarifFiles.calledWith(
9598
logger,
9699
features,
100+
config,
97101
sinon.match.any,
98102
analysisKindResult.expectedFiles?.map(toFullPath) ??
99103
fullSarifPaths,
@@ -223,6 +227,7 @@ test.serial(
223227
const actual = await postProcessAndUploadSarif(
224228
logger,
225229
features,
230+
undefined,
226231
"never",
227232
"",
228233
tempDir,
@@ -253,6 +258,7 @@ test.serial(
253258
const actual = await postProcessAndUploadSarif(
254259
logger,
255260
features,
261+
undefined,
256262
"never",
257263
"",
258264
tempDir,

‎src/upload-sarif.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UploadKind } from "./actions-util";
22
import * as analyses from "./analyses";
3+
import type { ActionConfig } from "./config/action-config";
34
import { FeatureEnablement } from "./feature-flags";
45
import { Logger } from "./logging";
56
import * as upload_lib from "./upload-lib";
@@ -26,6 +27,7 @@ export type UploadSarifResults = Partial<
2627
export async function postProcessAndUploadSarif(
2728
logger: Logger,
2829
features: FeatureEnablement,
30+
config: ActionConfig<"codeQLCmd" | "tempDir"> | undefined,
2931
uploadKind: UploadKind,
3032
checkoutPath: string,
3133
sarifPath: string,
@@ -45,6 +47,7 @@ export async function postProcessAndUploadSarif(
4547
const postProcessingResults = await upload_lib.postProcessSarifFiles(
4648
logger,
4749
features,
50+
config,
4851
checkoutPath,
4952
sarifFiles,
5053
category,

0 commit comments

Comments
 (0)