Skip to content

Commit 95246ce

Browse files
committed
Prefer explicit env var to binary accessibility check
1 parent a7e88a4 commit 95246ce

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

.github/workflows/__global-proxy.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pr-checks/checks/global-proxy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ services:
2323
- 3128:3128
2424
env:
2525
https_proxy: http://squid-proxy:3128
26+
CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION: true
2627
steps:
2728
- uses: ./../action/init
2829
with:

src/config-utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import {
5454
getCodeQLMemoryLimit,
5555
getErrorMessage,
5656
isInTestMode,
57-
isBinaryAccessible,
5857
} from "./util";
5958

6059
export * from "./config/db-config";
@@ -937,10 +936,13 @@ export async function initConfig(
937936
await logGitVersionTelemetry(config, gitVersion);
938937
} catch (e) {
939938
logger.warning(`Could not determine Git version: ${getErrorMessage(e)}`);
940-
// Throw the error in test mode so it's more visible, but tolerate cases
941-
// where the git binary is not present, for example because we're running
942-
// in a Docker container.
943-
if (isInTestMode() && (await isBinaryAccessible("git", logger))) {
939+
// Throw the error in test mode so it's more visible, unless the environment
940+
// variable is set to tolerate this, for example because we're running in a
941+
// Docker container where git may not be available.
942+
if (
943+
isInTestMode() &&
944+
process.env.CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION !== "true"
945+
) {
944946
throw e;
945947
}
946948
}

src/environment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,10 @@ export enum EnvVar {
129129
* the workflow is valid and validation is not necessary.
130130
*/
131131
SKIP_WORKFLOW_VALIDATION = "CODEQL_ACTION_SKIP_WORKFLOW_VALIDATION",
132+
133+
/**
134+
* Whether to tolerate failure to determine the git version (only applicable in test mode).
135+
* Intended for use in environments where git may not be installed, such as Docker containers.
136+
*/
137+
TOLERATE_MISSING_GIT_VERSION = "CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION",
132138
}

src/git-utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export class GitVersionInfo {
4040
/**
4141
* Gets the version of Git installed on the system and throws an error if
4242
* the version cannot be determined.
43-
*
44-
* @returns The Git version string (e.g., "2.40.0").
45-
* @throws {Error} if the version could not be determined.
4643
*/
4744
export async function getGitVersionOrThrow(): Promise<GitVersionInfo> {
4845
const stdout = await runGitCommand(

0 commit comments

Comments
 (0)