mirror of https://github.com/actions/toolkit
Add cross os opt-in functionality for cache on windows
parent
2867e318d4
commit
ec3a87298b
|
@ -61,6 +61,7 @@ export function isFeatureAvailable(): boolean {
|
|||
* @param paths a list of file paths to restore from the cache
|
||||
* @param primaryKey an explicit key for restoring the cache
|
||||
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
|
||||
* @param crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform
|
||||
* @param downloadOptions cache download options
|
||||
* @returns string returns the key for the cache hit, otherwise returns undefined
|
||||
*/
|
||||
|
@ -68,6 +69,7 @@ export async function restoreCache(
|
|||
paths: string[],
|
||||
primaryKey: string,
|
||||
restoreKeys?: string[],
|
||||
crossOsEnabled = false,
|
||||
options?: DownloadOptions
|
||||
): Promise<string | undefined> {
|
||||
checkPaths(paths)
|
||||
|
@ -93,7 +95,8 @@ export async function restoreCache(
|
|||
try {
|
||||
// path are needed to compute version
|
||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
||||
compressionMethod
|
||||
compressionMethod,
|
||||
crossOsEnabled
|
||||
})
|
||||
if (!cacheEntry?.archiveLocation) {
|
||||
// This is to support the old cache entry created by gzip on windows.
|
||||
|
@ -171,12 +174,14 @@ export async function restoreCache(
|
|||
*
|
||||
* @param paths a list of file paths to be cached
|
||||
* @param key an explicit key for restoring the cache
|
||||
* @param crossOsEnabled an optional boolean enabled to save cache on windows which could be restored on any platform
|
||||
* @param options cache upload options
|
||||
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
|
||||
*/
|
||||
export async function saveCache(
|
||||
paths: string[],
|
||||
key: string,
|
||||
crossOsEnabled = false,
|
||||
options?: UploadOptions
|
||||
): Promise<number> {
|
||||
checkPaths(paths)
|
||||
|
@ -227,6 +232,7 @@ export async function saveCache(
|
|||
paths,
|
||||
{
|
||||
compressionMethod,
|
||||
crossOsEnabled,
|
||||
cacheSize: archiveFileSize
|
||||
}
|
||||
)
|
||||
|
|
|
@ -73,13 +73,18 @@ function createHttpClient(): HttpClient {
|
|||
|
||||
export function getCacheVersion(
|
||||
paths: string[],
|
||||
compressionMethod?: CompressionMethod
|
||||
compressionMethod?: CompressionMethod,
|
||||
crossOsEnabled = false
|
||||
): string {
|
||||
const components = paths.concat(
|
||||
!compressionMethod || compressionMethod === CompressionMethod.Gzip
|
||||
? []
|
||||
: [compressionMethod]
|
||||
)
|
||||
const components = paths
|
||||
.concat(
|
||||
!compressionMethod || compressionMethod === CompressionMethod.Gzip
|
||||
? []
|
||||
: [compressionMethod]
|
||||
)
|
||||
.concat(
|
||||
process.platform !== 'win32' || crossOsEnabled ? [] : ['windows-only']
|
||||
) // Only check for windows platforms if crossOsEnabled is false
|
||||
|
||||
// Add salt to cache version to support breaking changes in cache entry
|
||||
components.push(versionSalt)
|
||||
|
@ -96,7 +101,11 @@ export async function getCacheEntry(
|
|||
options?: InternalCacheOptions
|
||||
): Promise<ArtifactCacheEntry | null> {
|
||||
const httpClient = createHttpClient()
|
||||
const version = getCacheVersion(paths, options?.compressionMethod)
|
||||
const version = getCacheVersion(
|
||||
paths,
|
||||
options?.compressionMethod,
|
||||
options?.crossOsEnabled
|
||||
)
|
||||
const resource = `cache?keys=${encodeURIComponent(
|
||||
keys.join(',')
|
||||
)}&version=${version}`
|
||||
|
@ -181,7 +190,11 @@ export async function reserveCache(
|
|||
options?: InternalCacheOptions
|
||||
): Promise<ITypedResponseWithError<ReserveCacheResponse>> {
|
||||
const httpClient = createHttpClient()
|
||||
const version = getCacheVersion(paths, options?.compressionMethod)
|
||||
const version = getCacheVersion(
|
||||
paths,
|
||||
options?.compressionMethod,
|
||||
options?.crossOsEnabled
|
||||
)
|
||||
|
||||
const reserveCacheRequest: ReserveCacheRequest = {
|
||||
key,
|
||||
|
|
|
@ -34,8 +34,9 @@ export interface ReserveCacheResponse {
|
|||
}
|
||||
|
||||
export interface InternalCacheOptions {
|
||||
compressionMethod?: CompressionMethod
|
||||
cacheSize?: number
|
||||
compressionMethod?: CompressionMethod
|
||||
crossOsEnabled?: boolean
|
||||
}
|
||||
|
||||
export interface ArchiveTool {
|
||||
|
|
Loading…
Reference in New Issue