diff --git a/lib/analyze-action.js b/lib/analyze-action.js index bf59496d5..bc09ce15d 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -93330,7 +93330,7 @@ async function makeGlobber(patterns) { return glob.create(patterns.join("\n")); } async function uploadDependencyCaches(config, logger, minimizeJavaJars) { - const status = {}; + const status = []; for (const language of config.languages) { const cacheConfig = getDefaultCacheConfig()[language]; if (cacheConfig === void 0) { @@ -93341,7 +93341,7 @@ async function uploadDependencyCaches(config, logger, minimizeJavaJars) { } const globber = await makeGlobber(cacheConfig.hash); if ((await globber.glob()).length === 0) { - status[language] = { result: "no-hash" /* NoHash */ }; + status.push({ language, result: "no-hash" /* NoHash */ }); logger.info( `Skipping upload of dependency cache for ${language} as we cannot calculate a hash for the cache key.` ); @@ -93349,7 +93349,7 @@ async function uploadDependencyCaches(config, logger, minimizeJavaJars) { } const size = await getTotalCacheSize(cacheConfig.paths, logger, true); if (size === 0) { - status[language] = { result: "empty" /* Empty */ }; + status.push({ language, result: "empty" /* Empty */ }); logger.info( `Skipping upload of dependency cache for ${language} since it is empty.` ); @@ -93363,18 +93363,19 @@ async function uploadDependencyCaches(config, logger, minimizeJavaJars) { const start = performance.now(); await actionsCache3.saveCache(cacheConfig.paths, key); const upload_duration_ms = Math.round(performance.now() - start); - status[language] = { + status.push({ + language, result: "stored" /* Stored */, upload_size_bytes: Math.round(size), upload_duration_ms - }; + }); } catch (error2) { if (error2 instanceof actionsCache3.ReserveCacheError) { logger.info( `Not uploading cache for ${language}, because ${key} is already in use.` ); logger.debug(error2.message); - status[language] = { result: "duplicate" /* Duplicate */ }; + status.push({ language, result: "duplicate" /* Duplicate */ }); } else { throw error2; } @@ -95963,9 +95964,7 @@ async function sendStatusReport2(startedAt, config, stats, error2, trapCacheUplo ...stats || {}, ...dbCreationTimings || {}, ...trapCacheCleanup || {}, - dependency_caching_upload_results: JSON.stringify( - dependencyCacheResults ?? {} - ) + dependency_caching_upload_results: dependencyCacheResults }; if (config && didUploadTrapCaches) { const trapCacheUploadStatusReport = { diff --git a/lib/init-action-post.js b/lib/init-action-post.js index ae5bee748..8194dffd7 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -133803,7 +133803,7 @@ async function runWrapper() { ...statusReportBase, ...uploadFailedSarifResult, job_status: getFinalJobStatus(), - dependency_caching_usage: JSON.stringify(dependencyCachingUsage ?? {}) + dependency_caching_usage: dependencyCachingUsage }; logger.info("Sending status report for init-post step."); await sendStatusReport(statusReport); diff --git a/lib/init-action.js b/lib/init-action.js index 994a68e6d..e0e99987a 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -88175,7 +88175,7 @@ async function makeGlobber(patterns) { return glob.create(patterns.join("\n")); } async function downloadDependencyCaches(languages, logger, minimizeJavaJars) { - const status = {}; + const status = []; for (const language of languages) { const cacheConfig = getDefaultCacheConfig()[language]; if (cacheConfig === void 0) { @@ -88186,7 +88186,7 @@ async function downloadDependencyCaches(languages, logger, minimizeJavaJars) { } const globber = await makeGlobber(cacheConfig.hash); if ((await globber.glob()).length === 0) { - status[language] = { hit_kind: "no-hash" /* NoHash */ }; + status.push({ language, hit_kind: "no-hash" /* NoHash */ }); logger.info( `Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.` ); @@ -88211,12 +88211,9 @@ async function downloadDependencyCaches(languages, logger, minimizeJavaJars) { if (hitKey !== void 0) { logger.info(`Cache hit on key ${hitKey} for ${language}.`); const hit_kind = hitKey === primaryKey ? "exact" /* Exact */ : "partial" /* Partial */; - status[language] = { - hit_kind, - download_duration_ms - }; + status.push({ language, hit_kind, download_duration_ms }); } else { - status[language] = { hit_kind: "miss" /* Miss */ }; + status.push({ language, hit_kind: "miss" /* Miss */ }); logger.info(`No suitable cache found for ${language}.`); } } @@ -90361,9 +90358,7 @@ async function createInitWithConfigStatusReport(config, initStatusReport, config trap_cache_download_duration_ms: Math.round(config.trapCacheDownloadTime), overlay_base_database_download_size_bytes: overlayBaseDatabaseStats?.databaseSizeBytes, overlay_base_database_download_duration_ms: overlayBaseDatabaseStats?.databaseDownloadDurationMs, - dependency_caching_restore_results: JSON.stringify( - dependencyCachingResults ?? {} - ), + dependency_caching_restore_results: dependencyCachingResults, query_filters: JSON.stringify( config.originalUserInput["query-filters"] ?? [] ), diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 6422981ce..bb5ee2d91 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -59,7 +59,7 @@ interface AnalysisStatusReport QueriesStatusReport {} interface DependencyCachingUploadStatusReport { - dependency_caching_upload_results?: string; + dependency_caching_upload_results?: DependencyCacheUploadStatusReport; } interface FinishStatusReport @@ -104,9 +104,7 @@ async function sendStatusReport( ...(stats || {}), ...(dbCreationTimings || {}), ...(trapCacheCleanup || {}), - dependency_caching_upload_results: JSON.stringify( - dependencyCacheResults ?? {}, - ), + dependency_caching_upload_results: dependencyCacheResults, }; if (config && didUploadTrapCaches) { const trapCacheUploadStatusReport: FinishWithTrapUploadStatusReport = { diff --git a/src/dependency-caching.ts b/src/dependency-caching.ts index dedd1075c..df82e0d57 100644 --- a/src/dependency-caching.ts +++ b/src/dependency-caching.ts @@ -99,14 +99,13 @@ export enum CacheHitKind { /** Represents results of trying to restore a dependency cache for a language. */ export interface DependencyCacheRestoreStatus { + language: Language; hit_kind: CacheHitKind; download_duration_ms?: number; } /** A partial mapping from languages to the results of restoring dependency caches for them. */ -export type DependencyCacheRestoreStatusReport = Partial< - Record ->; +export type DependencyCacheRestoreStatusReport = DependencyCacheRestoreStatus[]; /** * Attempts to restore dependency caches for the languages being analyzed. @@ -121,7 +120,7 @@ export async function downloadDependencyCaches( logger: Logger, minimizeJavaJars: boolean, ): Promise { - const status: DependencyCacheRestoreStatusReport = {}; + const status: DependencyCacheRestoreStatusReport = []; for (const language of languages) { const cacheConfig = getDefaultCacheConfig()[language]; @@ -138,7 +137,7 @@ export async function downloadDependencyCaches( const globber = await makeGlobber(cacheConfig.hash); if ((await globber.glob()).length === 0) { - status[language] = { hit_kind: CacheHitKind.NoHash }; + status.push({ language, hit_kind: CacheHitKind.NoHash }); logger.info( `Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`, ); @@ -168,12 +167,9 @@ export async function downloadDependencyCaches( logger.info(`Cache hit on key ${hitKey} for ${language}.`); const hit_kind = hitKey === primaryKey ? CacheHitKind.Exact : CacheHitKind.Partial; - status[language] = { - hit_kind, - download_duration_ms, - }; + status.push({ language, hit_kind, download_duration_ms }); } else { - status[language] = { hit_kind: CacheHitKind.Miss }; + status.push({ language, hit_kind: CacheHitKind.Miss }); logger.info(`No suitable cache found for ${language}.`); } } @@ -195,15 +191,14 @@ export enum CacheStoreResult { /** Represents results of trying to upload a dependency cache for a language. */ export interface DependencyCacheUploadStatus { + language: Language; result: CacheStoreResult; upload_size_bytes?: number; upload_duration_ms?: number; } /** A partial mapping from languages to the results of uploading dependency caches for them. */ -export type DependencyCacheUploadStatusReport = Partial< - Record ->; +export type DependencyCacheUploadStatusReport = DependencyCacheUploadStatus[]; /** * Attempts to store caches for the languages that were analyzed. @@ -219,7 +214,7 @@ export async function uploadDependencyCaches( logger: Logger, minimizeJavaJars: boolean, ): Promise { - const status: DependencyCacheUploadStatusReport = {}; + const status: DependencyCacheUploadStatusReport = []; for (const language of config.languages) { const cacheConfig = getDefaultCacheConfig()[language]; @@ -235,7 +230,7 @@ export async function uploadDependencyCaches( const globber = await makeGlobber(cacheConfig.hash); if ((await globber.glob()).length === 0) { - status[language] = { result: CacheStoreResult.NoHash }; + status.push({ language, result: CacheStoreResult.NoHash }); logger.info( `Skipping upload of dependency cache for ${language} as we cannot calculate a hash for the cache key.`, ); @@ -256,7 +251,7 @@ export async function uploadDependencyCaches( // Skip uploading an empty cache. if (size === 0) { - status[language] = { result: CacheStoreResult.Empty }; + status.push({ language, result: CacheStoreResult.Empty }); logger.info( `Skipping upload of dependency cache for ${language} since it is empty.`, ); @@ -274,11 +269,12 @@ export async function uploadDependencyCaches( await actionsCache.saveCache(cacheConfig.paths, key); const upload_duration_ms = Math.round(performance.now() - start); - status[language] = { + status.push({ + language, result: CacheStoreResult.Stored, upload_size_bytes: Math.round(size), upload_duration_ms, - }; + }); } catch (error) { // `ReserveCacheError` indicates that the cache key is already in use, which means that a // cache with that key already exists or is in the process of being uploaded by another @@ -289,7 +285,7 @@ export async function uploadDependencyCaches( ); logger.debug(error.message); - status[language] = { result: CacheStoreResult.Duplicate }; + status.push({ language, result: CacheStoreResult.Duplicate }); } else { // Propagate other errors upwards. throw error; diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 3b1d6aea7..97bf21ada 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -8,6 +8,7 @@ import { CodeScanning } from "./analyses"; import { getApiClient } from "./api-client"; import { CodeQL, getCodeQL } from "./codeql"; import { Config } from "./config-utils"; +import * as dependencyCaching from "./dependency-caching"; import { EnvVar } from "./environment"; import { Feature, FeatureEnablement } from "./feature-flags"; import { Logger } from "./logging"; @@ -46,7 +47,7 @@ export interface JobStatusReport { } export interface DependencyCachingUsageReport { - dependency_caching_usage?: string; + dependency_caching_usage?: dependencyCaching.DependencyCachingUsageReport; } function createFailedUploadFailedSarifResult( diff --git a/src/init-action-post.ts b/src/init-action-post.ts index 74759bb3c..9a93f38bc 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -128,7 +128,7 @@ async function runWrapper() { ...statusReportBase, ...uploadFailedSarifResult, job_status: initActionPostHelper.getFinalJobStatus(), - dependency_caching_usage: JSON.stringify(dependencyCachingUsage ?? {}), + dependency_caching_usage: dependencyCachingUsage, }; logger.info("Sending status report for init-post step."); await sendStatusReport(statusReport); diff --git a/src/status-report.ts b/src/status-report.ts index 41f63a20a..b795779ef 100644 --- a/src/status-report.ts +++ b/src/status-report.ts @@ -499,7 +499,7 @@ export interface InitWithConfigStatusReport extends InitStatusReport { /** Time taken to download the overlay-base database, in milliseconds. */ overlay_base_database_download_duration_ms?: number; /** Stringified JSON object representing information about the results of restoring dependency caches. */ - dependency_caching_restore_results: string; + dependency_caching_restore_results?: DependencyCacheRestoreStatusReport; /** Stringified JSON array of registry configuration objects, from the 'registries' config field or workflow input. **/ registries: string; @@ -574,9 +574,7 @@ export async function createInitWithConfigStatusReport( overlayBaseDatabaseStats?.databaseSizeBytes, overlay_base_database_download_duration_ms: overlayBaseDatabaseStats?.databaseDownloadDurationMs, - dependency_caching_restore_results: JSON.stringify( - dependencyCachingResults ?? {}, - ), + dependency_caching_restore_results: dependencyCachingResults, query_filters: JSON.stringify( config.originalUserInput["query-filters"] ?? [], ),