diff --git a/.github/workflows/__global-proxy.yml b/.github/workflows/__global-proxy.yml index 35f1f08fc..398796649 100644 --- a/.github/workflows/__global-proxy.yml +++ b/.github/workflows/__global-proxy.yml @@ -76,6 +76,7 @@ jobs: - uses: ./../action/analyze env: https_proxy: http://squid-proxy:3128 + CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION: true CODEQL_ACTION_TEST_MODE: true container: image: ubuntu:22.04 diff --git a/lib/init-action.js b/lib/init-action.js index cb447eeb6..9941f85b5 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -92985,7 +92985,7 @@ async function initConfig(features, inputs) { await logGitVersionTelemetry(config, gitVersion); } catch (e) { logger.warning(`Could not determine Git version: ${getErrorMessage(e)}`); - if (isInTestMode() && await isBinaryAccessible("git", logger)) { + if (isInTestMode() && process.env.CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION !== "true") { throw e; } } diff --git a/pr-checks/checks/global-proxy.yml b/pr-checks/checks/global-proxy.yml index 1d6412574..b965eec3b 100644 --- a/pr-checks/checks/global-proxy.yml +++ b/pr-checks/checks/global-proxy.yml @@ -23,6 +23,7 @@ services: - 3128:3128 env: https_proxy: http://squid-proxy:3128 + CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION: true steps: - uses: ./../action/init with: diff --git a/src/config-utils.ts b/src/config-utils.ts index d65fffdb2..406a63a6f 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -54,7 +54,6 @@ import { getCodeQLMemoryLimit, getErrorMessage, isInTestMode, - isBinaryAccessible, } from "./util"; export * from "./config/db-config"; @@ -937,10 +936,13 @@ export async function initConfig( await logGitVersionTelemetry(config, gitVersion); } catch (e) { logger.warning(`Could not determine Git version: ${getErrorMessage(e)}`); - // Throw the error in test mode so it's more visible, but tolerate cases - // where the git binary is not present, for example because we're running - // in a Docker container. - if (isInTestMode() && (await isBinaryAccessible("git", logger))) { + // Throw the error in test mode so it's more visible, unless the environment + // variable is set to tolerate this, for example because we're running in a + // Docker container where git may not be available. + if ( + isInTestMode() && + process.env.CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION !== "true" + ) { throw e; } } diff --git a/src/environment.ts b/src/environment.ts index 1d33c68a6..16617c647 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -129,4 +129,10 @@ export enum EnvVar { * the workflow is valid and validation is not necessary. */ SKIP_WORKFLOW_VALIDATION = "CODEQL_ACTION_SKIP_WORKFLOW_VALIDATION", + + /** + * Whether to tolerate failure to determine the git version (only applicable in test mode). + * Intended for use in environments where git may not be installed, such as Docker containers. + */ + TOLERATE_MISSING_GIT_VERSION = "CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION", } diff --git a/src/git-utils.ts b/src/git-utils.ts index 7902f845f..eb9d8c695 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -40,9 +40,6 @@ export class GitVersionInfo { /** * Gets the version of Git installed on the system and throws an error if * the version cannot be determined. - * - * @returns The Git version string (e.g., "2.40.0"). - * @throws {Error} if the version could not be determined. */ export async function getGitVersionOrThrow(): Promise { const stdout = await runGitCommand(