mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-01-03 12:52:55 +08:00
Formatting and stylistic cleanup
This commit is contained in:
parent
69409b3acd
commit
b2557ac90c
57
packages/cache/src/cache.ts
vendored
57
packages/cache/src/cache.ts
vendored
@ -86,11 +86,23 @@ export async function restoreCache(
|
||||
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||
console.debug(`Cache service version: ${cacheServiceVersion}`)
|
||||
switch (cacheServiceVersion) {
|
||||
case "v2":
|
||||
return await restoreCachev2(paths, primaryKey, restoreKeys, options, enableCrossOsArchive)
|
||||
case "v1":
|
||||
case 'v2':
|
||||
return await restoreCachev2(
|
||||
paths,
|
||||
primaryKey,
|
||||
restoreKeys,
|
||||
options,
|
||||
enableCrossOsArchive
|
||||
)
|
||||
case 'v1':
|
||||
default:
|
||||
return await restoreCachev1(paths, primaryKey, restoreKeys, options, enableCrossOsArchive)
|
||||
return await restoreCachev1(
|
||||
paths,
|
||||
primaryKey,
|
||||
restoreKeys,
|
||||
options,
|
||||
enableCrossOsArchive
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,12 +250,15 @@ async function restoreCachev2(
|
||||
version: utils.getCacheVersion(
|
||||
paths,
|
||||
compressionMethod,
|
||||
enableCrossOsArchive,
|
||||
),
|
||||
enableCrossOsArchive
|
||||
)
|
||||
}
|
||||
|
||||
core.debug(`GetCacheEntryDownloadURLRequest: ${JSON.stringify(twirpClient)}`)
|
||||
const response: GetCacheEntryDownloadURLResponse = await twirpClient.GetCacheEntryDownloadURL(request)
|
||||
core.debug(
|
||||
`GetCacheEntryDownloadURLRequest: ${JSON.stringify(twirpClient)}`
|
||||
)
|
||||
const response: GetCacheEntryDownloadURLResponse =
|
||||
await twirpClient.GetCacheEntryDownloadURL(request)
|
||||
core.debug(`GetCacheEntryDownloadURLResponse: ${JSON.stringify(response)}`)
|
||||
|
||||
if (!response.ok) {
|
||||
@ -266,10 +281,7 @@ async function restoreCachev2(
|
||||
|
||||
core.debug(`Starting download of artifact to: ${archivePath}`)
|
||||
|
||||
await DownloadCacheFile(
|
||||
response.signedDownloadUrl,
|
||||
archivePath
|
||||
)
|
||||
await DownloadCacheFile(response.signedDownloadUrl, archivePath)
|
||||
|
||||
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
||||
core.info(
|
||||
@ -320,9 +332,9 @@ export async function saveCache(
|
||||
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||
console.debug(`Cache Service Version: ${cacheServiceVersion}`)
|
||||
switch (cacheServiceVersion) {
|
||||
case "v2":
|
||||
case 'v2':
|
||||
return await saveCachev2(paths, key, options, enableCrossOsArchive)
|
||||
case "v1":
|
||||
case 'v1':
|
||||
default:
|
||||
return await saveCachev1(paths, key, options, enableCrossOsArchive)
|
||||
}
|
||||
@ -500,7 +512,8 @@ async function saveCachev2(
|
||||
key: key,
|
||||
version: version
|
||||
}
|
||||
const response: CreateCacheEntryResponse = await twirpClient.CreateCacheEntry(request)
|
||||
const response: CreateCacheEntryResponse =
|
||||
await twirpClient.CreateCacheEntry(request)
|
||||
if (!response.ok) {
|
||||
throw new ReserveCacheError(
|
||||
`Unable to reserve cache with key ${key}, another job may be creating this cache.`
|
||||
@ -508,21 +521,21 @@ async function saveCachev2(
|
||||
}
|
||||
|
||||
core.debug(`Saving Cache to: ${core.setSecret(response.signedUploadUrl)}`)
|
||||
await UploadCacheFile(
|
||||
response.signedUploadUrl,
|
||||
archivePath,
|
||||
)
|
||||
await UploadCacheFile(response.signedUploadUrl, archivePath)
|
||||
|
||||
const finalizeRequest: FinalizeCacheEntryUploadRequest = {
|
||||
workflowRunBackendId: backendIds.workflowRunBackendId,
|
||||
workflowJobRunBackendId: backendIds.workflowJobRunBackendId,
|
||||
key: key,
|
||||
version: version,
|
||||
sizeBytes: `${archiveFileSize}`,
|
||||
sizeBytes: `${archiveFileSize}`
|
||||
}
|
||||
|
||||
const finalizeResponse: FinalizeCacheEntryUploadResponse = await twirpClient.FinalizeCacheEntryUpload(finalizeRequest)
|
||||
core.debug(`FinalizeCacheEntryUploadResponse: ${JSON.stringify(finalizeResponse)}`)
|
||||
const finalizeResponse: FinalizeCacheEntryUploadResponse =
|
||||
await twirpClient.FinalizeCacheEntryUpload(finalizeRequest)
|
||||
core.debug(
|
||||
`FinalizeCacheEntryUploadResponse: ${JSON.stringify(finalizeResponse)}`
|
||||
)
|
||||
|
||||
if (!finalizeResponse.ok) {
|
||||
throw new Error(
|
||||
|
||||
@ -3,15 +3,15 @@ import * as core from '@actions/core'
|
||||
import {
|
||||
BlobClient,
|
||||
BlockBlobClient,
|
||||
BlobDownloadOptions,
|
||||
BlobDownloadOptions
|
||||
} from '@azure/storage-blob'
|
||||
|
||||
export async function DownloadCacheFile(
|
||||
signedUploadURL: string,
|
||||
archivePath: string,
|
||||
archivePath: string
|
||||
): Promise<{}> {
|
||||
const downloadOptions: BlobDownloadOptions = {
|
||||
maxRetryRequests: 5,
|
||||
maxRetryRequests: 5
|
||||
}
|
||||
|
||||
// TODO: tighten the configuration and pass the appropriate user-agent
|
||||
@ -21,5 +21,10 @@ export async function DownloadCacheFile(
|
||||
core.debug(`BlobClient: ${JSON.stringify(blobClient)}`)
|
||||
core.debug(`blockBlobClient: ${JSON.stringify(blockBlobClient)}`)
|
||||
|
||||
return blockBlobClient.downloadToFile(archivePath, 0, undefined, downloadOptions)
|
||||
return blockBlobClient.downloadToFile(
|
||||
archivePath,
|
||||
0,
|
||||
undefined,
|
||||
downloadOptions
|
||||
)
|
||||
}
|
||||
@ -7,15 +7,15 @@ import {
|
||||
|
||||
export async function UploadCacheFile(
|
||||
signedUploadURL: string,
|
||||
archivePath: string,
|
||||
archivePath: string
|
||||
): Promise<{}> {
|
||||
// TODO: tighten the configuration and pass the appropriate user-agent
|
||||
// Specify data transfer options
|
||||
const uploadOptions: BlockBlobParallelUploadOptions = {
|
||||
blockSize: 4 * 1024 * 1024, // 4 MiB max block size
|
||||
concurrency: 4, // maximum number of parallel transfer workers
|
||||
maxSingleShotSize: 8 * 1024 * 1024, // 8 MiB initial transfer size
|
||||
};
|
||||
maxSingleShotSize: 8 * 1024 * 1024 // 8 MiB initial transfer size
|
||||
}
|
||||
|
||||
const blobClient: BlobClient = new BlobClient(signedUploadURL)
|
||||
const blockBlobClient: BlockBlobClient = blobClient.getBlockBlobClient()
|
||||
@ -23,5 +23,5 @@ export async function UploadCacheFile(
|
||||
core.debug(`BlobClient: ${JSON.stringify(blobClient)}`)
|
||||
core.debug(`blockBlobClient: ${JSON.stringify(blockBlobClient)}`)
|
||||
|
||||
return blockBlobClient.uploadFile(archivePath, uploadOptions);
|
||||
return blockBlobClient.uploadFile(archivePath, uploadOptions)
|
||||
}
|
||||
@ -216,7 +216,8 @@ async function uploadChunk(
|
||||
end: number
|
||||
): Promise<void> {
|
||||
core.debug(
|
||||
`Uploading chunk of size ${end - start + 1
|
||||
`Uploading chunk of size ${
|
||||
end - start + 1
|
||||
} bytes at offset ${start} with content range: ${getContentRange(
|
||||
start,
|
||||
end
|
||||
|
||||
10
packages/cache/src/internal/config.ts
vendored
10
packages/cache/src/internal/config.ts
vendored
@ -7,16 +7,20 @@ export function getRuntimeToken(): string {
|
||||
}
|
||||
|
||||
export function getCacheServiceVersion(): string {
|
||||
return process.env['ACTIONS_CACHE_SERVICE_V2'] ? 'v2' : 'v1';
|
||||
return process.env['ACTIONS_CACHE_SERVICE_V2'] ? 'v2' : 'v1'
|
||||
}
|
||||
|
||||
export function getCacheServiceURL(): string {
|
||||
const version = getCacheServiceVersion()
|
||||
switch (version) {
|
||||
case 'v1':
|
||||
return process.env['ACTIONS_CACHE_URL'] || process.env['ACTIONS_RESULTS_URL'] || ""
|
||||
return (
|
||||
process.env['ACTIONS_CACHE_URL'] ||
|
||||
process.env['ACTIONS_RESULTS_URL'] ||
|
||||
''
|
||||
)
|
||||
case 'v2':
|
||||
return process.env['ACTIONS_RESULTS_URL'] || ""
|
||||
return process.env['ACTIONS_RESULTS_URL'] || ''
|
||||
default:
|
||||
throw new Error(`Unsupported cache service version: ${version}`)
|
||||
}
|
||||
|
||||
@ -136,7 +136,8 @@ class CacheServiceClient implements Rpc {
|
||||
const retryTimeMilliseconds =
|
||||
this.getExponentialRetryTimeMilliseconds(attempt)
|
||||
info(
|
||||
`Attempt ${attempt + 1} of ${this.maxAttempts
|
||||
`Attempt ${attempt + 1} of ${
|
||||
this.maxAttempts
|
||||
} failed with error: ${errorMessage}. Retrying request in ${retryTimeMilliseconds} ms...`
|
||||
)
|
||||
await this.sleep(retryTimeMilliseconds)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user