mirror of https://github.com/actions/toolkit
Update the useragent of the old http client to pass cache version
parent
27e5cf2514
commit
af3981c955
|
@ -3,18 +3,18 @@ import * as path from 'path'
|
||||||
import * as utils from './internal/cacheUtils'
|
import * as utils from './internal/cacheUtils'
|
||||||
import * as cacheHttpClient from './internal/cacheHttpClient'
|
import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||||
import * as cacheTwirpClient from './internal/shared/cacheTwirpClient'
|
import * as cacheTwirpClient from './internal/shared/cacheTwirpClient'
|
||||||
import {downloadCacheStorageSDK} from './internal/downloadUtils'
|
import { downloadCacheStorageSDK } from './internal/downloadUtils'
|
||||||
import {getCacheServiceVersion, isGhes} from './internal/config'
|
import { getCacheServiceVersion, isGhes } from './internal/config'
|
||||||
import {DownloadOptions, UploadOptions} from './options'
|
import { DownloadOptions, UploadOptions } from './options'
|
||||||
import {createTar, extractTar, listTar} from './internal/tar'
|
import { createTar, extractTar, listTar } from './internal/tar'
|
||||||
import {
|
import {
|
||||||
CreateCacheEntryRequest,
|
CreateCacheEntryRequest,
|
||||||
FinalizeCacheEntryUploadRequest,
|
FinalizeCacheEntryUploadRequest,
|
||||||
FinalizeCacheEntryUploadResponse,
|
FinalizeCacheEntryUploadResponse,
|
||||||
GetCacheEntryDownloadURLRequest
|
GetCacheEntryDownloadURLRequest
|
||||||
} from './generated/results/api/v1/cache'
|
} from './generated/results/api/v1/cache'
|
||||||
import {CacheFileSizeLimit} from './internal/constants'
|
import { CacheFileSizeLimit } from './internal/constants'
|
||||||
import {uploadCacheFile} from './internal/blob/upload-cache'
|
import { uploadCacheFile } from './internal/blob/upload-cache'
|
||||||
export class ValidationError extends Error {
|
export class ValidationError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(message)
|
super(message)
|
||||||
|
@ -161,14 +161,11 @@ async function restoreCacheV1(
|
||||||
)
|
)
|
||||||
core.debug(`Archive Path: ${archivePath}`)
|
core.debug(`Archive Path: ${archivePath}`)
|
||||||
|
|
||||||
// Download the cache archive from from blob storage
|
// Download the cache from the cache entry
|
||||||
await cacheHttpClient.downloadCache(
|
await cacheHttpClient.downloadCache(
|
||||||
cacheEntry.archiveLocation,
|
cacheEntry.archiveLocation,
|
||||||
archivePath,
|
archivePath,
|
||||||
options ||
|
options
|
||||||
({
|
|
||||||
timeoutInMs: 30000
|
|
||||||
} as DownloadOptions)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
|
@ -278,9 +275,9 @@ async function restoreCacheV2(
|
||||||
response.signedDownloadUrl,
|
response.signedDownloadUrl,
|
||||||
archivePath,
|
archivePath,
|
||||||
options ||
|
options ||
|
||||||
({
|
({
|
||||||
timeoutInMs: 30000
|
timeoutInMs: 30000
|
||||||
} as DownloadOptions)
|
} as DownloadOptions)
|
||||||
)
|
)
|
||||||
|
|
||||||
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
||||||
|
@ -417,9 +414,9 @@ async function saveCacheV1(
|
||||||
} else if (reserveCacheResponse?.statusCode === 400) {
|
} else if (reserveCacheResponse?.statusCode === 400) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
reserveCacheResponse?.error?.message ??
|
reserveCacheResponse?.error?.message ??
|
||||||
`Cache size of ~${Math.round(
|
`Cache size of ~${Math.round(
|
||||||
archiveFileSize / (1024 * 1024)
|
archiveFileSize / (1024 * 1024)
|
||||||
)} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
)} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw new ReserveCacheError(
|
throw new ReserveCacheError(
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {HttpClient} from '@actions/http-client'
|
import { HttpClient } from '@actions/http-client'
|
||||||
import {BearerCredentialHandler} from '@actions/http-client/lib/auth'
|
import { BearerCredentialHandler } from '@actions/http-client/lib/auth'
|
||||||
import {
|
import {
|
||||||
RequestOptions,
|
RequestOptions,
|
||||||
TypedResponse
|
TypedResponse
|
||||||
} from '@actions/http-client/lib/interfaces'
|
} from '@actions/http-client/lib/interfaces'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import {URL} from 'url'
|
import { URL } from 'url'
|
||||||
import * as utils from './cacheUtils'
|
import * as utils from './cacheUtils'
|
||||||
import {
|
import {
|
||||||
ArtifactCacheEntry,
|
ArtifactCacheEntry,
|
||||||
|
@ -33,7 +33,8 @@ import {
|
||||||
retryHttpClientResponse,
|
retryHttpClientResponse,
|
||||||
retryTypedResponse
|
retryTypedResponse
|
||||||
} from './requestUtils'
|
} from './requestUtils'
|
||||||
import {getCacheServiceURL} from './config'
|
import { getCacheServiceURL } from './config'
|
||||||
|
import { getUserAgentString } from './shared/user-agent'
|
||||||
|
|
||||||
function getCacheApiUrl(resource: string): string {
|
function getCacheApiUrl(resource: string): string {
|
||||||
const baseUrl: string = getCacheServiceURL()
|
const baseUrl: string = getCacheServiceURL()
|
||||||
|
@ -65,7 +66,7 @@ function createHttpClient(): HttpClient {
|
||||||
const bearerCredentialHandler = new BearerCredentialHandler(token)
|
const bearerCredentialHandler = new BearerCredentialHandler(token)
|
||||||
|
|
||||||
return new HttpClient(
|
return new HttpClient(
|
||||||
'actions/cache',
|
getUserAgentString(),
|
||||||
[bearerCredentialHandler],
|
[bearerCredentialHandler],
|
||||||
getRequestOptions()
|
getRequestOptions()
|
||||||
)
|
)
|
||||||
|
@ -216,8 +217,7 @@ async function uploadChunk(
|
||||||
end: number
|
end: number
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.debug(
|
core.debug(
|
||||||
`Uploading chunk of size ${
|
`Uploading chunk of size ${end - start + 1
|
||||||
end - start + 1
|
|
||||||
} bytes at offset ${start} with content range: ${getContentRange(
|
} bytes at offset ${start} with content range: ${getContentRange(
|
||||||
start,
|
start,
|
||||||
end
|
end
|
||||||
|
@ -313,7 +313,7 @@ async function commitCache(
|
||||||
cacheId: number,
|
cacheId: number,
|
||||||
filesize: number
|
filesize: number
|
||||||
): Promise<TypedResponse<null>> {
|
): Promise<TypedResponse<null>> {
|
||||||
const commitCacheRequest: CommitCacheRequest = {size: filesize}
|
const commitCacheRequest: CommitCacheRequest = { size: filesize }
|
||||||
return await retryTypedResponse('commitCache', async () =>
|
return await retryTypedResponse('commitCache', async () =>
|
||||||
httpClient.postJson<null>(
|
httpClient.postJson<null>(
|
||||||
getCacheApiUrl(`caches/${cacheId.toString()}`),
|
getCacheApiUrl(`caches/${cacheId.toString()}`),
|
||||||
|
|
Loading…
Reference in New Issue