mirror of https://github.com/actions/toolkit
Added cacheSize in ReserveCache API request
parent
b463992869
commit
76ac2fcd59
|
@ -43,16 +43,6 @@ function checkKey(key: string): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* isFeatureAvailable to check the presence of Actions cache service
|
|
||||||
*
|
|
||||||
* @returns boolean return true if Actions cache service feature is available, otherwise false
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function isFeatureAvailable(): boolean {
|
|
||||||
return !!process.env['ACTIONS_CACHE_URL']
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores cache from keys
|
* Restores cache from keys
|
||||||
*
|
*
|
||||||
|
@ -152,17 +142,7 @@ export async function saveCache(
|
||||||
checkKey(key)
|
checkKey(key)
|
||||||
|
|
||||||
const compressionMethod = await utils.getCompressionMethod()
|
const compressionMethod = await utils.getCompressionMethod()
|
||||||
|
let cacheId = null
|
||||||
core.debug('Reserving Cache')
|
|
||||||
const cacheId = await cacheHttpClient.reserveCache(key, paths, {
|
|
||||||
compressionMethod
|
|
||||||
})
|
|
||||||
if (cacheId === -1) {
|
|
||||||
throw new ReserveCacheError(
|
|
||||||
`Unable to reserve cache with key ${key}, another job may be creating this cache.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
core.debug(`Cache ID: ${cacheId}`)
|
|
||||||
|
|
||||||
const cachePaths = await utils.resolvePaths(paths)
|
const cachePaths = await utils.resolvePaths(paths)
|
||||||
core.debug('Cache Paths:')
|
core.debug('Cache Paths:')
|
||||||
|
@ -185,7 +165,7 @@ export async function saveCache(
|
||||||
const fileSizeLimit = 10 * 1024 * 1024 * 1024 // 10GB per repo limit
|
const fileSizeLimit = 10 * 1024 * 1024 * 1024 // 10GB per repo limit
|
||||||
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
||||||
core.debug(`File Size: ${archiveFileSize}`)
|
core.debug(`File Size: ${archiveFileSize}`)
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit && !utils.isGhes()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Cache size of ~${Math.round(
|
`Cache size of ~${Math.round(
|
||||||
archiveFileSize / (1024 * 1024)
|
archiveFileSize / (1024 * 1024)
|
||||||
|
@ -193,6 +173,24 @@ export async function saveCache(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cacheSize = utils.isGhes() ? archiveFileSize : undefined
|
||||||
|
core.debug('Reserving Cache')
|
||||||
|
cacheId = await cacheHttpClient.reserveCache(key, paths, {
|
||||||
|
compressionMethod,
|
||||||
|
cacheSize
|
||||||
|
})
|
||||||
|
if (cacheId === -1) {
|
||||||
|
throw new ReserveCacheError(
|
||||||
|
`Unable to reserve cache with key ${key}, another job may be creating this cache.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (cacheId === -2) {
|
||||||
|
throw new ReserveCacheError(
|
||||||
|
`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
core.debug(`Cache ID: ${cacheId}`)
|
||||||
|
|
||||||
core.debug(`Saving Cache (ID: ${cacheId})`)
|
core.debug(`Saving Cache (ID: ${cacheId})`)
|
||||||
await cacheHttpClient.saveCache(cacheId, archivePath, options)
|
await cacheHttpClient.saveCache(cacheId, archivePath, options)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -31,7 +31,12 @@ import {
|
||||||
const versionSalt = '1.0'
|
const versionSalt = '1.0'
|
||||||
|
|
||||||
function getCacheApiUrl(resource: string): string {
|
function getCacheApiUrl(resource: string): string {
|
||||||
const baseUrl: string = process.env['ACTIONS_CACHE_URL'] || ''
|
// Ideally we just use ACTIONS_CACHE_URL
|
||||||
|
const baseUrl: string = (
|
||||||
|
process.env['ACTIONS_CACHE_URL'] ||
|
||||||
|
process.env['ACTIONS_RUNTIME_URL'] ||
|
||||||
|
''
|
||||||
|
).replace('pipelines', 'artifactcache')
|
||||||
if (!baseUrl) {
|
if (!baseUrl) {
|
||||||
throw new Error('Cache Service Url not found, unable to restore cache.')
|
throw new Error('Cache Service Url not found, unable to restore cache.')
|
||||||
}
|
}
|
||||||
|
@ -149,7 +154,8 @@ export async function reserveCache(
|
||||||
|
|
||||||
const reserveCacheRequest: ReserveCacheRequest = {
|
const reserveCacheRequest: ReserveCacheRequest = {
|
||||||
key,
|
key,
|
||||||
version
|
version,
|
||||||
|
cacheSize: options?.cacheSize
|
||||||
}
|
}
|
||||||
const response = await retryTypedResponse('reserveCache', async () =>
|
const response = await retryTypedResponse('reserveCache', async () =>
|
||||||
httpClient.postJson<ReserveCacheResponse>(
|
httpClient.postJson<ReserveCacheResponse>(
|
||||||
|
@ -157,6 +163,9 @@ export async function reserveCache(
|
||||||
reserveCacheRequest
|
reserveCacheRequest
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if(response?.statusCode === 400){
|
||||||
|
return -2
|
||||||
|
}
|
||||||
return response?.result?.cacheId ?? -1
|
return response?.result?.cacheId ?? -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,3 +123,10 @@ export function assertDefined<T>(name: string, value?: T): T {
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isGhes(): boolean {
|
||||||
|
const ghUrl = new URL(
|
||||||
|
process.env["GITHUB_SERVER_URL"] || "https://github.com"
|
||||||
|
);
|
||||||
|
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ export interface CommitCacheRequest {
|
||||||
export interface ReserveCacheRequest {
|
export interface ReserveCacheRequest {
|
||||||
key: string
|
key: string
|
||||||
version?: string
|
version?: string
|
||||||
|
cacheSize?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReserveCacheResponse {
|
export interface ReserveCacheResponse {
|
||||||
|
@ -22,4 +23,5 @@ export interface ReserveCacheResponse {
|
||||||
|
|
||||||
export interface InternalCacheOptions {
|
export interface InternalCacheOptions {
|
||||||
compressionMethod?: CompressionMethod
|
compressionMethod?: CompressionMethod
|
||||||
|
cacheSize?: number
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue