Log CLI version and git commit hash (v2) (#6176)
This commit is contained in:
parent
3e004048cf
commit
dd55a82a28
|
@ -37,5 +37,6 @@ packages/*/coverage/
|
|||
|
||||
# Generated files
|
||||
packages/cli/src/generated/
|
||||
packages/core/src/generated/
|
||||
.integration-tests/
|
||||
packages/vscode-ide-companion/*.vsix
|
||||
|
|
|
@ -30,6 +30,7 @@ import {
|
|||
} from '../../utils/user_account.js';
|
||||
import { getInstallationId } from '../../utils/user_id.js';
|
||||
import { FixedDeque } from 'mnemonist';
|
||||
import { GIT_COMMIT_INFO, CLI_VERSION } from '../../generated/git-commit.js';
|
||||
import { DetectedIde, detectIde } from '../../ide/detect-ide.js';
|
||||
|
||||
const start_session_event_name = 'start_session';
|
||||
|
@ -374,6 +375,14 @@ export class ClearcutLogger {
|
|||
EventMetadataKey.GEMINI_CLI_START_SESSION_TELEMETRY_LOG_USER_PROMPTS_ENABLED,
|
||||
value: event.telemetry_log_user_prompts_enabled.toString(),
|
||||
},
|
||||
{
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_VERSION,
|
||||
value: CLI_VERSION,
|
||||
},
|
||||
{
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_GIT_COMMIT_HASH,
|
||||
value: GIT_COMMIT_INFO,
|
||||
},
|
||||
];
|
||||
|
||||
// Flush start event immediately
|
||||
|
|
|
@ -157,6 +157,12 @@ export enum EventMetadataKey {
|
|||
// Logs the session id
|
||||
GEMINI_CLI_SESSION_ID = 40,
|
||||
|
||||
// Logs the Gemini CLI version
|
||||
GEMINI_CLI_VERSION = 54,
|
||||
|
||||
// Logs the Gemini CLI Git commit hash
|
||||
GEMINI_CLI_GIT_COMMIT_HASH = 55,
|
||||
|
||||
// ==========================================================================
|
||||
// Loop Detected Event Keys
|
||||
// ===========================================================================
|
||||
|
|
|
@ -21,16 +21,24 @@ import { execSync } from 'child_process';
|
|||
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
||||
import { dirname, join, relative } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { readPackageUp } from 'read-package-up';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const root = join(__dirname, '..');
|
||||
const scriptPath = relative(root, fileURLToPath(import.meta.url));
|
||||
const generatedDir = join(root, 'packages/cli/src/generated');
|
||||
const gitCommitFile = join(generatedDir, 'git-commit.ts');
|
||||
const generatedCliDir = join(root, 'packages/cli/src/generated');
|
||||
const cliGitCommitFile = join(generatedCliDir, 'git-commit.ts');
|
||||
const generatedCoreDir = join(root, 'packages/core/src/generated');
|
||||
const coreGitCommitFile = join(generatedCoreDir, 'git-commit.ts');
|
||||
let gitCommitInfo = 'N/A';
|
||||
let cliVersion = 'UNKNOWN';
|
||||
|
||||
if (!existsSync(generatedDir)) {
|
||||
mkdirSync(generatedDir, { recursive: true });
|
||||
if (!existsSync(generatedCliDir)) {
|
||||
mkdirSync(generatedCliDir, { recursive: true });
|
||||
}
|
||||
|
||||
if (!existsSync(generatedCoreDir)) {
|
||||
mkdirSync(generatedCoreDir, { recursive: true });
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -40,6 +48,9 @@ try {
|
|||
if (gitHash) {
|
||||
gitCommitInfo = gitHash;
|
||||
}
|
||||
|
||||
const result = await readPackageUp();
|
||||
cliVersion = result?.packageJson?.version ?? 'UNKNOWN';
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
@ -53,6 +64,8 @@ const fileContent = `/**
|
|||
// This file is auto-generated by the build script (${scriptPath})
|
||||
// Do not edit this file manually.
|
||||
export const GIT_COMMIT_INFO = '${gitCommitInfo}';
|
||||
export const CLI_VERSION = '${cliVersion}';
|
||||
`;
|
||||
|
||||
writeFileSync(gitCommitFile, fileContent);
|
||||
writeFileSync(cliGitCommitFile, fileContent);
|
||||
writeFileSync(coreGitCommitFile, fileContent);
|
||||
|
|
Loading…
Reference in New Issue