Skip to content

Commit 4a91879

Browse files
committed
Merge branch 'main' into henrymercer/fix-ghae-setup-test
2 parents 70a288d + 42d6d35 commit 4a91879

14 files changed

+106
-72
lines changed

lib/analyze.js

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

lib/analyze.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

+11-4
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.

lib/codeql.test.js

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

lib/codeql.test.js.map

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

lib/config-utils.js

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

lib/config-utils.js.map

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

lib/feature-flags.js

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

src/analyze.ts

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export async function runQueries(
262262
logger.endGroup();
263263
logger.info(analysisSummary);
264264
} else {
265+
// config was generated by the action, so must be interpreted by the action.
265266
logger.startGroup(`Running queries for ${language}`);
266267
const querySuitePaths: string[] = [];
267268
if (queries["builtin"].length > 0) {

src/codeql.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { GitHubApiDetails } from "./api-client";
1515
import * as codeql from "./codeql";
1616
import { AugmentationProperties, Config } from "./config-utils";
1717
import * as defaults from "./defaults.json";
18-
import { Feature } from "./feature-flags";
18+
import { Feature, featureConfig } from "./feature-flags";
1919
import { Language } from "./languages";
2020
import { getRunnerLogger } from "./logging";
2121
import { setupTests, setupActionsVars, createFeatures } from "./testing-utils";
@@ -559,7 +559,7 @@ const injectedConfigMacro = test.macro({
559559
const codeqlObject = await codeql.getCodeQLForTesting();
560560
sinon
561561
.stub(codeqlObject, "getVersion")
562-
.resolves(codeql.CODEQL_VERSION_CONFIG_FILES);
562+
.resolves(featureConfig[Feature.CliConfigFileEnabled].minimumVersion);
563563

564564
const thisStubConfig: Config = {
565565
...stubConfig,
@@ -616,7 +616,7 @@ test(
616616
},
617617
{},
618618
{
619-
packs: ["codeql/javascript-experimental-atm-queries@~0.3.0"],
619+
packs: ["codeql/javascript-experimental-atm-queries@~0.4.0"],
620620
}
621621
);
622622

@@ -637,7 +637,7 @@ test(
637637
packs: {
638638
javascript: [
639639
"codeql/something-else",
640-
"codeql/javascript-experimental-atm-queries@~0.3.0",
640+
"codeql/javascript-experimental-atm-queries@~0.4.0",
641641
],
642642
},
643643
}
@@ -659,7 +659,7 @@ test(
659659
{
660660
packs: {
661661
cpp: ["codeql/something-else"],
662-
javascript: ["codeql/javascript-experimental-atm-queries@~0.3.0"],
662+
javascript: ["codeql/javascript-experimental-atm-queries@~0.4.0"],
663663
},
664664
}
665665
);
@@ -740,7 +740,7 @@ test(
740740
},
741741
},
742742
{
743-
packs: ["xxx", "yyy", "codeql/javascript-experimental-atm-queries@~0.3.0"],
743+
packs: ["xxx", "yyy", "codeql/javascript-experimental-atm-queries@~0.4.0"],
744744
}
745745
);
746746

@@ -872,7 +872,7 @@ test("does not use injected config", async (t: ExecutionContext<unknown>) => {
872872
const codeqlObject = await codeql.getCodeQLForTesting();
873873
sinon
874874
.stub(codeqlObject, "getVersion")
875-
.resolves(codeql.CODEQL_VERSION_CONFIG_FILES);
875+
.resolves(featureConfig[Feature.CliConfigFileEnabled].minimumVersion);
876876

877877
await codeqlObject.databaseInitCluster(
878878
stubConfig,

src/codeql.ts

+27-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as yaml from "js-yaml";
99
import * as semver from "semver";
1010
import { v4 as uuidV4 } from "uuid";
1111

12-
import { isRunningLocalAction } from "./actions-util";
12+
import { getOptionalInput, isRunningLocalAction } from "./actions-util";
1313
import * as api from "./api-client";
1414
import { Config } from "./config-utils";
1515
import * as defaults from "./defaults.json"; // Referenced from codeql-action-sync-tool!
@@ -252,7 +252,6 @@ const CODEQL_MINIMUM_VERSION = "2.6.3";
252252
*/
253253
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1";
254254
const CODEQL_VERSION_LUA_TRACER_CONFIG = "2.10.0";
255-
export const CODEQL_VERSION_CONFIG_FILES = "2.10.1";
256255
const CODEQL_VERSION_LUA_TRACING_GO_WINDOWS_FIXED = "2.10.4";
257256
export const CODEQL_VERSION_GHES_PACK_DOWNLOAD = "2.10.4";
258257
const CODEQL_VERSION_FILE_BASELINE_INFORMATION = "2.11.3";
@@ -885,24 +884,35 @@ async function getCodeQLForCmd(
885884
}
886885
}
887886

887+
// A config file is only generated if the CliConfigFileEnabled feature flag is enabled.
888888
const configLocation = await generateCodeScanningConfig(
889889
codeql,
890890
config,
891891
featureEnablement
892892
);
893+
// Only pass external repository token if a config file is going to be parsed by the CLI.
894+
let externalRepositoryToken: string | undefined;
893895
if (configLocation) {
894896
extraArgs.push(`--codescanning-config=${configLocation}`);
897+
externalRepositoryToken = getOptionalInput("external-repository-token");
898+
if (externalRepositoryToken) {
899+
extraArgs.push("--external-repository-token-stdin");
900+
}
895901
}
896902

897-
await runTool(cmd, [
898-
"database",
899-
"init",
900-
"--db-cluster",
901-
config.dbLocation,
902-
`--source-root=${sourceRoot}`,
903-
...extraArgs,
904-
...getExtraOptionsFromEnv(["database", "init"]),
905-
]);
903+
await runTool(
904+
cmd,
905+
[
906+
"database",
907+
"init",
908+
"--db-cluster",
909+
config.dbLocation,
910+
`--source-root=${sourceRoot}`,
911+
...extraArgs,
912+
...getExtraOptionsFromEnv(["database", "init"]),
913+
],
914+
{ stdin: externalRepositoryToken }
915+
);
906916
},
907917
async runAutobuild(language: Language) {
908918
const cmdName =
@@ -1335,7 +1345,11 @@ export function getExtraOptions(
13351345
*/
13361346
const maxErrorSize = 20_000;
13371347

1338-
async function runTool(cmd: string, args: string[] = []) {
1348+
async function runTool(
1349+
cmd: string,
1350+
args: string[] = [],
1351+
opts: { stdin?: string } = {}
1352+
) {
13391353
let output = "";
13401354
let error = "";
13411355
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
@@ -1354,6 +1368,7 @@ async function runTool(cmd: string, args: string[] = []) {
13541368
},
13551369
},
13561370
ignoreReturnCode: true,
1371+
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
13571372
}).exec();
13581373
if (exitCode !== 0)
13591374
throw new CommandInvocationError(cmd, args, exitCode, error, output);

0 commit comments

Comments
 (0)