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 paths a list of file paths to restore from the cache
|
||||||
* @param primaryKey an explicit key for restoring 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 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
|
* @param downloadOptions cache download options
|
||||||
* @returns string returns the key for the cache hit, otherwise returns undefined
|
* @returns string returns the key for the cache hit, otherwise returns undefined
|
||||||
*/
|
*/
|
||||||
|
@ -68,6 +69,7 @@ export async function restoreCache(
|
||||||
paths: string[],
|
paths: string[],
|
||||||
primaryKey: string,
|
primaryKey: string,
|
||||||
restoreKeys?: string[],
|
restoreKeys?: string[],
|
||||||
|
crossOsEnabled = false,
|
||||||
options?: DownloadOptions
|
options?: DownloadOptions
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
checkPaths(paths)
|
checkPaths(paths)
|
||||||
|
@ -93,7 +95,8 @@ export async function restoreCache(
|
||||||
try {
|
try {
|
||||||
// path are needed to compute version
|
// path are needed to compute version
|
||||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
||||||
compressionMethod
|
compressionMethod,
|
||||||
|
crossOsEnabled
|
||||||
})
|
})
|
||||||
if (!cacheEntry?.archiveLocation) {
|
if (!cacheEntry?.archiveLocation) {
|
||||||
// This is to support the old cache entry created by gzip on windows.
|
// 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 paths a list of file paths to be cached
|
||||||
* @param key an explicit key for restoring the cache
|
* @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
|
* @param options cache upload options
|
||||||
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
|
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
|
||||||
*/
|
*/
|
||||||
export async function saveCache(
|
export async function saveCache(
|
||||||
paths: string[],
|
paths: string[],
|
||||||
key: string,
|
key: string,
|
||||||
|
crossOsEnabled = false,
|
||||||
options?: UploadOptions
|
options?: UploadOptions
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
checkPaths(paths)
|
checkPaths(paths)
|
||||||
|
@ -227,6 +232,7 @@ export async function saveCache(
|
||||||
paths,
|
paths,
|
||||||
{
|
{
|
||||||
compressionMethod,
|
compressionMethod,
|
||||||
|
crossOsEnabled,
|
||||||
cacheSize: archiveFileSize
|
cacheSize: archiveFileSize
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,13 +73,18 @@ function createHttpClient(): HttpClient {
|
||||||
|
|
||||||
export function getCacheVersion(
|
export function getCacheVersion(
|
||||||
paths: string[],
|
paths: string[],
|
||||||
compressionMethod?: CompressionMethod
|
compressionMethod?: CompressionMethod,
|
||||||
|
crossOsEnabled = false
|
||||||
): string {
|
): string {
|
||||||
const components = paths.concat(
|
const components = paths
|
||||||
!compressionMethod || compressionMethod === CompressionMethod.Gzip
|
.concat(
|
||||||
? []
|
!compressionMethod || compressionMethod === CompressionMethod.Gzip
|
||||||
: [compressionMethod]
|
? []
|
||||||
)
|
: [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
|
// Add salt to cache version to support breaking changes in cache entry
|
||||||
components.push(versionSalt)
|
components.push(versionSalt)
|
||||||
|
@ -96,7 +101,11 @@ export async function getCacheEntry(
|
||||||
options?: InternalCacheOptions
|
options?: InternalCacheOptions
|
||||||
): Promise<ArtifactCacheEntry | null> {
|
): Promise<ArtifactCacheEntry | null> {
|
||||||
const httpClient = createHttpClient()
|
const httpClient = createHttpClient()
|
||||||
const version = getCacheVersion(paths, options?.compressionMethod)
|
const version = getCacheVersion(
|
||||||
|
paths,
|
||||||
|
options?.compressionMethod,
|
||||||
|
options?.crossOsEnabled
|
||||||
|
)
|
||||||
const resource = `cache?keys=${encodeURIComponent(
|
const resource = `cache?keys=${encodeURIComponent(
|
||||||
keys.join(',')
|
keys.join(',')
|
||||||
)}&version=${version}`
|
)}&version=${version}`
|
||||||
|
@ -181,7 +190,11 @@ export async function reserveCache(
|
||||||
options?: InternalCacheOptions
|
options?: InternalCacheOptions
|
||||||
): Promise<ITypedResponseWithError<ReserveCacheResponse>> {
|
): Promise<ITypedResponseWithError<ReserveCacheResponse>> {
|
||||||
const httpClient = createHttpClient()
|
const httpClient = createHttpClient()
|
||||||
const version = getCacheVersion(paths, options?.compressionMethod)
|
const version = getCacheVersion(
|
||||||
|
paths,
|
||||||
|
options?.compressionMethod,
|
||||||
|
options?.crossOsEnabled
|
||||||
|
)
|
||||||
|
|
||||||
const reserveCacheRequest: ReserveCacheRequest = {
|
const reserveCacheRequest: ReserveCacheRequest = {
|
||||||
key,
|
key,
|
||||||
|
|
|
@ -34,8 +34,9 @@ export interface ReserveCacheResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InternalCacheOptions {
|
export interface InternalCacheOptions {
|
||||||
compressionMethod?: CompressionMethod
|
|
||||||
cacheSize?: number
|
cacheSize?: number
|
||||||
|
compressionMethod?: CompressionMethod
|
||||||
|
crossOsEnabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArchiveTool {
|
export interface ArchiveTool {
|
||||||
|
|
Loading…
Reference in New Issue