mirror of
https://github.com/github/codeql-action.git
synced 2026-04-05 03:02:16 +00:00
Merge pull request #2773 from github/redsun82/rust
Support rust analysis
This commit is contained in:
71
.github/workflows/__rust.yml
generated
vendored
Normal file
71
.github/workflows/__rust.yml
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# Warning: This file is generated automatically, and should not be modified.
|
||||
# Instead, please modify the template in the pr-checks directory and run:
|
||||
# (cd pr-checks; pip install ruamel.yaml@0.17.31 && python3 sync.py)
|
||||
# to regenerate this file.
|
||||
|
||||
name: PR Check - Rust analysis
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GO111MODULE: auto
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- releases/v*
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- synchronize
|
||||
- reopened
|
||||
- ready_for_review
|
||||
schedule:
|
||||
- cron: '0 5 * * *'
|
||||
workflow_dispatch: {}
|
||||
jobs:
|
||||
rust:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
version: linked
|
||||
- os: ubuntu-latest
|
||||
version: default
|
||||
- os: ubuntu-latest
|
||||
version: nightly-latest
|
||||
name: Rust analysis
|
||||
permissions:
|
||||
contents: read
|
||||
security-events: read
|
||||
timeout-minutes: 45
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Prepare test
|
||||
id: prepare-test
|
||||
uses: ./.github/actions/prepare-test
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
use-all-platform-bundle: 'false'
|
||||
setup-kotlin: 'true'
|
||||
- uses: ./../action/init
|
||||
with:
|
||||
languages: rust
|
||||
tools: ${{ steps.prepare-test.outputs.tools-url }}
|
||||
env:
|
||||
CODEQL_ACTION_RUST_ANALYSIS: true
|
||||
- uses: ./../action/analyze
|
||||
id: analysis
|
||||
with:
|
||||
upload-database: false
|
||||
- name: Check database
|
||||
shell: bash
|
||||
run: |
|
||||
RUST_DB="${{ fromJson(steps.analysis.outputs.db-locations).rust }}"
|
||||
if [[ ! -d "$RUST_DB" ]]; then
|
||||
echo "Did not create a database for Rust."
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CODEQL_ACTION_TEST_MODE: true
|
||||
6
lib/feature-flags.js
generated
6
lib/feature-flags.js
generated
@@ -68,6 +68,7 @@ var Feature;
|
||||
Feature["ExtractToToolcache"] = "extract_to_toolcache";
|
||||
Feature["PythonDefaultIsToNotExtractStdlib"] = "python_default_is_to_not_extract_stdlib";
|
||||
Feature["QaTelemetryEnabled"] = "qa_telemetry_enabled";
|
||||
Feature["RustAnalysis"] = "rust_analysis";
|
||||
Feature["ZstdBundleStreamingExtraction"] = "zstd_bundle_streaming_extraction";
|
||||
})(Feature || (exports.Feature = Feature = {}));
|
||||
exports.featureConfig = {
|
||||
@@ -132,6 +133,11 @@ exports.featureConfig = {
|
||||
minimumVersion: undefined,
|
||||
toolsFeature: tools_features_1.ToolsFeature.PythonDefaultIsToNotExtractStdlib,
|
||||
},
|
||||
[Feature.RustAnalysis]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_RUST_ANALYSIS",
|
||||
minimumVersion: "2.19.3",
|
||||
},
|
||||
[Feature.QaTelemetryEnabled]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_QA_TELEMETRY",
|
||||
|
||||
File diff suppressed because one or more lines are too long
21
lib/init-action.js
generated
21
lib/init-action.js
generated
@@ -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");
|
||||
@@ -345,6 +346,26 @@ async function run() {
|
||||
logger.info(`Setting C++ build-mode: none to ${value}`);
|
||||
core.exportVariable(bmnVar, value);
|
||||
}
|
||||
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
|
||||
if (config.languages.includes(languages_1.Language.rust)) {
|
||||
const feat = feature_flags_1.Feature.RustAnalysis;
|
||||
const minVer = feature_flags_1.featureConfig[feat].minimumVersion;
|
||||
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
|
||||
// if in default setup, it means the feature flag was on when rust was enabled
|
||||
// if the feature flag gets turned off, let's not have rust analysis throwing a configuration error
|
||||
// in that case rust analysis will be disabled only when default setup is refreshed
|
||||
if ((0, actions_util_1.isDefaultSetup)() || (await features.getValue(feat, codeql))) {
|
||||
core.exportVariable(envVar, "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)) {
|
||||
await (0, dependency_caching_1.downloadDependencyCaches)(config.languages, logger);
|
||||
|
||||
File diff suppressed because one or more lines are too long
23
pr-checks/checks/rust.yml
Normal file
23
pr-checks/checks/rust.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
name: "Rust analysis"
|
||||
description: "Tests creation of a Rust database"
|
||||
versions: ["linked", "default", "nightly-latest"]
|
||||
operatingSystems: ["ubuntu"]
|
||||
steps:
|
||||
- uses: ./../action/init
|
||||
with:
|
||||
languages: rust
|
||||
tools: ${{ steps.prepare-test.outputs.tools-url }}
|
||||
env:
|
||||
CODEQL_ACTION_RUST_ANALYSIS: true
|
||||
- uses: ./../action/analyze
|
||||
id: analysis
|
||||
with:
|
||||
upload-database: false
|
||||
- name: Check database
|
||||
shell: bash
|
||||
run: |
|
||||
RUST_DB="${{ fromJson(steps.analysis.outputs.db-locations).rust }}"
|
||||
if [[ ! -d "$RUST_DB" ]]; then
|
||||
echo "Did not create a database for Rust."
|
||||
exit 1
|
||||
fi
|
||||
@@ -53,6 +53,7 @@ export enum Feature {
|
||||
ExtractToToolcache = "extract_to_toolcache",
|
||||
PythonDefaultIsToNotExtractStdlib = "python_default_is_to_not_extract_stdlib",
|
||||
QaTelemetryEnabled = "qa_telemetry_enabled",
|
||||
RustAnalysis = "rust_analysis",
|
||||
ZstdBundleStreamingExtraction = "zstd_bundle_streaming_extraction",
|
||||
}
|
||||
|
||||
@@ -148,6 +149,11 @@ export const featureConfig: Record<
|
||||
minimumVersion: undefined,
|
||||
toolsFeature: ToolsFeature.PythonDefaultIsToNotExtractStdlib,
|
||||
},
|
||||
[Feature.RustAnalysis]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_RUST_ANALYSIS",
|
||||
minimumVersion: "2.19.3",
|
||||
},
|
||||
[Feature.QaTelemetryEnabled]: {
|
||||
defaultValue: false,
|
||||
envVar: "CODEQL_ACTION_QA_TELEMETRY",
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import * as io from "@actions/io";
|
||||
import * as semver from "semver";
|
||||
import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
import {
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
getRequiredInput,
|
||||
getTemporaryDirectory,
|
||||
persistInputs,
|
||||
isDefaultSetup,
|
||||
} from "./actions-util";
|
||||
import { getGitHubVersion } from "./api-client";
|
||||
import {
|
||||
@@ -30,7 +32,7 @@ import {
|
||||
makeDiagnostic,
|
||||
} from "./diagnostics";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Feature, Features } from "./feature-flags";
|
||||
import { Feature, featureConfig, Features } from "./feature-flags";
|
||||
import {
|
||||
checkInstallPython311,
|
||||
cleanupDatabaseClusterDirectory,
|
||||
@@ -72,7 +74,6 @@ import {
|
||||
getErrorMessage,
|
||||
} from "./util";
|
||||
import { validateWorkflow } from "./workflow";
|
||||
|
||||
/** Fields of the init status report that can be sent before `config` is populated. */
|
||||
interface InitStatusReport extends StatusReportBase {
|
||||
/** Value given by the user as the "tools" input. */
|
||||
@@ -576,6 +577,31 @@ async function run() {
|
||||
core.exportVariable(bmnVar, value);
|
||||
}
|
||||
|
||||
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
|
||||
if (config.languages.includes(Language.rust)) {
|
||||
const feat = Feature.RustAnalysis;
|
||||
const minVer = featureConfig[feat].minimumVersion as string;
|
||||
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
|
||||
// if in default setup, it means the feature flag was on when rust was enabled
|
||||
// if the feature flag gets turned off, let's not have rust analysis throwing a configuration error
|
||||
// in that case rust analysis will be disabled only when default setup is refreshed
|
||||
if (isDefaultSetup() || (await features.getValue(feat, codeql))) {
|
||||
core.exportVariable(envVar, "true");
|
||||
}
|
||||
if (process.env[envVar] !== "true") {
|
||||
throw new 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 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 (shouldRestoreCache(config.dependencyCachingEnabled)) {
|
||||
await downloadDependencyCaches(config.languages, logger);
|
||||
|
||||
7
tests/multi-language-repo/Cargo.lock
generated
Normal file
7
tests/multi-language-repo/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "test"
|
||||
version = "0.0.1"
|
||||
8
tests/multi-language-repo/Cargo.toml
Normal file
8
tests/multi-language-repo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "test"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
[[bin]]
|
||||
name = "main"
|
||||
path = "main.rs"
|
||||
|
||||
6
tests/multi-language-repo/main.rs
Normal file
6
tests/multi-language-repo/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
if true {
|
||||
println!("Hello world!")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user