Skip to content

Commit

Permalink
Merge pull request #1923 from github/henrymercer/fix-resolve-environm…
Browse files Browse the repository at this point in the history
…ent-aliases

Fix using the `resolve-environment` Action with language aliases
  • Loading branch information
henrymercer authored Oct 5, 2023
2 parents 1ea6a10 + 8f0e8b0 commit 2723530
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 55 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/__resolve-environment-action.yml

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

15 changes: 10 additions & 5 deletions lib/codeql.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/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.

15 changes: 13 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.

26 changes: 19 additions & 7 deletions pr-checks/checks/resolve-environment-action.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
name: "Resolve environment"
description: "Tests that the resolve-environment action works for Go"
versions: ["stable-v2.13.4"]
description: "Tests that the resolve-environment action works for Go and JavaScript/TypeScript"
versions: ["stable-v2.13.4", "default", "latest", "nightly-latest"]
steps:
- uses: ./../action/init
with:
languages: go
languages: ${{ matrix.version == 'stable-v2.13.4' && 'go' || 'go,javascript-typescript' }}
tools: ${{ steps.prepare-test.outputs.tools-url }}

- uses: ./../action/resolve-environment
id: resolve-environment
- name: Resolve environment for Go
uses: ./../action/resolve-environment
id: resolve-environment-go
with:
language: go

- name: "Fail if no Go configuration was returned"
if: (!fromJSON(steps.resolve-environment.outputs.environment).configuration.go)
- name: Fail if Go configuration missing
if: (!fromJSON(steps.resolve-environment-go.outputs.environment).configuration.go)
run: exit 1

- name: Resolve environment for JavaScript/TypeScript
if: matrix.version != 'stable-v2.13.4'
uses: ./../action/resolve-environment
id: resolve-environment-js
with:
language: javascript-typescript

- name: Fail if JavaScript/TypeScript configuration present
if: matrix.version != 'stable-v2.13.4' && fromJSON(steps.resolve-environment-js.outputs.environment).configuration.javascript
run: exit 1
24 changes: 13 additions & 11 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 @@ -624,6 +624,7 @@ export async function getCodeQLForCmd(
"--db-cluster",
config.dbLocation,
`--source-root=${sourceRoot}`,
...(await getLanguageAliasingArguments(this)),
...extraArgs,
...getExtraOptionsFromEnv(["database", "init"]),
],
Expand Down Expand Up @@ -737,20 +738,12 @@ export async function getCodeQLForCmd(
}
},
async betterResolveLanguages() {
const extraArgs: string[] = [];

if (
await util.codeQlVersionAbove(this, CODEQL_VERSION_LANGUAGE_ALIASING)
) {
extraArgs.push("--extractor-include-aliases");
}

const codeqlArgs = [
"resolve",
"languages",
"--format=betterjson",
"--extractor-options-verbosity=4",
...extraArgs,
...(await getLanguageAliasingArguments(this)),
...getExtraOptionsFromEnv(["resolve", "languages"]),
];
const output = await runTool(cmd, codeqlArgs);
Expand Down Expand Up @@ -787,12 +780,13 @@ export async function getCodeQLForCmd(
},
async resolveBuildEnvironment(
workingDir: string | undefined,
language: Language,
language: string,
) {
const codeqlArgs = [
"resolve",
"build-environment",
`--language=${language}`,
...(await getLanguageAliasingArguments(this)),
...getExtraOptionsFromEnv(["resolve", "build-environment"]),
];
if (workingDir !== undefined) {
Expand Down Expand Up @@ -1082,6 +1076,7 @@ export async function getCodeQLForCmd(
"extractor",
"--format=json",
`--language=${language}`,
...(await getLanguageAliasingArguments(this)),
...getExtraOptionsFromEnv(["resolve", "extractor"]),
],
{
Expand Down Expand Up @@ -1470,3 +1465,10 @@ async function isDiagnosticsExportInvalidSarifFixed(
CODEQL_VERSION_DIAGNOSTICS_EXPORT_FIXED,
);
}

async function getLanguageAliasingArguments(codeql: CodeQL): Promise<string[]> {
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_LANGUAGE_ALIASING)) {
return ["--extractor-include-aliases"];
}
return [];
}
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
Loading

0 comments on commit 2723530

Please sign in to comment.