8000 Send the external repository token to the CLI · github/codeql-action@c17dc61 · GitHub
[go: up one dir, main page]

Skip to content

Commit c17dc61

Browse files
committed
Send the external repository token to the CLI
This commit does a few related things: 1. Bumps the minimum version for cli config parsing to 2.10.6 2. Ensures that if cli config parsing is enabled, then remove repos are _not_ downloaded by the action. It happens in the CLI. 3. Passes the `--external-repository-token-stdin` option to the CLI and passes the appropriate token via stdin if cli config parsing is enabled.
1 parent cf1437a commit c17dc61

14 files changed

+94
-64
lines changed

lib/analyze.js

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

lib/analyze.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js

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

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js

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

lib/codeql.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js

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

lib/config-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze.ts

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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,
@@ -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

Lines changed: 23 additions & 12 deletions
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.
888+
// Only pass external repository token if a config file is
889+
let externalRepositoryToken: string | undefined;
888890
const configLocation = await generateCodeScanningConfig(
889891
codeql,
890892
config,
891893
featureEnablement
892894
);
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+
externalRepositoryToken
915+
);
906916
},
907917
async runAutobuild(language: Language) {
908918
const cmdName =
@@ -1335,7 +1345,7 @@ export function getExtraOptions(
13351345
*/
13361346
const maxErrorSize = 20_000;
13371347

1338-
async function runTool(cmd: string, args: string[] = []) {
1348+
async function runTool(cmd: string, args: string[] = [], stdin?: string) {
13391349
let output = "";
13401350
let error = "";
13411351
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
@@ -1354,6 +1364,7 @@ async function runTool(cmd: string, args: string[] = []) {
13541364
},
13551365
},
13561366
ignoreReturnCode: true,
1367+
input: Buffer.from(stdin || ""),
13571368
}).exec();
13581369
if (exitCode !== 0)
13591370
throw new CommandInvocationError(cmd, args, exitCode, error, output);

src/config-utils.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -582,16 +582,20 @@ async function parseQueryUses(
582582
);
583583
}
584584

585-
// Otherwise, must be a reference to another repo
586-
await addRemoteQueries(
587-
codeQL,
588-
resultMap,
589-
queryUses,
590-
tempDir,
591-
apiDetails,
592-
logger,
593-
configFile
594-
);
585+
// Otherwise, must be a reference to another repo.
586+
// If config parsing is handled in CLI, then this repo will be downloaded
587+
// later by the CLI.
588+
if (!(await useCodeScanningConfigInCli(codeQL, featureEnablement))) {
589+
await addRemoteQueries(
590+
codeQL,
591+
resultMap,
592+
queryUses,
593+
tempDir,
594+
apiDetails,
595+
logger,
596+
configFile
597+
);
598+
}
595599
return false;
596600
}
597601

@@ -1724,26 +1728,27 @@ export async function initConfig(
17241728
);
17251729
}
17261730

1727-
// The list of queries should not be empty for any language. If it is then
1728-
// it is a user configuration error.
1729-
for (const language of config.languages) {
1730-
const hasBuiltinQueries = config.queries[language]?.builtin.length > 0;
1731-
const hasCustomQueries = config.queries[language]?.custom.length > 0;
1732-
const hasPacks = (config.packs[language]?.length || 0) > 0;
1733-
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
1734-
throw new Error(
1735-
`Did not detect any queries to run for ${language}. ` +
1736-
"Please make sure that the default queries are enabled, or you are specifying queries to run."
1737-
);
1738-
}
1739-
}
1740-
17411731
// When using the codescanning config in the CLI, pack downloads
17421732
// happen in the CLI during the `database init` command, so no need
17431733
// to download them here.
17441734
await logCodeScanningConfigInCli(codeQL, featureEnablement, logger);
17451735

17461736
if (!(await useCodeScanningConfigInCli(codeQL, featureEnablement))) {
1737+
// The list of queries should not be empty for any language. If it is then
1738+
// it is a user configuration error.
1739+
// This check occurs in the CLI when it parses the config file.
1740+
for (const language of config.languages) {
1741+
const hasBuiltinQueries = config.queries[language]?.builtin.length > 0;
1742+
const hasCustomQueries = config.queries[language]?.custom.length > 0;
1743+
const hasPacks = (config.packs[language]?.length || 0) > 0;
1744+
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
1745+
throw new Error(
1746+
`Did not detect any queries to run for ${language}. ` +
1747+
"Please make sure that the default queries are enabled, or you are specifying queries to run."
1748+
);
1749+
}
1750+
}
1751+
17471752
const registries = parseRegistries(registriesInput);
17481753
await downloadPacks(
17491754
codeQL,

src/feature-flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const featureConfig: Record<
4343
},
4444
[Feature.CliConfigFileEnabled]: {
4545
envVar: "CODEQL_PASS_CONFIG_TO_CLI",
46-
minimumVersion: "2.11.1",
46+
minimumVersion: "2.11.6",
4747
},
4848
[Feature.MlPoweredQueriesEnabled]: {
4949
envVar: "CODEQL_ML_POWERED_QUERIES",

0 commit comments

Comments
 (0)
0