Mirror project-cache type and report changes from the caching library

Prepares the consumer for the gated project-entry caching feature in the
gradle-actions-caching library. Source-only; the vendored bundle is refreshed
in a later commit.

- cache-service.ts: add develocityAccessToken / develocityServerUrl to the
  local CacheOptions mirror; replace ConfigurationCacheStatus (4 values) with
  the 9-value ProjectCacheStatus (not-active retired); rename
  CacheReport.configurationCache to projectCache.
- caching-report.ts: PROJECT_CACHE_COPY is an exhaustive
  Record<ProjectCacheStatus, string> so a missed status fails compilation;
  not-enabled maps to '' (dropped by the existing .filter(Boolean)).
  renderConfigCacheLine becomes renderProjectCacheLine, reading
  report.projectCache.
- Tests updated for the renamed field and new copy, including a not-enabled
  case that renders nothing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daz DeBoer
2026-06-13 14:42:39 -06:00
parent 54d3208a40
commit 3283118ee4
3 changed files with 57 additions and 20 deletions
+15 -2
View File
@@ -8,6 +8,8 @@ export interface CacheOptions {
strictMatch: boolean
cleanup: string
encryptionKey?: string
develocityAccessToken?: string
develocityServerUrl?: string
includes: string[]
excludes: string[]
}
@@ -27,7 +29,18 @@ export type CacheCleanupStatus =
| 'disabled-config-cache-hit'
| 'disabled-readonly'
export type ConfigurationCacheStatus = 'not-active' | 'restored' | 'not-restored' | 'restore-incomplete'
// Mirrors ProjectCacheStatus in the gradle-actions-caching library. The first three are set on
// restore (ungated); the rest on save, reflecting the opt-in + Develocity trial gate.
export type ProjectCacheStatus =
| 'restore-incomplete'
| 'restored'
| 'not-restored'
| 'not-enabled'
| 'trial-expired'
| 'trial-not-licensed'
| 'not-stored-no-develocity-plugin'
| 'stored'
| 'stored-no-configuration-cache'
export interface CacheEntryReport {
entryName: string
@@ -49,7 +62,7 @@ export interface CacheEntryReport {
export interface CacheReport {
status: CacheStatus
cleanup?: CacheCleanupStatus
configurationCache?: ConfigurationCacheStatus
projectCache?: ProjectCacheStatus
entries: CacheEntryReport[]
}
+19 -10
View File
@@ -1,4 +1,4 @@
import {CacheCleanupStatus, CacheEntryReport, CacheReport, CacheStatus, ConfigurationCacheStatus} from './cache-service'
import {CacheCleanupStatus, CacheEntryReport, CacheReport, CacheStatus, ProjectCacheStatus} from './cache-service'
const DOCS = 'https://github.com/gradle/actions/blob/main/docs/setup-gradle.md'
const DISTRIBUTION = 'https://github.com/gradle/actions/blob/main/DISTRIBUTION.md'
@@ -28,11 +28,19 @@ const CLEANUP_COPY: Record<CacheCleanupStatus, string> = {
'disabled-readonly': `[Cache cleanup](${DOCS}#configuring-cache-cleanup) is always disabled when the cache is read-only.`
}
const CONFIG_CACHE_COPY: Record<ConfigurationCacheStatus, string> = {
'not-active': `Configuration cache state was not cached — set a [cache-encryption-key](${DOCS}#cache-encryption-key) to enable configuration-cache caching.`,
restored: `Configuration cache state was restored from the cache.`,
'not-restored': `Configuration cache state was not restored — no cached data was available (e.g. the first run for this cache key).`,
'restore-incomplete': `Configuration cache state was not restored — the Gradle User Home was not fully restored.`
const PROJECT_CACHE_COPY: Record<ProjectCacheStatus, string> = {
// Restore (ungated).
'restore-incomplete': `Project state was not restored the Gradle User Home was not fully restored.`,
restored: `Project state (build-logic and configuration cache) was restored from the cache.`,
'not-restored': `Project state was not restored — no cached data was available (e.g. the first run for this cache key).`,
// Save, Tier A gate. 'not-enabled' renders nothing (dropped by the .filter(Boolean) below).
'not-enabled': ``,
'trial-expired': `Project state was not cached — the Develocity caching trial has expired.`,
'trial-not-licensed': `Project state was not cached — a valid Develocity trial token is required.`,
// Save, post-gate outcomes.
'not-stored-no-develocity-plugin': `Project state was not cached — applying the Develocity plugin is required to cache build-logic and configuration-cache state.`,
stored: `Project state (build-logic and configuration cache) was saved to the cache.`,
'stored-no-configuration-cache': `Build-logic state was cached. Storing configuration-cache data requires a build running Gradle >= 8.6 and a [valid encryption key](${DOCS}#cache-encryption-key).`
}
/**
@@ -76,8 +84,9 @@ function renderCleanupLine(cleanup?: CacheCleanupStatus): string | undefined {
return cleanup ? CLEANUP_COPY[cleanup] : undefined
}
function renderConfigCacheLine(configurationCache?: ConfigurationCacheStatus): string | undefined {
return configurationCache ? CONFIG_CACHE_COPY[configurationCache] : undefined
function renderProjectCacheLine(projectCache?: ProjectCacheStatus): string | undefined {
// PROJECT_CACHE_COPY['not-enabled'] is '', which the .filter(Boolean) at the call site drops.
return projectCache ? PROJECT_CACHE_COPY[projectCache] : undefined
}
function renderProviderNote(providerNote?: ProviderNote): string | undefined {
@@ -99,10 +108,10 @@ function renderDetails(report: CacheReport): string {
: `Entries: ${restored} restored, ${saved} saved - Expand for more details`
const cleanup = report.status === 'enabled' ? renderCleanupLine(report.cleanup) : undefined
const configCache = renderConfigCacheLine(report.configurationCache)
const projectCache = renderProjectCacheLine(report.projectCache)
const table = renderEntryTable(report.entries)
const pre = `<pre>\n${renderEntryDetails(report.entries)}</pre>`
const body = [STATUS_COPY[report.status], cleanup, configCache, table, pre].filter(Boolean).join('\n\n')
const body = [STATUS_COPY[report.status], cleanup, projectCache, table, pre].filter(Boolean).join('\n\n')
return `<details>
<summary>${summary}</summary>
+23 -8
View File
@@ -79,37 +79,52 @@ describe('renderCachingReport', () => {
expect(md).toContain('<summary>Entries: 1 restored, 0 saved - Expand for more details</summary>')
})
it('renders the configuration-cache status line inside the details', () => {
it('renders the project-cache status line inside the details', () => {
const report: CacheReport = {
status: 'enabled',
cleanup: 'enabled',
configurationCache: 'restored',
projectCache: 'restored',
entries: [entry()]
}
const md = renderCachingReport(report, ENHANCED)
const detailsBody = md.slice(md.indexOf('</summary>'))
expect(detailsBody).toContain('Configuration cache state was restored from the cache.')
expect(detailsBody).toContain(
'Project state (build-logic and configuration cache) was restored from the cache.'
)
})
it('explains an inactive configuration cache with a link to the encryption key docs', () => {
it('explains an omitted configuration cache with a link to the encryption key docs', () => {
const report: CacheReport = {
status: 'enabled',
cleanup: 'enabled',
configurationCache: 'not-active',
projectCache: 'stored-no-configuration-cache',
entries: [entry()]
}
const md = renderCachingReport(report, ENHANCED)
expect(md).toContain('Configuration cache state was not cached')
expect(md).toContain('Build-logic state was cached.')
expect(md).toContain('#cache-encryption-key')
})
it('omits the configuration-cache line when the status is absent', () => {
it('renders nothing for the not-enabled project-cache status', () => {
const report: CacheReport = {
status: 'enabled',
cleanup: 'enabled',
projectCache: 'not-enabled',
entries: [entry()]
}
const md = renderCachingReport(report, ENHANCED)
expect(md).not.toContain('Project state')
expect(md).not.toContain('Build-logic state')
})
it('omits the project-cache line when the status is absent', () => {
const report: CacheReport = {status: 'enabled', cleanup: 'enabled', entries: [entry()]}
const md = renderCachingReport(report, ENHANCED)
expect(md).not.toContain('Configuration cache state')
expect(md).not.toContain('Project state')
})
it('renders a compact disabled report with no note and no details', () => {