mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Add git version check for overlay analysis enablement
Overlay analysis depends on `getFileOidsUnderPath`, which uses `git ls-files --format` option that requires Git 2.38.0+. This change adds a check for the git version before enabling overlay analysis. Co-authored-by: henrymercer <14129055+henrymercer@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,67 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as io from "@actions/io";
|
||||
import * as semver from "semver";
|
||||
|
||||
import {
|
||||
getOptionalInput,
|
||||
getWorkflowEvent,
|
||||
getWorkflowEventName,
|
||||
} from "./actions-util";
|
||||
import { Logger } from "./logging";
|
||||
import { ConfigurationError, getRequiredEnvParam } from "./util";
|
||||
|
||||
/**
|
||||
* Minimum Git version required for overlay analysis. The `git ls-files --format`
|
||||
* option, which is used by `getFileOidsUnderPath`, was introduced in Git 2.38.0.
|
||||
*/
|
||||
export const GIT_MINIMUM_VERSION_FOR_OVERLAY = "2.38.0";
|
||||
|
||||
/**
|
||||
* Gets the version of Git installed on the system.
|
||||
*
|
||||
* @returns The Git version string (e.g., "2.40.0"), or undefined if the
|
||||
* version could not be determined.
|
||||
*/
|
||||
export async function getGitVersion(): Promise<string | undefined> {
|
||||
try {
|
||||
const stdout = await runGitCommand(
|
||||
undefined,
|
||||
["--version"],
|
||||
"Failed to get git version.",
|
||||
);
|
||||
// Expected output format: "git version 2.40.0"
|
||||
const match = stdout.match(/git version (\d+\.\d+\.\d+)/);
|
||||
if (match?.[1]) {
|
||||
return match[1];
|
||||
}
|
||||
return undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the installed Git version is at least the given required version.
|
||||
*
|
||||
* @param requiredVersion The minimum required Git version.
|
||||
* @param logger A logger to use for logging.
|
||||
* @returns `true` if the installed Git version is at least the required version,
|
||||
* `false` otherwise.
|
||||
*/
|
||||
export async function gitVersionAtLeast(
|
||||
requiredVersion: string,
|
||||
logger: Logger,
|
||||
): Promise<boolean> {
|
||||
const version = await getGitVersion();
|
||||
if (version === undefined) {
|
||||
logger.debug("Could not determine Git version.");
|
||||
return false;
|
||||
}
|
||||
logger.debug(`Installed Git version is ${version}.`);
|
||||
return semver.gte(version, requiredVersion);
|
||||
}
|
||||
|
||||
export const runGitCommand = async function (
|
||||
workingDirectory: string | undefined,
|
||||
args: string[],
|
||||
|
||||
Reference in New Issue
Block a user