Skip to content

Commit 42d6d35

Browse files
authored
Merge pull request #1464 from github/aeisenberg/externalRepoTokenConfigParsing
Send the external repository token to the CLI
2 parents bdc7c5d + e009918 commit 42d6d35

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";
@@ -513,7 +513,7 @@ const injectedConfigMacro = test.macro({
513513
const codeqlObject = await codeql.getCodeQLForTesting();
514514
sinon
515515
.stub(codeqlObject, "getVersion")
516-
.resolves(codeql.CODEQL_VERSION_CONFIG_FILES);
516+
.resolves(featureConfig[Feature.CliConfigFileEnabled].minimumVersion);
517517

518518
const thisStubConfig: Config = {
519519
...stubConfig,
@@ -570,7 +570,7 @@ test(
570570
},
571571
{},
572572
{
573-
packs: ["codeql/javascript-experimental-atm-queries@~0.3.0"],
573+
packs: ["codeql/javascript-experimental-atm-queries@~0.4.0"],
574574
}
575575
);
576576

@@ -591,7 +591,7 @@ test(
591591
packs: {
592592
javascript: [
593593
"codeql/something-else",
594-
"codeql/javascript-experimental-atm-queries@~0.3.0",
594+
"codeql/javascript-experimental-atm-queries@~0.4.0",
595595
],
596596
},
597597
}
@@ -613,7 +613,7 @@ test(
613613
{
614614
packs: {
615615
cpp: ["codeql/something-else"],
616-
javascript: ["codeql/javascript-experimental-atm-queries@~0.3.0"],
616+
javascript: ["codeql/javascript-experimental-atm-queries@~0.4.0"],
617617
},
618618
}
619619
);
@@ -694,7 +694,7 @@ test(
694694
},
695695
},
696696
{
697-
packs: ["xxx", "yyy", "codeql/javascript-experimental-atm-queries@~0.3.0"],
697+
packs: ["xxx", "yyy", "codeql/javascript-experimental-atm-queries@~0.4.0"],
698698
}
699699
);
700700

@@ -826,7 +826,7 @@ test("does not use injected config", async (t: ExecutionContext<unknown>) => {
826826
const codeqlObject = await codeql.getCodeQLForTesting();
827827
sinon
828828
.stub(codeqlObject, "getVersion")
829-
.resolves(codeql.CODEQL_VERSION_CONFIG_FILES);
829+
.resolves(featureConfig[Feature.CliConfigFileEnabled].minimumVersion);
830830

831831
await codeqlObject.databaseInitCluster(
832832
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)