mirror of https://github.com/actions/toolkit
Resolved comments
parent
3abbc6c24c
commit
6cd8286138
|
@ -63,17 +63,16 @@ test('save with large cache outputs should fail', async () => {
|
|||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, 'reserveCache')
|
||||
.mockImplementation(async () => {
|
||||
const response: ITypedResponseWithErrorMessage<ReserveCacheResponse> = {
|
||||
const response: ITypedResponse<ReserveCacheResponse> = {
|
||||
statusCode: 400,
|
||||
result: null,
|
||||
headers: {},
|
||||
typeKey: 'InvalidReserveCacheRequestException'
|
||||
headers: {}
|
||||
}
|
||||
return response
|
||||
})
|
||||
|
||||
await expect(saveCache([filePath], primaryKey)).rejects.toThrowError(
|
||||
'Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.'
|
||||
'Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
|
||||
)
|
||||
|
||||
const archiveFolder = '/foo/bar'
|
||||
|
@ -94,7 +93,7 @@ test('save with reserve cache failure should fail', async () => {
|
|||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, 'reserveCache')
|
||||
.mockImplementation(async () => {
|
||||
const response: ITypedResponseWithErrorMessage<ReserveCacheResponse> = {
|
||||
const response: ITypedResponse<ReserveCacheResponse> = {
|
||||
statusCode: 500,
|
||||
result: null,
|
||||
headers: {}
|
||||
|
|
|
@ -171,9 +171,17 @@ 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}`)
|
||||
// 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)
|
||||
)} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.`
|
||||
)
|
||||
}
|
||||
|
||||
const cacheSize = archiveFileSize
|
||||
core.debug('Reserving Cache')
|
||||
|
@ -186,20 +194,15 @@ export async function saveCache(
|
|||
}
|
||||
)
|
||||
|
||||
if (
|
||||
reserveCacheResponse?.statusCode === 400 &&
|
||||
reserveCacheResponse?.typeKey === 'InvalidReserveCacheRequestException'
|
||||
) {
|
||||
if (reserveCacheResponse?.result?.cacheId) {
|
||||
cacheId = reserveCacheResponse?.result?.cacheId
|
||||
} else if (reserveCacheResponse?.statusCode === 400) {
|
||||
throw new ReserveCacheError(
|
||||
reserveCacheResponse?.message ??
|
||||
reserveCacheResponse?.error?.message ??
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
)} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
||||
)
|
||||
}
|
||||
|
||||
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.`
|
||||
|
|
|
@ -123,3 +123,10 @@ 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";
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {CompressionMethod} from './constants'
|
||||
import {ITypedResponse} from '@actions/http-client/interfaces'
|
||||
import {HttpClientError} from '@actions/http-client'
|
||||
|
||||
export interface ITypedResponseWithErrorMessage<T> extends ITypedResponse<T> {
|
||||
message?: string
|
||||
typeKey?: string
|
||||
error?: HttpClientError
|
||||
}
|
||||
|
||||
export interface ArtifactCacheEntry {
|
||||
|
|
|
@ -110,8 +110,7 @@ export async function retryTypedResponse<T>(
|
|||
statusCode: error.statusCode,
|
||||
result: null,
|
||||
headers: {},
|
||||
message: error.message,
|
||||
typeKey: error.result.typeKey
|
||||
error: error
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
|
|
Loading…
Reference in New Issue