GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add git version check for overlay analysis enablement by Copilot · Pull Request #3370 · github/codeql-action Conversation
|
There was an error while loading. Please reload this page.
| File | Description |
|---|---|
| src/git-utils.ts | Added version constants, parsing function, and comparison utilities for Git version checking |
| src/git-utils.test.ts | Added comprehensive test coverage for version parsing and comparison logic |
| src/config-utils.ts | Integrated Git version check into overlay database mode determination |
| src/config-utils.test.ts | Added test cases for overlay fallback scenarios with old/missing Git versions |
| lib/*.js | Generated JavaScript output from TypeScript compilation |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@copilot Please address the following feedback: Error handling improvements
Telemetry
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…metry - Cache the git version to avoid recomputing on repeated calls - Refactor getGitVersion to getGitVersionOrThrow with detailed errors - Add getGitVersion that logs errors and handles caching - Add makeTelemetryDiagnostic helper to diagnostics.ts - Add logGitVersionTelemetry function to log git version telemetry - Call logGitVersionTelemetry in init-action.ts - Add resetCachedGitVersion for testing - Update tests to work with new function signatures and caching Co-authored-by: henrymercer <[email protected]>
Refactored bundle-download-telemetry and zstd-availability diagnostics in init-action.ts to use the new makeTelemetryDiagnostic helper function. Also added guard for empty languages array in logGitVersionTelemetry. Co-authored-by: henrymercer <[email protected]>
... Addressed in commits c3dc529 and 393c074: Error handling improvements:
Telemetry:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have given this an initial review. Two primary points:
git-utils. That should essentially just have getGitVersionOrThrow in it along with maybe the caching.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import type { Config } from "./config-utils"; | ||
| import { addDiagnostic, makeTelemetryDiagnostic } from "./diagnostics"; | ||
| import { Logger } from "./logging"; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am not overly keen on having this in git-utils. I think it would make more sense to keep this file for the git-related utility functions and then perform the version check / logging / diagnostic stuff elsewhere.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've moved the logging/diagnostics elsewhere, so now it's just the ability to get the git version. I think that's not worth moving to a new file.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| * displayed on the status page or CLI summary table. | ||
| * | ||
| * @param id An identifier under which it makes sense to group this diagnostic message. | ||
| * @param name Display name for the ID. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| * @param name Display name for the ID. | |
| * @param name Display name for the diagnostic. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| languages: [KnownLanguage.javascript], | ||
| codeqlVersion: CODEQL_OVERLAY_MINIMUM_VERSION, | ||
| gitRoot: "/some/git/root", | ||
| gitVersion: "2.40.0", // Default to a version that supports overlay analysis |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why is this not GIT_MINIMUM_VERSION_FOR_OVERLAY by default? Having a different version here might mislead someone into thinking that 2.40.0 is the minimum required, and it means we don't test the case for where the git version is exactly 2.38.0.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const version = await gitUtils.getGitVersionOrThrow(); | ||
| t.is(version, "2.40.0"); | ||
| } finally { | ||
| runGitCommandStub.restore(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| runGitCommandStub.restore(); | ||
| gitUtils.resetCachedGitVersion(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| t.true( | ||
| messages.some( | ||
| (m) => | ||
| m.type === "debug" && | ||
| typeof m.message === "string" && | ||
| m.message.includes("Could not determine Git version"), | ||
| ), | ||
| ); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| runGitCommandStub.restore(); | ||
| gitUtils.resetCachedGitVersion(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As above.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export const GIT_MINIMUM_VERSION_FOR_OVERLAY = "2.38.0"; | ||
|
|
||
| /** Cached git version to avoid recomputing it multiple times. */ | ||
| let cachedGitVersion: string | undefined; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Observation: This will cache the git version for one step in a workflow (e.g. init), but not across steps (e.g. init and analyze).
I think that's probably OK based on the current usage where logGitVersionTelemetry is only called once in init, but does lead to two points:
init.So this only becomes useful if we need the git version multiple times in the same action.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The caching makes for an easier API since we don't need to pass the git version around the program, but as you mention, we're not really making use of it now. I've removed it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Most of my feedback is addressed now, I think. I responded to the question in one of the conversations and added one new question. Other than those, this looks good now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| // Git version output can vary: "git version 2.40.0" or "git version 2.40.0.windows.1" | ||
| // We capture just the major.minor.patch portion to ensure semver compatibility. | ||
| const match = stdout.match(/git version (\d+\.\d+\.\d+)/); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's probably OK for now, especially if we report the git version in telemetry. We can keep an eye out for unusual version formats that we might care about.
One possible improvement might be to document in the JSDoc that only the first three components are considered or, indeed, return a more structured type than string which also makes it clear that the version might be truncated to just those parts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| logger.info(`Using Git version ${gitVersion}`); | ||
| await logGitVersionTelemetry(config, gitVersion); | ||
| } catch (e) { | ||
| logger.debug(`Could not determine Git version: ${getErrorMessage(e)}`); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Question about the log-levels here. The actual failure here is logged at debug level, and so wouldn't ordinarily be visible (especially in dynamic workflows).
Meanwhile, the subsequent message in getOverlayDatabaseMode is logged at warning level and so would show up quite prominently in the log (including workflow annotations).
That could lead to a situation where the actual problem is not easily debuggable. Should this be a warning instead / in addition to the gitVersion === undefined message?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /** | ||
| * Git version information | ||
| * | ||
| * The full version string as reported by `git --version` may not be | ||
| * semver-compatible (e.g., "2.40.0.windows.1"). This class captures both | ||
| * the full version string and a truncated semver-compatible version string | ||
| * (e.g., "2.40.0"). | ||
| */ | ||
| export class GitVersionInfo { | ||
| constructor( | ||
| /** Truncated semver-compatible version */ | ||
| public truncatedVersion: string, | ||
| /** Full version string as reported by `git --version` */ | ||
| public fullVersion: string, | ||
| ) {} | ||
|
|
||
| isAtLeast(minVersion: string): boolean { | ||
| return semver.gte(this.truncatedVersion, minVersion); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! This should make it more obvious what's going on.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const match = stdout.match(/^git version ((\d+\.\d+\.\d+).*)$/); | ||
| if (match?.[1]) { | ||
| return match[1]; | ||
| return new GitVersionInfo(match[2], match[1]); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
One comment: we might want to think about whether it is worthwhile to store whatever we get from git --version after ^git version as the fullVersion and then only store truncatedVersion if it matches the \d+\.\d+\.\d+ pattern. As it stands, we only store the fullVersion if it starts with the semver-like pattern.
I don't think this is a big deal since I'd expect the git versions to always start with at least three numeric components, so this probably doesn't need to be addressed at this point unless we find that we are missing data for troubleshooting purposes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a big deal since I'd expect the
gitversions to always start with at least three numeric components, so this probably doesn't need to be addressed at this point unless we find that we are missing data for troubleshooting purposes.
Agreed, I'll leave this as-is for now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .resolves("git version 2.40.0.windows.1"); | ||
|
|
||
| const version = await gitUtils.getGitVersionOrThrow(); | ||
| // Should extract just the major.minor.patch portion |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| // Should extract just the major.minor.patch portion | |
| // Should extract just the major.minor.patch portion as `truncatedVersion` |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| test("getGitVersionOrThrow returns version for valid git output", async (t) => { | ||
| sinon.stub(gitUtils as any, "runGitCommand").resolves("git version 2.40.0\n"); | ||
| sinon.stub(gitUtils as any, "runGitCommand").resolves("git version 2.40.0"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what motivated this change, but it reminded me that we might want to check that this works correctly across platforms depending on what git uses for line endings in its output there. I think I tried to do something like that for my tests in #3318
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM, aside from one oversight(?)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Docker container where git may not be available. | ||
| if ( | ||
| isInTestMode() && | ||
| process.env.CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION !== "true" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You added TOLERATE_MISSING_GIT_VERSION to the EnvVar enum, but aren't using it here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
![]()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.