2020-07-10 15:09:32 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
|
2020-05-12 16:37:03 +00:00
|
|
|
/**
|
|
|
|
* Options to control cache upload
|
|
|
|
*/
|
|
|
|
export interface UploadOptions {
|
|
|
|
/**
|
|
|
|
* Number of parallel cache upload
|
|
|
|
*
|
|
|
|
* @default 4
|
|
|
|
*/
|
|
|
|
uploadConcurrency?: number
|
|
|
|
/**
|
2020-05-15 16:18:50 +00:00
|
|
|
* Maximum chunk size in bytes for cache upload
|
2020-05-12 16:37:03 +00:00
|
|
|
*
|
|
|
|
* @default 32MB
|
|
|
|
*/
|
|
|
|
uploadChunkSize?: number
|
|
|
|
}
|
2020-07-10 15:09:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Options to control cache download
|
|
|
|
*/
|
|
|
|
export interface DownloadOptions {
|
|
|
|
/**
|
|
|
|
* Indicates whether to use the Azure Blob SDK to download caches
|
|
|
|
* that are stored on Azure Blob Storage to improve reliability and
|
|
|
|
* performance
|
|
|
|
*
|
|
|
|
* @default true
|
|
|
|
*/
|
|
|
|
useAzureSdk?: boolean
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of parallel downloads (this option only applies when using
|
|
|
|
* the Azure SDK)
|
|
|
|
*
|
|
|
|
* @default 8
|
|
|
|
*/
|
|
|
|
downloadConcurrency?: number
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether to use Actions HttpClient with concurrency
|
|
|
|
* for Azure Blob Storage
|
|
|
|
*/
|
|
|
|
concurrentBlobDownloads?: boolean
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
/**
|
|
|
|
* Maximum time for each download request, in milliseconds (this
|
|
|
|
* option only applies when using the Azure SDK)
|
|
|
|
*
|
|
|
|
* @default 30000
|
|
|
|
*/
|
2022-08-03 14:12:16 +00:00
|
|
|
timeoutInMs?: number
|
2022-08-03 10:23:42 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-08 04:48:36 +00:00
|
|
|
* Time after which a segment download should be aborted if stuck
|
2022-08-03 10:23:42 +00:00
|
|
|
*
|
2022-08-05 05:44:59 +00:00
|
|
|
* @default 3600000
|
2022-08-03 10:23:42 +00:00
|
|
|
*/
|
2022-08-08 04:48:36 +00:00
|
|
|
segmentTimeoutInMs?: number
|
2022-12-23 11:44:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Weather to skip downloading the cache entry.
|
2023-01-17 16:12:42 +00:00
|
|
|
* If lookupOnly is set to true, the restore function will only check if
|
2022-12-23 11:44:35 +00:00
|
|
|
* a matching cache entry exists and return the cache key if it does.
|
|
|
|
*
|
|
|
|
* @default false
|
|
|
|
*/
|
2023-01-17 16:12:42 +00:00
|
|
|
lookupOnly?: boolean
|
2020-07-10 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a copy of the upload options with defaults filled in.
|
|
|
|
*
|
|
|
|
* @param copy the original upload options
|
|
|
|
*/
|
|
|
|
export function getUploadOptions(copy?: UploadOptions): UploadOptions {
|
|
|
|
const result: UploadOptions = {
|
|
|
|
uploadConcurrency: 4,
|
|
|
|
uploadChunkSize: 32 * 1024 * 1024
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy) {
|
|
|
|
if (typeof copy.uploadConcurrency === 'number') {
|
|
|
|
result.uploadConcurrency = copy.uploadConcurrency
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof copy.uploadChunkSize === 'number') {
|
|
|
|
result.uploadChunkSize = copy.uploadChunkSize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
core.debug(`Upload concurrency: ${result.uploadConcurrency}`)
|
|
|
|
core.debug(`Upload chunk size: ${result.uploadChunkSize}`)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a copy of the download options with defaults filled in.
|
|
|
|
*
|
|
|
|
* @param copy the original download options
|
|
|
|
*/
|
|
|
|
export function getDownloadOptions(copy?: DownloadOptions): DownloadOptions {
|
|
|
|
const result: DownloadOptions = {
|
2023-08-07 17:25:56 +00:00
|
|
|
useAzureSdk: false,
|
|
|
|
concurrentBlobDownloads: true,
|
2020-07-10 15:09:32 +00:00
|
|
|
downloadConcurrency: 8,
|
2022-08-03 10:23:42 +00:00
|
|
|
timeoutInMs: 30000,
|
2023-03-08 19:14:15 +00:00
|
|
|
segmentTimeoutInMs: 600000,
|
2023-01-17 16:12:42 +00:00
|
|
|
lookupOnly: false
|
2020-07-10 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (copy) {
|
|
|
|
if (typeof copy.useAzureSdk === 'boolean') {
|
|
|
|
result.useAzureSdk = copy.useAzureSdk
|
|
|
|
}
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
if (typeof copy.concurrentBlobDownloads === 'boolean') {
|
|
|
|
result.concurrentBlobDownloads = copy.concurrentBlobDownloads
|
|
|
|
}
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
if (typeof copy.downloadConcurrency === 'number') {
|
|
|
|
result.downloadConcurrency = copy.downloadConcurrency
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof copy.timeoutInMs === 'number') {
|
|
|
|
result.timeoutInMs = copy.timeoutInMs
|
|
|
|
}
|
2022-08-03 10:23:42 +00:00
|
|
|
|
2022-08-08 04:48:36 +00:00
|
|
|
if (typeof copy.segmentTimeoutInMs === 'number') {
|
|
|
|
result.segmentTimeoutInMs = copy.segmentTimeoutInMs
|
2022-08-03 10:23:42 +00:00
|
|
|
}
|
2022-12-23 11:44:35 +00:00
|
|
|
|
2023-01-17 16:12:42 +00:00
|
|
|
if (typeof copy.lookupOnly === 'boolean') {
|
|
|
|
result.lookupOnly = copy.lookupOnly
|
2022-12-23 11:44:35 +00:00
|
|
|
}
|
2020-07-10 15:09:32 +00:00
|
|
|
}
|
2022-08-18 05:32:49 +00:00
|
|
|
const segmentDownloadTimeoutMins =
|
|
|
|
process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']
|
2022-08-16 04:14:27 +00:00
|
|
|
|
|
|
|
if (
|
2022-08-18 05:32:49 +00:00
|
|
|
segmentDownloadTimeoutMins &&
|
|
|
|
!isNaN(Number(segmentDownloadTimeoutMins)) &&
|
|
|
|
isFinite(Number(segmentDownloadTimeoutMins))
|
2022-08-16 04:14:27 +00:00
|
|
|
) {
|
2022-08-18 05:32:49 +00:00
|
|
|
result.segmentTimeoutInMs = Number(segmentDownloadTimeoutMins) * 60 * 1000
|
2022-08-16 04:14:27 +00:00
|
|
|
}
|
2020-07-10 15:09:32 +00:00
|
|
|
core.debug(`Use Azure SDK: ${result.useAzureSdk}`)
|
|
|
|
core.debug(`Download concurrency: ${result.downloadConcurrency}`)
|
|
|
|
core.debug(`Request timeout (ms): ${result.timeoutInMs}`)
|
2022-08-16 04:14:27 +00:00
|
|
|
core.debug(
|
2022-08-18 05:32:49 +00:00
|
|
|
`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`
|
2022-08-16 04:14:27 +00:00
|
|
|
)
|
2022-08-08 04:48:36 +00:00
|
|
|
core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`)
|
2023-01-17 16:12:42 +00:00
|
|
|
core.debug(`Lookup only: ${result.lookupOnly}`)
|
2020-07-10 15:09:32 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|