Added cacheSize in ReserveCache API request

This commit is contained in:
Deepak Dahiya
2022-03-29 22:17:04 +00:00
committed by GitHub
parent b463992869
commit 76ac2fcd59
4 changed files with 40 additions and 24 deletions

View File

@@ -31,7 +31,12 @@ import {
const versionSalt = '1.0'
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) {
throw new Error('Cache Service Url not found, unable to restore cache.')
}
@@ -149,7 +154,8 @@ export async function reserveCache(
const reserveCacheRequest: ReserveCacheRequest = {
key,
version
version,
cacheSize: options?.cacheSize
}
const response = await retryTypedResponse('reserveCache', async () =>
httpClient.postJson<ReserveCacheResponse>(
@@ -157,6 +163,9 @@ export async function reserveCache(
reserveCacheRequest
)
)
if(response?.statusCode === 400){
return -2
}
return response?.result?.cacheId ?? -1
}

View File

@@ -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";
}

View File

@@ -14,6 +14,7 @@ export interface CommitCacheRequest {
export interface ReserveCacheRequest {
key: string
version?: string
cacheSize?: number
}
export interface ReserveCacheResponse {
@@ -22,4 +23,5 @@ export interface ReserveCacheResponse {
export interface InternalCacheOptions {
compressionMethod?: CompressionMethod
cacheSize?: number
}