This commit is contained in:
Deepak Dahiya
2022-03-30 07:22:56 +00:00
committed by GitHub
parent 6d774fcb59
commit 7756e7c4cb
5 changed files with 22 additions and 641 deletions
+13 -17
View File
@@ -172,35 +172,31 @@ export async function saveCache(
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 && !utils.isGhes()) {
throw new Error(
`Cache size of ~${Math.round(
archiveFileSize / (1024 * 1024)
)} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.`
)
}
const cacheSize = utils.isGhes() ? archiveFileSize : undefined
const cacheSize = archiveFileSize
core.debug('Reserving Cache')
cacheId = await cacheHttpClient.reserveCache(key, paths, {
let reserveCacheResponse = 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) {
if(reserveCacheResponse?.statusCode === 400){
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}`)
if(reserveCacheResponse?.result?.cacheId){
cacheId = reserveCacheResponse?.result?.cacheId
}else{
throw new ReserveCacheError(
`Unable to reserve cache with key ${key}, another job may be creating this cache.`
)
}
core.debug(`Cache ID: ${cacheId}`)
core.debug(`Saving Cache (ID: ${cacheId})`)
await cacheHttpClient.saveCache(cacheId, archivePath, options)
} finally {
+2 -5
View File
@@ -143,7 +143,7 @@ export async function reserveCache(
key: string,
paths: string[],
options?: InternalCacheOptions
): Promise<number> {
): Promise<ITypedResponse<ReserveCacheResponse>> {
const httpClient = createHttpClient()
const version = getCacheVersion(paths, options?.compressionMethod)
@@ -158,10 +158,7 @@ export async function reserveCache(
reserveCacheRequest
)
)
if(response?.statusCode === 400){
return -2
}
return response?.result?.cacheId ?? -1
return response
}
function getContentRange(start: number, end: number): string {
-7
View File
@@ -123,10 +123,3 @@ export function assertDefined<T>(name: string, value?: T): T {
return value
}
export function isGhes(): boolean {
const ghUrl = new URL(
process.env["GITHUB_SERVER_URL"] || "https://github.com"
);
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
}