Rust: throw configuration errors if requested and not correctly enabled

This commit is contained in:
Paolo Tranquilli 2025-02-20 11:25:51 +01:00
parent 3971ed2a74
commit cfedae723e
3 changed files with 28 additions and 39 deletions

27
lib/init-action.js generated
View file

@ -37,6 +37,7 @@ const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const core = __importStar(require("@actions/core"));
const io = __importStar(require("@actions/io"));
const semver = __importStar(require("semver"));
const uuid_1 = require("uuid");
const actions_util_1 = require("./actions-util");
const api_client_1 = require("./api-client");
@ -349,24 +350,18 @@ async function run() {
if (config.languages.includes(languages_1.Language.rust)) {
const feat = feature_flags_1.Feature.RustAnalysis;
const minVer = feature_flags_1.featureConfig[feat].minimumVersion;
if (!(await (0, util_1.codeQlVersionAtLeast)(codeql, minVer))) {
logger.error(`Experimental rust analysis requires CodeQL version ${minVer} or higher`);
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
if (await features.getValue(feat, codeql)) {
core.exportVariable(envVar, "true");
}
else {
const envVar = feature_flags_1.featureConfig[feat].envVar;
const expVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
if (process.env[envVar] === "true" ||
(await features.getValue(feat, codeql))) {
core.exportVariable(expVar, "true");
}
if (process.env[expVar] === "true") {
logger.info("Experimental rust analysis enabled");
}
else {
logger.error("Experimental rust analysis requested but not enabled. " +
"You must set the CODEQL_ENABLE_EXPERIMENTAL_FEATURES environment variable to true");
}
if (process.env[envVar] !== "true") {
throw new util_1.ConfigurationError(`Experimental and not officially supported Rust analysis requires setting {envVar}=true in the environment`);
}
const actualVer = (await codeql.getVersion()).version;
if (semver.lt(actualVer, minVer)) {
throw new util_1.ConfigurationError(`Experimental rust analysis is supported by CodeQL CLI version ${minVer} or higher, but found version ${actualVer}`);
}
logger.info("Experimental rust analysis enabled");
}
// Restore dependency cache(s), if they exist.
if ((0, caching_utils_1.shouldRestoreCache)(config.dependencyCachingEnabled)) {

File diff suppressed because one or more lines are too long