mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-05 21:53:15 +08:00
Added cacheSize in ReserveCache API request (#1044)
* Added cacheSize in ReserveCache API request * minor * minor * minor * Cleanup * package-lock revert * Modified tests * New Response Type * cleanup * Linting * Lint fix * Resolved comments * Added tests * package-lock * Resolved package-lock mismatch * Liniting * Update packages/cache/src/cache.ts Co-authored-by: Bishal Prasad <bishal-pdmsft@github.com> * Linting issue * Resolved few comments * version upgrade * Savecache tests * RequestUtil test * test * test * test * test * test * test * test * test * test * test Co-authored-by: Apple <apple@Apples-MacBook-Pro.local> Co-authored-by: Bishal Prasad <bishal-pdmsft@github.com>
This commit is contained in:
42
packages/cache/src/cache.ts
vendored
42
packages/cache/src/cache.ts
vendored
@@ -152,17 +152,7 @@ export async function saveCache(
|
||||
checkKey(key)
|
||||
|
||||
const compressionMethod = await utils.getCompressionMethod()
|
||||
|
||||
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}`)
|
||||
let cacheId = null
|
||||
|
||||
const cachePaths = await utils.resolvePaths(paths)
|
||||
core.debug('Cache Paths:')
|
||||
@@ -181,11 +171,12 @@ export async function saveCache(
|
||||
if (core.isDebug()) {
|
||||
await listTar(archivePath, compressionMethod)
|
||||
}
|
||||
|
||||
const fileSizeLimit = 10 * 1024 * 1024 * 1024 // 10GB per repo limit
|
||||
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
||||
core.debug(`File Size: ${archiveFileSize}`)
|
||||
if (archiveFileSize > fileSizeLimit) {
|
||||
|
||||
// For GHES, this check will take place in ReserveCache API with enterprise file size limit
|
||||
if (archiveFileSize > fileSizeLimit && !utils.isGhes()) {
|
||||
throw new Error(
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
@@ -193,6 +184,31 @@ export async function saveCache(
|
||||
)
|
||||
}
|
||||
|
||||
core.debug('Reserving Cache')
|
||||
const reserveCacheResponse = await cacheHttpClient.reserveCache(
|
||||
key,
|
||||
paths,
|
||||
{
|
||||
compressionMethod,
|
||||
cacheSize: archiveFileSize
|
||||
}
|
||||
)
|
||||
|
||||
if (reserveCacheResponse?.result?.cacheId) {
|
||||
cacheId = reserveCacheResponse?.result?.cacheId
|
||||
} else if (reserveCacheResponse?.statusCode === 400) {
|
||||
throw new ReserveCacheError(
|
||||
reserveCacheResponse?.error?.message ??
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
)} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
||||
)
|
||||
} else {
|
||||
throw new ReserveCacheError(
|
||||
`Unable to reserve cache with key ${key}, another job may be creating this cache. More details: ${reserveCacheResponse?.error?.message}`
|
||||
)
|
||||
}
|
||||
|
||||
core.debug(`Saving Cache (ID: ${cacheId})`)
|
||||
await cacheHttpClient.saveCache(cacheId, archivePath, options)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user