Add legacy open-source caching module as default

Recover the pre-extraction caching code (from 7a4e0968~1) into a
standalone module at sources/legacy-caching/. This module bundles
@actions/cache@4.0.5 with the existing patch and adapts the old
caching API to the current CacheService interface.

The cache-service-loader now uses the legacy module by default and
only loads the proprietary vendored module when the license is
accepted. Both paths are wrapped in a LoggingCacheService that
identifies which module is active in logs and the Job Summary.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daz DeBoer
2026-04-01 13:10:20 -06:00
parent b93d9dccdc
commit e48bd1161b
18 changed files with 4404 additions and 41 deletions
+41
View File
@@ -0,0 +1,41 @@
import * as core from '@actions/core'
import * as os from 'os'
import {CacheConfig, CacheOptions} from './cache-config-adapter'
import {BuildResult, BuildResults} from './build-results-adapter'
import {CacheListener, generateCachingReport} from './cache-reporting'
import {DaemonController} from './daemon-controller'
import * as caches from './caches'
const CACHE_LISTENER_STATE_KEY = 'legacy-cache-listener'
export async function restore(gradleUserHome: string, cacheOptions: CacheOptions): Promise<void> {
const userHome = os.homedir()
const cacheListener = new CacheListener()
const cacheConfig = new CacheConfig(cacheOptions)
await caches.restore(userHome, gradleUserHome, cacheListener, cacheConfig)
// Persist the listener so it can be rehydrated in save()
core.saveState(CACHE_LISTENER_STATE_KEY, cacheListener.stringify())
}
export async function save(
gradleUserHome: string,
buildResults: BuildResult[],
cacheOptions: CacheOptions
): Promise<string> {
const userHome = os.homedir()
const cacheConfig = new CacheConfig(cacheOptions)
// Rehydrate the listener from the restore phase
const listenerState = core.getState(CACHE_LISTENER_STATE_KEY)
const cacheListener = CacheListener.rehydrate(listenerState)
const buildResultsWrapper = new BuildResults(buildResults)
const daemonController = new DaemonController(buildResultsWrapper)
await caches.save(userHome, gradleUserHome, cacheListener, daemonController, buildResultsWrapper, cacheConfig)
return generateCachingReport(cacheListener)
}