Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using the resolve-environment Action with language aliases #1923

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading