mirror of
https://github.com/gradle/actions.git
synced 2026-06-26 05:20:43 +00:00
97715a29bc
Redesigns the caching section of the Job Summary into a single, consistent layout across every cache provider and state, and integrates the provider message into the report rather than appending it disconnected at the bottom. ## Motivation The caching report was produced by three divergent code paths (NoOp / basic / enhanced), each rendering its own markdown: - **Explicitly disabled** → a one-line message, no expand, no provider note. - **Enhanced** (incl. skipped-due-to-existing-home) → a full `<details>` block. - **Basic** → a one-line message with **no** expandable details at all. The Enhanced/Basic provider note floated at the very bottom, disconnected from the report. ## What changed `save()` now returns structured `CacheReport` data instead of pre-rendered HTML, and a single renderer (`caching-report.ts`) produces one unified layout for all variants: - **Section heading**: `#### <icon> Gradle Caching — <Provider> (<status>)` - **Status line** explaining what the cache did - **Integrated provider note** woven in under the heading — now shown **unconditionally** (no longer gated on license acceptance) - **Expandable cache-entry details** when there are entries — basic caching now gets this too The two disabled variants (explicitly disabled, and skipped due to a pre-existing Gradle User Home) render as **compact callouts with no expandable section**. ### Main repo - `caching-report.ts` (new): central renderer + all framing copy + entry table/`<pre>` helpers. - `cache-service.ts`: `CacheReport` / `CacheEntryReport` / status types; `save()` returns `CacheReport`. - `cache-service-loader.ts`: `NoOp` returns a report; `LicenseWarningCacheService` removed; new `getProviderNote()`. - `cache-service-basic.ts`: builds a `CacheReport`. - `job-summary.ts` / `setup-gradle.ts`: thread `CacheReport` + `ProviderNote`. - `configuration.ts`: remove now-unused `isCacheLicenseAccepted()`. ### Vendored library The structured contract requires **gradle-actions-caching v0.7.0** (gradle/actions-caching#74). This PR updates the vendored library to that release — the official `Update gradle-actions-caching library to v0.7.0` vendor commit is included here, so merging this PR ships the redesign together with the library it depends on. ## Testing - Both repos build; prettier + eslint clean. - `gradle/actions`: 363/363 Jest tests pass, including new `caching-report.test.ts` covering every variant. - `gradle-actions-caching`: 74/74 pass under JDK 17. - Rendered markdown verified for all five variants (enhanced/basic enabled & read-only, disabled, skipped). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Bot Githubaction <bot-githubaction@gradle.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
import {pathToFileURL} from 'url'
|
|
|
|
import {CacheConfig, CacheProvider} from './configuration'
|
|
import {BasicCacheService} from './cache-service-basic'
|
|
import {BuildResult} from './build-results'
|
|
import {CacheOptions, CacheReport, CacheService} from './cache-service'
|
|
import {ProviderNote} from './caching-report'
|
|
|
|
const ENHANCED_CACHE_MESSAGE = `Enhanced Caching: This build is using the proprietary 'gradle-actions-caching' provider for optimized caching support. See https://github.com/gradle/actions/blob/main/DISTRIBUTION.md for terms of use and opt-out instructions.`
|
|
|
|
const BASIC_CACHE_MESSAGE = `Basic Caching: This build uses the basic open-source caching provider. For faster builds and advanced features, consider switching to the Enhanced Caching provider. See https://github.com/gradle/actions/blob/main/DISTRIBUTION.md for details.`
|
|
|
|
class NoOpCacheService implements CacheService {
|
|
async restore(_gradleUserHome: string, _cacheOptions: CacheOptions): Promise<void> {
|
|
return
|
|
}
|
|
|
|
async save(
|
|
_gradleUserHome: string,
|
|
_buildResults: BuildResult[],
|
|
_cacheOptions: CacheOptions
|
|
): Promise<CacheReport> {
|
|
return {status: 'disabled', entries: []}
|
|
}
|
|
}
|
|
|
|
export async function getCacheService(cacheConfig: CacheConfig): Promise<CacheService> {
|
|
if (cacheConfig.isCacheDisabled()) {
|
|
logCacheMessage('Cache is disabled: will not restore state from previous builds.')
|
|
return new NoOpCacheService()
|
|
}
|
|
|
|
if (cacheConfig.getCacheProvider() === CacheProvider.Basic) {
|
|
logCacheMessage(BASIC_CACHE_MESSAGE)
|
|
return new BasicCacheService()
|
|
}
|
|
|
|
logCacheMessage(ENHANCED_CACHE_MESSAGE)
|
|
return loadVendoredCacheService()
|
|
}
|
|
|
|
/**
|
|
* Identifies the caching provider for the Job Summary. Returns `undefined` when
|
|
* caching is disabled, since no provider is engaged in that case.
|
|
*/
|
|
export function getProviderNote(cacheConfig: CacheConfig): ProviderNote | undefined {
|
|
if (cacheConfig.isCacheDisabled()) {
|
|
return undefined
|
|
}
|
|
return cacheConfig.getCacheProvider() === CacheProvider.Basic ? {kind: 'basic'} : {kind: 'enhanced'}
|
|
}
|
|
|
|
export async function loadVendoredCacheService(): Promise<CacheService> {
|
|
const vendoredLibraryPath = findVendoredLibraryPath()
|
|
const moduleUrl = pathToFileURL(vendoredLibraryPath).href
|
|
return (await import(moduleUrl)) as CacheService
|
|
}
|
|
|
|
function findVendoredLibraryPath(): string {
|
|
const moduleDir = import.meta.dirname
|
|
const absolutePath = path.resolve(moduleDir, '../../../sources/vendor/gradle-actions-caching/index.js')
|
|
|
|
if (fs.existsSync(absolutePath)) {
|
|
return absolutePath
|
|
}
|
|
|
|
throw new Error(`Unable to locate vendored cache library at ${absolutePath}.`)
|
|
}
|
|
|
|
export function logCacheMessage(message: string): void {
|
|
console.info(message)
|
|
}
|