Skip to content

Commit 201b400

Browse files
committed
Rust: throw configuration errors if requested and not correctly enabled
1 parent 3971ed2 commit 201b400

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/init-action.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path";
33

44
import * as core from "@actions/core";
55
import * as io from "@actions/io";
6+
import * as semver from "semver";
67
import { v4 as uuidV4 } from "uuid";
78

89
import {
@@ -72,6 +73,7 @@ import {
7273
getErrorMessage,
7374
} from "./util";
7475
import { validateWorkflow } from "./workflow";
76+
import { util } from "node-forge";
7577

7678
/** Fields of the init status report that can be sent before `config` is populated. */
7779
interface InitStatusReport extends StatusReportBase {
@@ -580,28 +582,22 @@ async function run() {
580582
if (config.languages.includes(Language.rust)) {
581583
const feat = Feature.RustAnalysis;
582584
const minVer = featureConfig[feat].minimumVersion as string;
583-
if (!(await codeQlVersionAtLeast(codeql, minVer))) {
584-
logger.error(
585-
`Experimental rust analysis requires CodeQL version ${minVer} or higher`,
585+
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
586+
if (await features.getValue(feat, codeql)) {
587+
core.exportVariable(envVar, "true");
588+
}
589+
if (process.env[envVar] !== "true") {
590+
throw new ConfigurationError(
591+
`Experimental and not officially supported Rust analysis requires setting {envVar}=true in the environment`
592+
);
593+
}
594+
const actualVer = (await codeql.getVersion()).version;
595+
if (semver.lt(actualVer, minVer)) {
596+
throw new ConfigurationError(
597+
`Experimental rust analysis is supported by CodeQL CLI version ${minVer} or higher, but found version ${actualVer}`,
586598
);
587-
} else {
588-
const envVar = featureConfig[feat].envVar;
589-
const expVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
590-
if (
591-
process.env[envVar] === "true" ||
592-
(await features.getValue(feat, codeql))
593-
) {
594-
core.exportVariable(expVar, "true");
595-
}
596-
if (process.env[expVar] === "true") {
597-
logger.info("Experimental rust analysis enabled");
598-
} else {
599-
logger.error(
600-
"Experimental rust analysis requested but not enabled. " +
601-
"You must set the CODEQL_ENABLE_EXPERIMENTAL_FEATURES environment variable to true",
602-
);
603-
}
604599
}
600+
logger.info("Experimental rust analysis enabled");
605601
}
606602

607603
// Restore dependency cache(s), if they exist.

0 commit comments

Comments
 (0)