1
0
Fork 0
toolkit/packages/cache/src/internal/uploadUtils.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-06-13 10:16:59 +00:00
import * as core from '@actions/core'
import {
2024-09-24 10:17:44 +00:00
BlobClient,
2024-11-24 18:44:39 +00:00
BlobUploadCommonResponse,
2024-09-24 10:17:44 +00:00
BlockBlobClient,
2024-06-13 10:16:59 +00:00
BlockBlobParallelUploadOptions
} from '@azure/storage-blob'
2024-11-28 11:53:34 +00:00
import {InvalidResponseError} from './shared/errors'
2024-06-13 10:16:59 +00:00
2024-11-28 11:53:34 +00:00
export async function uploadCacheArchiveSDK(
signedUploadURL: string,
archivePath: string
): Promise<BlobUploadCommonResponse> {
2024-06-13 10:16:59 +00:00
// Specify data transfer options
const uploadOptions: BlockBlobParallelUploadOptions = {
blockSize: 4 * 1024 * 1024, // 4 MiB max block size
concurrency: 4, // maximum number of parallel transfer workers
2024-11-14 11:22:03 +00:00
maxSingleShotSize: 8 * 1024 * 1024 // 8 MiB initial transfer size
}
2024-06-13 10:16:59 +00:00
const blobClient: BlobClient = new BlobClient(signedUploadURL)
2024-06-13 10:16:59 +00:00
const blockBlobClient: BlockBlobClient = blobClient.getBlockBlobClient()
2024-11-14 12:47:27 +00:00
core.debug(
`BlobClient: ${blobClient.name}:${blobClient.accountName}:${blobClient.containerName}`
)
2024-06-13 10:16:59 +00:00
const resp = await blockBlobClient.uploadFile(archivePath, uploadOptions)
if (resp._response.status >= 400) {
throw new InvalidResponseError(
`Upload failed with status code ${resp._response.status}`
)
}
return resp
2024-11-14 11:22:03 +00:00
}