Skip to content

Commit

Permalink
Defer language aliasing to CLI when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Oct 5, 2023
1 parent 0ac7669 commit e26ed57
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions lib/resolve-environment-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/resolve-environment-action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions lib/resolve-environment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/resolve-environment.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface CodeQL {
*/
resolveBuildEnvironment(
workingDir: string | undefined,
language: Language,
language: string,
): Promise<ResolveBuildEnvironmentOutput>;

/**
Expand Down Expand Up @@ -780,7 +780,7 @@ export async function getCodeQLForCmd(
},
async resolveBuildEnvironment(
workingDir: string | undefined,
language: Language,
language: string,
) {
const codeqlArgs = [
"resolve",
Expand Down
13 changes: 1 addition & 12 deletions src/resolve-environment-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { getGitHubVersion } from "./api-client";
import { CommandInvocationError } from "./codeql";
import * as configUtils from "./config-utils";
import { Language, parseLanguage } from "./languages";
import { getActionsLogger } from "./logging";
import { runResolveBuildEnvironment } from "./resolve-environment";
import {
Expand Down Expand Up @@ -44,16 +43,6 @@ async function run() {
return;
}

const language: Language | undefined = parseLanguage(
getRequiredInput("language"),
);

if (language === undefined) {
throw new Error(
`Did not recognize the language "${getRequiredInput("language")}".`,
);
}

const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger);

Expand All @@ -69,7 +58,7 @@ async function run() {
config.codeQLCmd,
logger,
workingDirectory,
language,
getRequiredInput("language"),
);
core.setOutput(ENVIRONMENT_OUTPUT_NAME, result);
} catch (unwrappedError) {
Expand Down
27 changes: 23 additions & 4 deletions src/resolve-environment.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import { CODEQL_VERSION_RESOLVE_ENVIRONMENT, getCodeQL } from "./codeql";
import { Language } from "./languages";
import {
CODEQL_VERSION_LANGUAGE_ALIASING,
CODEQL_VERSION_RESOLVE_ENVIRONMENT,
getCodeQL,
} from "./codeql";
import { parseLanguage } from "./languages";
import { Logger } from "./logging";
import * as util from "./util";

export async function runResolveBuildEnvironment(
cmd: string,
logger: Logger,
workingDir: string | undefined,
language: Language,
languageInput: string,
) {
logger.startGroup(`Attempting to resolve build environment for ${language}`);
logger.startGroup(
`Attempting to resolve build environment for ${languageInput}`,
);

const codeql = await getCodeQL(cmd);

let language = languageInput;
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_LANGUAGE_ALIASING)) {
// Delegate to the CodeQL CLI to handle aliasing.
} else {
// Handle aliasing in the Action using `parseLanguage`.
const parsedLanguage = parseLanguage(languageInput)?.toString();
if (parsedLanguage === undefined) {
throw new Error(`Did not recognize the language '${languageInput}'.`);
}
language = parsedLanguage;
}

let result = {};

// If the CodeQL version in use does not support the `resolve build-environment`
Expand Down

0 comments on commit e26ed57

Please sign in to comment.